Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion components/SearchOnTop.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
'use client';
import React, { useState } from 'react';
import { useRouter } from "next/navigation";
import { useRouter, usePathname } from "next/navigation";
import { FaSearch, FaMapPin, FaSun, FaEthereum } from 'react-icons/fa';
import { LoadingScreen } from "@/components/loading-screen";

const SearchOnTop = () => {
const pathname = usePathname();
const [searchQuery, setSearchQuery] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [searchType, setSearchType] = useState<"onchain" | "offchain">("onchain");
const router = useRouter();

if (pathname === "/") {
return null;
}

const handleSearch = async (event: React.FormEvent) => {
event.preventDefault();
if (!searchQuery.trim()) return;
Expand Down
27 changes: 23 additions & 4 deletions components/home/CryptoExplorer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client'
import React, { useState, useEffect } from 'react';
import { useRouter } from "next/navigation"
import { useRouter } from "next/navigation";
import { LoadingScreen } from "@/components/loading-screen";

const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
const [searchValue, setSearchValue] = useState('');
Expand All @@ -10,7 +12,7 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
const [isFilterOpen, setIsFilterOpen] = useState(false);
const [selectedFilter, setSelectedFilter] = useState('All Filters');
const router = useRouter()

const [isLoading, setIsLoading] = useState(false);
const filters = ['All Filters', 'On-Chain', 'Off-Chain', 'Tokens', 'NFTs', 'Addresses'];

const translations = {
Expand Down Expand Up @@ -67,9 +69,23 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
fetchData();
}, []);

const handleSearch = (e: React.FormEvent<HTMLFormElement>) => {
const handleSearch = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
// Nho minh duy phan nay
if (!searchValue.trim()) return;

setIsLoading(true);
try {
await new Promise((resolve) => setTimeout(resolve, 2500)); // Simulated delay
if (selectedFilter === "On-Chain") {
router.push(`/search/?address=${encodeURIComponent(searchValue)}&network=mainnet`);
} else if (selectedFilter === "Off-Chain") {
router.push(`/search-offchain/?address=${encodeURIComponent(searchValue)}`);
}
} catch (error) {
console.error("Search error:", error);
} finally {
setIsLoading(false);
}
};

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

return (
<>
<div className="w-full mb-16 mt-16">
{/* Explorer Title */}
<div className="mb-6 text-center">
Expand Down Expand Up @@ -241,6 +258,8 @@ const CryptoPathExplorer = ({ language = 'en' as 'en' | 'vi' }) => {
</div>
</div>
</div>
<LoadingScreen isLoading={isLoading} />
</>
);
};

Expand Down