Skip to content

Commit

Permalink
Make expected stamps reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniils Petrovs committed Jun 23, 2024
1 parent 2e8fa84 commit 6831364
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
11 changes: 9 additions & 2 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export const csr = true;
import type { LayoutLoad } from './$types';

import { collectedStamps, expectedStamps } from '$lib/stores/stamps';
import { setToast } from '$lib/stores/toasts';
import { get } from 'svelte/store';
import { TOAST_TYPE } from '../custom';
import { supabase } from '../supabase-client';

export const load = (async () => {
Expand All @@ -15,14 +17,19 @@ export const load = (async () => {
async function startupTasks() {
console.log('Running startup tasks...');
get(collectedStamps);
await updateExpectedStamps();
try {
await updateExpectedStamps();
} catch (error) {
console.error('Error fetching stamp data:', error);
setToast({ message: 'Error fetching stamp data', type: TOAST_TYPE.ERROR });
}
setToast({ message: 'Updated stamp data', type: TOAST_TYPE.SUCCESS });
}

// Fetched expected stamp data from supabase and creates object in store
// With hash as key and rest of stamp data as value
async function updateExpectedStamps() {
console.log('Fetching stamp data...');
// TODO: Handle errors
const { data } = await supabase
.from('stamps')
.select('booth_id, name, description, image_url, external_url, hash, nsfw');
Expand Down
8 changes: 6 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script lang="ts">
import StampSheet from '$lib/components/StampSheet.svelte';
import { expectedStamps } from '$lib/stores/stamps.js';
export let data;
$: stampsCollection = Object.entries($expectedStamps).map(([key, value]) => ({
...value,
hash: key
}));
</script>

<StampSheet stamps={data.stamps} />
<StampSheet stamps={stampsCollection} />
9 changes: 1 addition & 8 deletions src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { expectedStamps } from '$lib/stores/stamps';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';

export const ssr = false;

export const load = (async () => {
const stamps = Object.entries(get(expectedStamps)).map(([key, value]) => ({
...value,
hash: key
}));

return { stamps };
return {};
}) satisfies PageLoad;

0 comments on commit 6831364

Please sign in to comment.