Skip to content

Commit

Permalink
fix: only call /api/me/votes when being signed in (#534)
Browse files Browse the repository at this point in the history
closes #522.

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
  • Loading branch information
mbhrznr and iuioiua authored Sep 8, 2023
1 parent 0d1dc98 commit 5cbfd3c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions islands/ItemsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ function EmptyItemsList() {
);
}

interface ItemListProps {
endpoint: string;
isSignedIn: boolean;
}

export default function ItemsList(props: ItemListProps) {
export default function ItemsList(
props: { endpoint: string; isSignedIn: boolean },
) {
const itemsSig = useSignal<Item[]>([]);
const votedItemsIdsSig = useSignal<string[]>([]);
const cursorSig = useSignal("");
Expand All @@ -66,6 +63,11 @@ export default function ItemsList(props: ItemListProps) {
}

useEffect(() => {
if (!props.isSignedIn) {
loadMoreItems();
return;
}

fetchVotedItems()
.then((votedItems) =>
votedItemsIdsSig.value = votedItems.map(({ id }) => id)
Expand Down

0 comments on commit 5cbfd3c

Please sign in to comment.