From 1cdbab0f6c0396988e3b44729d0ca3c850d13763 Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Sun, 14 Jul 2024 18:09:47 +0100 Subject: [PATCH] feat(*): Enable automatic saving --- .../components/pokedex/PokedexEntryCatchRecord.svelte | 10 ++++++---- src/routes/mydex/+page.svelte | 9 ++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lib/components/pokedex/PokedexEntryCatchRecord.svelte b/src/lib/components/pokedex/PokedexEntryCatchRecord.svelte index 8cf182a..72f896f 100644 --- a/src/lib/components/pokedex/PokedexEntryCatchRecord.svelte +++ b/src/lib/components/pokedex/PokedexEntryCatchRecord.svelte @@ -11,7 +11,7 @@ const dispatch = createEventDispatcher(); - function save() { + function updateCatchRecord() { dispatch('updateCatch', { pokedexEntry, catchRecord }); } @@ -83,6 +83,7 @@ type="checkbox" bind:checked={catchRecord.caught} class="checkbox checkbox-primary border-black" + on:change={updateCatchRecord} /> @@ -95,6 +96,7 @@ type="checkbox" bind:checked={catchRecord.haveToEvolve} class="checkbox checkbox-primary border-black" + on:change={updateCatchRecord} /> @@ -107,6 +109,7 @@ type="checkbox" bind:checked={catchRecord.inHome} class="checkbox checkbox-primary border-black" + on:change={updateCatchRecord} /> @@ -120,6 +123,7 @@ type="checkbox" bind:checked={catchRecord.hasGigantamaxed} class="checkbox checkbox-primary border-black" + on:change={updateCatchRecord} /> @@ -133,6 +137,7 @@ bind:value={catchRecord.personalNotes} id={`personalNotesInput-${catchRecord._id}`} class="form-textarea w-full p-2 border rounded" + on:change={updateCatchRecord} >

@@ -152,9 +157,6 @@ {/if} {/if} -
- -
diff --git a/src/routes/mydex/+page.svelte b/src/routes/mydex/+page.svelte index d68b44a..68ba284 100644 --- a/src/routes/mydex/+page.svelte +++ b/src/routes/mydex/+page.svelte @@ -58,7 +58,8 @@ } } - async function updateACatch(catchRecord: CatchRecord) { + async function updateACatch(event: any) { + const { catchRecord } = event.detail; if (!localUser?.id) { alert('User not signed in'); return; @@ -73,11 +74,9 @@ try { const response = await fetch('/api/catch-records', requestOptions); if (!response.ok) { + alert('Failed to update catch record'); throw new Error('Failed to update catch record'); } - - const updatedRecord = await response.json(); - console.log('Updated catch record:', updatedRecord); } catch (error) { console.error('Error updating catch record:', error); } @@ -177,7 +176,7 @@ {showOrigins} {showForms} bind:catchRecord - on:updateCatch={() => updateACatch(catchRecord)} + on:updateCatch={updateACatch} /> {/each} {:else if failedToLoad}