diff --git a/src/app/explorer/components/InfiniteScrollGuilds.tsx b/src/app/explorer/components/InfiniteScrollGuilds.tsx new file mode 100644 index 0000000000..345b166245 --- /dev/null +++ b/src/app/explorer/components/InfiniteScrollGuilds.tsx @@ -0,0 +1,52 @@ +"use client"; + +import { Button } from "@/components/ui/Button"; +import { env } from "@/lib/env"; +import { useInfiniteQuery } from "@tanstack/react-query"; +import { GuildCard } from "./GuildCard"; + +export const InfiniteScrollGuilds = () => { + const fetchGuilds = async ({ pageParam }: { pageParam: number }) => + ( + await fetch( + `${env.NEXT_PUBLIC_API}/guild/search?page=${pageParam}&pageSize=24&sortBy=name&reverse=false&search=`, + ) + ).json() as Promise>; + + const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = + useInfiniteQuery({ + queryKey: ["guilds"], + queryFn: fetchGuilds, + initialPageParam: 1, + getNextPageParam: (lastPage) => lastPage.page + 1, + }); + + const guilds = data?.pages.flatMap((page) => page.items); + + return ( +
+

Explore guilds

+ {guilds && guilds.length > 0 ? ( +
+ {guilds.map((guild) => ( + + ))} +
+ ) : ( +

Couldn't fetch guilds

+ )} + + +
+ ); +}; diff --git a/src/app/explorer/page.tsx b/src/app/explorer/page.tsx index d065d67227..85ab0de17e 100644 --- a/src/app/explorer/page.tsx +++ b/src/app/explorer/page.tsx @@ -1,14 +1,15 @@ -"use client"; - +import { AuthBoundary } from "@/components/AuthBoundary"; import { Button } from "@/components/ui/Button"; import { Card } from "@/components/ui/Card"; import { Input } from "@/components/ui/Input"; import { Skeleton } from "@/components/ui/Skeleton"; import { env } from "@/lib/env"; -import { Plus } from "@phosphor-icons/react/dist/ssr"; +import { Plus, SignIn } from "@phosphor-icons/react/dist/ssr"; +import { Suspense } from "react"; import { GuildCard } from "./components/GuildCard"; +import { InfiniteScrollGuilds } from "./components/InfiniteScrollGuilds"; -const getGuilds = async () => { +const _getGuilds = async () => { const request = `${env.NEXT_PUBLIC_API}/guild/search?page=1&pageSize=24&sortBy=name&reverse=false&search=`; const guilds = (await ( await fetch(request) @@ -34,8 +35,8 @@ const GuildCardSkeleton = () => { ); }; -export default async function Explorer() { - const { items: guilds } = await getGuilds(); +export default function Explorer() { + //const { items: guilds } = await getGuilds(); return (
@@ -49,7 +50,8 @@ export default async function Explorer() { -
+ + {/*

Explore guilds

{guilds.length > 0 ? (
@@ -60,7 +62,7 @@ export default async function Explorer() { ) : (

Couldn't fetch guilds

)} -
+
*/}
); } @@ -70,9 +72,9 @@ async function YourGuildsSection() {

Your guilds

- {/* +
Guild Robot

@@ -92,7 +94,7 @@ async function YourGuildsSection() { }> - */} +

); }