Skip to content

Commit d0ef0cf

Browse files
authored
Merge pull request #81 from TTMordred/hungphannelan2
Hungphannelan2
2 parents 38a9fc5 + a203756 commit d0ef0cf

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

components/SearchOnTop.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
'use client';
22
import React, { useState } from 'react';
3-
import { useRouter } from "next/navigation";
3+
import { useRouter, usePathname } from "next/navigation";
44
import { FaSearch, FaMapPin, FaSun, FaEthereum } from 'react-icons/fa';
55
import { LoadingScreen } from "@/components/loading-screen";
66

77
const SearchOnTop = () => {
8+
const pathname = usePathname();
89
const [searchQuery, setSearchQuery] = useState('');
910
const [isLoading, setIsLoading] = useState(false);
1011
const [searchType, setSearchType] = useState<"onchain" | "offchain">("onchain");
1112
const router = useRouter();
1213

14+
if (pathname === "/") {
15+
return null;
16+
}
17+
1318
const handleSearch = async (event: React.FormEvent) => {
1419
event.preventDefault();
1520
if (!searchQuery.trim()) return;

components/home/CryptoExplorer.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
'use client'
12
import React, { useState, useEffect } from 'react';
2-
import { useRouter } from "next/navigation"
3+
import { useRouter } from "next/navigation";
4+
import { LoadingScreen } from "@/components/loading-screen";
35

46
const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
57
const [searchValue, setSearchValue] = useState('');
@@ -10,7 +12,7 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
1012
const [isFilterOpen, setIsFilterOpen] = useState(false);
1113
const [selectedFilter, setSelectedFilter] = useState('All Filters');
1214
const router = useRouter()
13-
15+
const [isLoading, setIsLoading] = useState(false);
1416
const filters = ['All Filters', 'On-Chain', 'Off-Chain', 'Tokens', 'NFTs', 'Addresses'];
1517

1618
const translations = {
@@ -67,9 +69,23 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
6769
fetchData();
6870
}, []);
6971

70-
const handleSearch = (e: React.FormEvent<HTMLFormElement>) => {
72+
const handleSearch = async (e: React.FormEvent<HTMLFormElement>) => {
7173
e.preventDefault();
72-
// Nho minh duy phan nay
74+
if (!searchValue.trim()) return;
75+
76+
setIsLoading(true);
77+
try {
78+
await new Promise((resolve) => setTimeout(resolve, 2500)); // Simulated delay
79+
if (selectedFilter === "On-Chain") {
80+
router.push(`/search/?address=${encodeURIComponent(searchValue)}&network=mainnet`);
81+
} else if (selectedFilter === "Off-Chain") {
82+
router.push(`/search-offchain/?address=${encodeURIComponent(searchValue)}`);
83+
}
84+
} catch (error) {
85+
console.error("Search error:", error);
86+
} finally {
87+
setIsLoading(false);
88+
}
7389
};
7490

7591
const toggleFilterDropdown = () => {
@@ -82,6 +98,7 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
8298
};
8399

84100
return (
101+
<>
85102
<div className="w-full mb-16 mt-16">
86103
{/* Explorer Title */}
87104
<div className="mb-6 text-center">
@@ -241,6 +258,8 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
241258
</div>
242259
</div>
243260
</div>
261+
<LoadingScreen isLoading={isLoading} />
262+
</>
244263
);
245264
};
246265

0 commit comments

Comments
 (0)