Skip to content

Commit

Permalink
fix: avoid showing "No items found" stats in <ItemsList /> (denolan…
Browse files Browse the repository at this point in the history
…d#559)

fixes denoland#472 

@iuioiua this is as simple as I got, without being too intrusive; I
personally like it; the problem was a bug regarding the state change of
the variable `isLoadingSig`, I was able to avoid it by initializing the
variable as `undefined` and bypassing it with the conditional rendering
not sure if is worth taking another look at it some other time.

Note: The simplicity of this PR does not reflect at all the time that
took me to get there — just for the record.

---------

Co-authored-by: Asher Gomez <[email protected]>
  • Loading branch information
roberto-morado and iuioiua authored Sep 10, 2023
1 parent 1f42033 commit 3a193e1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions islands/ItemsList.tsx
Original file line number Diff line number Diff line change
@@ -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, User } from "@/utils/db.ts";
import { type Item } 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";
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function ItemsList(
const itemsSig = useSignal<Item[]>([]);
const votedItemsIdsSig = useSignal<string[]>([]);
const cursorSig = useSignal("");
const isLoadingSig = useSignal(false);
const isLoadingSig = useSignal<boolean | undefined>(undefined);
const itemsAreVotedSig = useComputed(() =>
itemsSig.value.map((item) => votedItemsIdsSig.value.includes(item.id))
);
Expand Down Expand Up @@ -75,6 +75,10 @@ export default function ItemsList(
.finally(() => loadMoreItems());
}, []);

if (isLoadingSig.value === undefined) {
return <p class={LINK_STYLES}>Loading...</p>;
}

return (
<div>
{itemsSig.value.length
Expand Down

0 comments on commit 3a193e1

Please sign in to comment.