From 29d71eb49583e6902cc06bd60f34ec673ba39e8b Mon Sep 17 00:00:00 2001 From: Ryan Ponce Date: Tue, 5 Sep 2023 21:41:12 -0700 Subject: [PATCH 1/3] Create static version of vote button --- components/ItemSummary.tsx | 14 ++++++++++---- components/StaticVoteButton.tsx | 18 ++++++++++++++++++ islands/ItemsList.tsx | 10 ++++++++-- routes/index.tsx | 7 ++++++- 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 components/StaticVoteButton.tsx diff --git a/components/ItemSummary.tsx b/components/ItemSummary.tsx index 8131abba9..7ea472a9e 100644 --- a/components/ItemSummary.tsx +++ b/components/ItemSummary.tsx @@ -2,19 +2,25 @@ import VoteButton from "@/islands/VoteButton.tsx"; import type { Item } from "@/utils/db.ts"; import UserPostedAt from "./UserPostedAt.tsx"; +import StaticVoteButton from "./StaticVoteButton.tsx"; export interface ItemSummaryProps { item: Item; isVoted: boolean; + isSignedIn: boolean; } export default function ItemSummary(props: ItemSummaryProps) { return (
- + {props.isSignedIn + ? ( + + ) + : }

+ ▲ +
+ {props.score} +
+ ); +} diff --git a/islands/ItemsList.tsx b/islands/ItemsList.tsx index 41ef48ec4..e631758c4 100644 --- a/islands/ItemsList.tsx +++ b/islands/ItemsList.tsx @@ -1,7 +1,7 @@ // Copyright 2023 the Deno authors. All rights reserved. MIT license. import { useComputed, useSignal } from "@preact/signals"; import { useEffect } from "preact/hooks"; -import type { Item } from "@/utils/db.ts"; +import type { Item, User } from "@/utils/db.ts"; import { LINK_STYLES } from "@/utils/constants.ts"; import IconInfo from "tabler_icons_tsx/info-circle.tsx"; import ItemSummary from "@/components/ItemSummary.tsx"; @@ -34,7 +34,12 @@ function EmptyItemsList() { ); } -export default function ItemsList(props: { endpoint: string }) { +interface ItemListProps { + endpoint: string; + isSignedIn: boolean; +} + +export default function ItemsList(props: ItemListProps) { const itemsSig = useSignal([]); const votedItemsIdsSig = useSignal([]); const cursorSig = useSignal(""); @@ -77,6 +82,7 @@ export default function ItemsList(props: { endpoint: string }) { key={item.id} item={item} isVoted={itemsAreVotedSig.value[id]} + isSignedIn={props.isSignedIn} /> ); }) diff --git a/routes/index.tsx b/routes/index.tsx index 99229180a..c948fb1a7 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -45,12 +45,17 @@ export default async function HomePage( _req: Request, ctx: RouteContext, ) { + const isSignedIn = Boolean(ctx.state.sessionUser); + return ( <>

{NEEDS_SETUP && } - +
); From 336bff07d6ee150b566207478b4539a9b0dcdec2 Mon Sep 17 00:00:00 2001 From: Ryan Ponce Date: Tue, 5 Sep 2023 21:57:36 -0700 Subject: [PATCH 2/3] Fix broken ci check --- routes/index.tsx | 2 +- routes/items/[id].tsx | 1 + routes/users/[login].tsx | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/routes/index.tsx b/routes/index.tsx index c948fb1a7..da825c503 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -45,7 +45,7 @@ export default async function HomePage( _req: Request, ctx: RouteContext, ) { - const isSignedIn = Boolean(ctx.state.sessionUser); + const isSignedIn = ctx.state.sessionUser !== undefined; return ( <> diff --git a/routes/items/[id].tsx b/routes/items/[id].tsx index 7d1f7dd90..6f6f5bb29 100644 --- a/routes/items/[id].tsx +++ b/routes/items/[id].tsx @@ -51,6 +51,7 @@ export default async function ItemsItemPage( diff --git a/routes/users/[login].tsx b/routes/users/[login].tsx index dc1a9533c..d77d1d211 100644 --- a/routes/users/[login].tsx +++ b/routes/users/[login].tsx @@ -44,7 +44,8 @@ export default async function UsersUserPage( ) { const { login } = ctx.params; const user = await getUser(login); - if (user === null) return await ctx.renderNotFound(); + const isSignedIn = user !== null; + if (!isSignedIn) return await ctx.renderNotFound(); return ( <> @@ -54,7 +55,10 @@ export default async function UsersUserPage( isSubscribed={user.isSubscribed} login={user.login} /> - + ); From 1baf158b4bb6a693820a4623f308b26737e09eec Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 7 Sep 2023 06:56:05 +1000 Subject: [PATCH 3/3] Update routes/users/[login].tsx --- routes/users/[login].tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/users/[login].tsx b/routes/users/[login].tsx index d77d1d211..f110b9ffa 100644 --- a/routes/users/[login].tsx +++ b/routes/users/[login].tsx @@ -44,8 +44,8 @@ export default async function UsersUserPage( ) { const { login } = ctx.params; const user = await getUser(login); - const isSignedIn = user !== null; - if (!isSignedIn) return await ctx.renderNotFound(); + if (user === null) return await ctx.renderNotFound(); + const isSignedIn = ctx.state.sessionUser !== undefined; return ( <>