From bac9b7f8881f6485a2685994937bc1769aa84970 Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Wed, 26 Oct 2022 17:31:57 -0400 Subject: [PATCH] Fixed random search in form action and the random component. --- src/lib/components/search/random/index.svelte | 95 ++++++++++++------- src/routes/+page.svelte | 2 +- src/routes/search/+page.server.ts | 74 ++++++++------- 3 files changed, 103 insertions(+), 68 deletions(-) diff --git a/src/lib/components/search/random/index.svelte b/src/lib/components/search/random/index.svelte index 441a80d..835cd73 100644 --- a/src/lib/components/search/random/index.svelte +++ b/src/lib/components/search/random/index.svelte @@ -1,43 +1,72 @@ -
-
- - -
+ { + boredState.update((n) => ({ ...n, loading: true })); + return async ({ result }) => { + boredState.update((n) => ({ ...n, loading: false })); + console.log('result main page search', result); + // `result` is an `ActionResult` object + if (result.type === 'success') { + console.log('In success'); + gameStore.removeAll(); + const resultGames = result?.data?.games; + if (resultGames?.length <= 0) { + toast.send('No results!', { duration: 3000, type: ToastType.INFO, dismissible: true }); + } + gameStore.addAll(resultGames); + console.log(`Frontend result: ${JSON.stringify(result)}`); + await applyAction(result); + } else { + console.log('Invalid'); + await applyAction(result); + } + }; + }} +> +
+ + +
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 62e1af6..8527455 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -73,7 +73,7 @@

Search Boardgames!

- Input your requirements to search for board game that match your criteria. + Input your requirements to search for board games that match your criteria.