Skip to content

Commit

Permalink
FIX: closes #180 suspense skeleton for search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ejmg committed Aug 27, 2024
1 parent c58e429 commit 4a8a376
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/app/(main)/search/[query]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Page : FC<PageProps> = ({ params }) => {
});

return (
<div className="bg-primary/60 flex flex-col gap-5 sm:p-8">
<div className="bg-primary/60 flex flex-col gap-5 sm:p-8" key={query}>
<h1 className="sm:text-2xl font-bold">Search results</h1>
<HydrationBoundary state={dehydrate(queryClient)}>
<SearchResultsTable className="w-full" query={query}/>
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/components/SearchResultsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataTable } from "../ui/data-table";
import { type FC } from "react";
import { useSuspenseQuery } from "@tanstack/react-query";
import { getBaseURL } from "@/lib/utils";
import Loading from "@/app/loading";

export interface RelatedQuery {
type: string,
Expand All @@ -22,15 +23,20 @@ interface SearchResultsTableProps {
}

const SearchResultsTable : FC<SearchResultsTableProps> = ({ className, query }) => {
const { data } = useSuspenseQuery({
const { data, isFetching } = useSuspenseQuery({
queryFn: async () => {
const baseUrl = getBaseURL();
console.log(`FETCHING: GET /api/search?q=${query}`);
const data = await fetch(`${baseUrl}/api/search?q=${query}`, { method: "GET" });
return await data.json();
},
queryKey: ["searchResult", query],
}) as { data: SearchResult };
}) as { data: SearchResult, isFetching: boolean };

if (isFetching) {
// TODO: This just shows why we should have generalized skeletons for different views (tabled results, paginated data, etc);
return <Loading/>;
}

const relatedVisible = !!data?.related?.at(0);
const columnVisibility = { "related": relatedVisible };
Expand Down

0 comments on commit 4a8a376

Please sign in to comment.