From ab49cec1897d127f38a2d9bd2fbacc54918016b2 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Mon, 25 Mar 2024 02:40:47 +0530 Subject: [PATCH] feat: search page --- app/page.tsx | 35 ++------ app/search/page.tsx | 46 ++++++++++ components/IconSearch.tsx | 11 +++ components/SearchProfile.tsx | 48 ++++++++++ components/background-beams.tsx | 4 +- components/card-hover-effect.tsx | 129 +++++++++++++++++++++++++++ components/hover-border-gradient.tsx | 2 +- components/ui/button.tsx | 5 +- services/apollo.ts | 44 +++++++++ 9 files changed, 291 insertions(+), 33 deletions(-) create mode 100644 app/search/page.tsx create mode 100644 components/IconSearch.tsx create mode 100644 components/SearchProfile.tsx create mode 100644 components/card-hover-effect.tsx diff --git a/app/page.tsx b/app/page.tsx index b6f152f..6f3e592 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,15 +1,11 @@ "use client"; -import Image from "next/image"; -import { cn } from "@/lib/utils"; import { BackgroundBeams } from "@/components/background-beams"; -import { Input } from "@/components/ui/input"; import { HoverBorderGradient } from "@/components/hover-border-gradient"; -import { useState } from "react"; -import { Button } from "@/components/ui/button"; +import SearchProfilesComponent from "@/components/SearchProfile"; +import { useRouter } from "next/navigation"; export default function Home() { - const [searchQuery, setSearchQuery] = useState(""); return (
@@ -23,18 +19,7 @@ export default function Home() {
- { - setSearchQuery(e.target.value); - }} - /> - +
@@ -43,25 +28,19 @@ export default function Home() { } export function ClaimYourProfileButton() { + const router = useRouter(); return (
{ + router.push("https://enter.metagame.wtf/"); + }} > Claim your profile
); } - -function IconSearch() { - return ( -
- - - -
- ); -} diff --git a/app/search/page.tsx b/app/search/page.tsx new file mode 100644 index 0000000..49e395b --- /dev/null +++ b/app/search/page.tsx @@ -0,0 +1,46 @@ +"use client"; + +import { useSearchParams } from "next/navigation"; +import SearchProfilesComponent from "@/components/SearchProfile"; +import { useQuery } from "@apollo/client"; +import { searchProfiles } from "@/services/apollo"; +import { HoverEffect } from "@/components/card-hover-effect"; +import { BackgroundBeams } from "@/components/background-beams"; +import { toHTTP } from "@/utils/ipfs"; + +const Page: React.FC = () => { + const searchParams = useSearchParams(); + const searchQuery = searchParams.get("query") ?? undefined; + + const { loading, error, data } = useQuery(searchProfiles, { + variables: { search: `%${searchQuery}%` }, + }); + + const players = data?.player ?? []; + const formattedData = players.map((player) => { + const { profile } = player; + return { + name: profile.name, + description: profile.description, + username: profile.username, + imageUrl: toHTTP(profile?.profileImageURL ?? ""), + ethereumAddress: player.ethereumAddress, + href: `/${player.ethereumAddress}`, + }; + }); + console.log("searchParams", players); + + return ( +
+
+ +
+
+ +
+ +
+ ); +}; + +export default Page; diff --git a/components/IconSearch.tsx b/components/IconSearch.tsx new file mode 100644 index 0000000..e93b106 --- /dev/null +++ b/components/IconSearch.tsx @@ -0,0 +1,11 @@ +const IconSearch = () => { + return ( +
+ + + +
+ ); +}; + +export default IconSearch; diff --git a/components/SearchProfile.tsx b/components/SearchProfile.tsx new file mode 100644 index 0000000..c177525 --- /dev/null +++ b/components/SearchProfile.tsx @@ -0,0 +1,48 @@ +"use client"; +import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; +import { useState } from "react"; +import IconSearch from "@/components/IconSearch"; +import { useRouter } from "next/navigation"; +import { cn } from "@/lib/utils"; + +const SearchProfile = ({ + val, + classname, +}: { + val?: string; + classname?: string; +}) => { + const [searchQuery, setSearchQuery] = useState(val ?? ""); + const router = useRouter(); + + return ( +
+ { + setSearchQuery(e.target.value); + }} + /> + +
+ ); +}; + +export default SearchProfile; diff --git a/components/background-beams.tsx b/components/background-beams.tsx index 116c47e..6703761 100644 --- a/components/background-beams.tsx +++ b/components/background-beams.tsx @@ -60,12 +60,12 @@ export const BackgroundBeams = React.memo( return (
{ + let [hoveredIndex, setHoveredIndex] = useState(null); + + return ( +
+ {items.map((item, idx) => ( + setHoveredIndex(idx)} + onMouseLeave={() => setHoveredIndex(null)} + target="_blank" + > + + {hoveredIndex === idx && ( + + )} + + +
+ Picture of the author +
+ + + {item.name} (@{item.username}) + + {item.description} +
+ + ))} +
+ ); +}; + +export const Card = ({ + className, + children, +}: { + className?: string; + children: React.ReactNode; +}) => { + return ( +
+
+
{children}
+
+
+ ); +}; +export const CardTitle = ({ + className, + children, +}: { + className?: string; + children: React.ReactNode; +}) => { + return ( +

+ {children} +

+ ); +}; +export const CardDescription = ({ + className, + children, +}: { + className?: string; + children: React.ReactNode; +}) => { + return ( +

+ {children} +

+ ); +}; diff --git a/components/hover-border-gradient.tsx b/components/hover-border-gradient.tsx index 5e49807..d9d4d10 100644 --- a/components/hover-border-gradient.tsx +++ b/components/hover-border-gradient.tsx @@ -77,7 +77,7 @@ export function HoverBorderGradient({