Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sse reactivity #101

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/routes/wishlists/[username]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

export let data: PageData;
type Item = PageData["items"][0];
let items: Item[] = data.items;

const [send, receive] = crossfade({
duration: (d) => Math.sqrt(d * 200),
Expand All @@ -39,7 +38,7 @@
let eventSource: EventSource;
onMount(async () => {
const userHash = await hash(data.listOwner.id + data.groupId);
$viewedItems[userHash] = await hashItems(items);
$viewedItems[userHash] = await hashItems(data.items);

subscribeToEvents();
});
Expand All @@ -62,7 +61,7 @@
};

const updateItems = (updatedItem: Item) => {
items = items.map((item) => {
data.items = data.items.map((item) => {
if (item.id === updatedItem.id) {
return { ...item, ...updatedItem };
}
Expand All @@ -71,11 +70,11 @@
};

const removeItem = (removedItem: Item) => {
items = items.filter((item) => item.id !== removedItem.id);
data.items = data.items.filter((item) => item.id !== removedItem.id);
};

const addItem = (addedItem: Item) => {
items = [...items, addedItem];
data.items = [...data.items, addedItem];
};
</script>

Expand All @@ -91,7 +90,7 @@
<hr class="pb-2" />
{/if}

{#if items.length === 0}
{#if data.items.length === 0}
<div class="flex flex-col items-center justify-center space-y-4 pt-4">
<img class="w-3/4 md:w-1/3" alt="Two people looking in an empty box" src={empty} />
<p class="text-2xl">No wishes yet</p>
Expand All @@ -108,20 +107,20 @@
<!-- items -->
<div class="flex flex-col space-y-4">
{#if data.listOwner.isMe}
{#each items as item (item.id)}
{#each data.items as item (item.id)}
<div in:receive={{ key: item.id }} out:send|local={{ key: item.id }} animate:flip={{ duration: 200 }}>
<ItemCard {item} showClaimedName={data.showClaimedName} user={data.user} />
</div>
{/each}
{:else}
<!-- unclaimed-->
{#each items.filter((item) => !item.pledgedById) as item (item.id)}
{#each data.items.filter((item) => !item.pledgedById) as item (item.id)}
<div in:receive={{ key: item.id }} out:send|local={{ key: item.id }} animate:flip={{ duration: 200 }}>
<ItemCard {item} showClaimedName={data.showClaimedName} user={data.user} />
</div>
{/each}
<!-- claimed -->
{#each items.filter((item) => item.pledgedById) as item (item.id)}
{#each data.items.filter((item) => item.pledgedById) as item (item.id)}
<div in:receive={{ key: item.id }} out:send|local={{ key: item.id }} animate:flip={{ duration: 200 }}>
<ItemCard {item} showClaimedName={data.showClaimedName} user={data.user} />
</div>
Expand Down
Loading