-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dff9293
commit db0a0c5
Showing
11 changed files
with
73 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/app/(pages)/(home)/_state/mutations/use-create-bookmark-mutation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/app/(pages)/(home)/_state/mutations/use-delete-bookmark-mutation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/app/(pages)/(home)/_state/mutations/use-update-bookmark-mutation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/app/(pages)/(home)/_state/mutations/use-url-metadata-mutation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
import { Suspense } from "react"; | ||
import { BookmarkInput } from "./_components/bookmark-input"; | ||
import { BookmarkList } from "./_components/bookmark-list"; | ||
import { bookmarksQueries } from "./_state/queries/bookmark-query"; | ||
import { | ||
dehydrate, | ||
HydrationBoundary, | ||
QueryClient, | ||
} from "@tanstack/react-query"; | ||
import { ServerPrefetcher } from "~/app/_common/providers/server-prefetcher"; | ||
|
||
export default async function HomePage() { | ||
const queryClient = new QueryClient(); | ||
|
||
await queryClient.prefetchQuery(bookmarksQueries.bookmarks()); | ||
|
||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<ServerPrefetcher query={bookmarksQueries.bookmarks()}> | ||
<main className="flex flex-col gap-4 pb-10"> | ||
<h1 className="sr-only"> | ||
{`Bookmarket - Buy and Sell Expert's Bookmark Collections`} | ||
</h1> | ||
<BookmarkInput /> | ||
<BookmarkList /> | ||
</main> | ||
</HydrationBoundary> | ||
</ServerPrefetcher> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
dehydrate, | ||
HydrationBoundary, | ||
type UseQueryOptions, | ||
} from "@tanstack/react-query"; | ||
import React from "react"; | ||
import { getQueryClient } from "~/app/_core/utils/get-query-client"; | ||
|
||
export const ServerPrefetcher = async ({ | ||
children, | ||
query, | ||
}: { | ||
children: React.ReactNode; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
query: UseQueryOptions<any, any, any, any>; | ||
}) => { | ||
const queryClient = getQueryClient(); | ||
await queryClient.prefetchQuery(query); | ||
|
||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
{children} | ||
</HydrationBoundary> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { isServer, QueryClient } from "@tanstack/react-query"; | ||
|
||
function makeQueryClient() { | ||
return new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 60 * 1000, | ||
refetchOnWindowFocus: false, | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
let browserQueryClient: QueryClient | undefined = undefined; | ||
|
||
export function getQueryClient() { | ||
if (isServer) { | ||
// Server: always make a new query client | ||
return makeQueryClient(); | ||
} else { | ||
// Browser: make a new query client if we don't already have one | ||
// This is very important, so we don't re-make a new client if React | ||
// suspends during the initial render. This may not be needed if we | ||
// have a suspense boundary BELOW the creation of the query client | ||
if (!browserQueryClient) browserQueryClient = makeQueryClient(); | ||
return browserQueryClient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters