Skip to content

Commit

Permalink
feat: fetch preload GET /api/me/votes when user is signed in (denol…
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Sep 11, 2023
1 parent 5337d16 commit 8043b5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ export default async function HomePage(
href={endpoint}
rel="preload"
/>
{isSignedIn && (
<link
as="fetch"
crossOrigin="anonymous"
href="/api/me/votes"
rel="preload"
/>
)}
</Head>
<main class="flex-1 p-4">
{NEEDS_SETUP && <SetupInstruction />}
Expand Down
8 changes: 8 additions & 0 deletions routes/items/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export default async function ItemsItemPage(
href={endpoint}
rel="preload"
/>
{isSignedIn && (
<link
as="fetch"
crossOrigin="anonymous"
href="/api/me/votes"
rel="preload"
/>
)}
</Head>
<main class="flex-1 p-4 space-y-8">
<ItemSummary
Expand Down
13 changes: 11 additions & 2 deletions routes/users/[login].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,32 @@ export default async function UsersUserPage(
const user = await getUser(login);
if (user === null) return await ctx.renderNotFound();
const isSignedIn = ctx.state.sessionUser !== undefined;
const endpoint = `/api/users/${login}/items`;

return (
<>
<Head title={user.login} href={ctx.url.href}>
<link
as="fetch"
crossOrigin="anonymous"
href={`/api/users/${login}/items`}
href={endpoint}
rel="preload"
/>
{isSignedIn && (
<link
as="fetch"
crossOrigin="anonymous"
href="/api/me/votes"
rel="preload"
/>
)}
</Head>
<main class="flex-1 p-4 flex flex-col md:flex-row gap-8">
<div class="flex justify-center p-4">
<Profile isSubscribed={user.isSubscribed} login={user.login} />
</div>
<ItemsList
endpoint={`/api/users/${user.login}/items`}
endpoint={endpoint}
isSignedIn={isSignedIn}
/>
</main>
Expand Down

0 comments on commit 8043b5e

Please sign in to comment.