mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Add search on the search page...who knew.
This commit is contained in:
parent
f4ac64e88e
commit
94c2b3fc93
1 changed files with 31 additions and 2 deletions
|
|
@ -1,10 +1,13 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { applyAction, enhance } from '$app/forms';
|
||||||
import type { ActionData, PageData } from './$types';
|
import type { ActionData, PageData } from './$types';
|
||||||
import Game from '$lib/components/game/index.svelte';
|
import Game from '$lib/components/game/index.svelte';
|
||||||
import { gameStore } from '$lib/stores/gameSearchStore';
|
import { gameStore } from '$lib/stores/gameSearchStore';
|
||||||
|
import TextSearch from '$lib/components/search/textSearch/index.svelte';
|
||||||
import RemoveCollectionDialog from '$root/lib/components/dialog/RemoveCollectionDialog.svelte';
|
import RemoveCollectionDialog from '$root/lib/components/dialog/RemoveCollectionDialog.svelte';
|
||||||
import type { GameType, SavedGameType } from '$root/lib/types';
|
import { ToastType, type GameType, type SavedGameType } from '$root/lib/types';
|
||||||
import { boredState } from '$root/lib/stores/boredState';
|
import { boredState } from '$root/lib/stores/boredState';
|
||||||
|
import { toast } from '$root/lib/components/toast/toast';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
export let form: ActionData;
|
export let form: ActionData;
|
||||||
|
|
@ -36,7 +39,33 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>Search</h1>
|
<div class="game-search">
|
||||||
|
<form
|
||||||
|
action="/search"
|
||||||
|
method="post"
|
||||||
|
use:enhance={() => {
|
||||||
|
boredState.update((n) => ({ ...n, loading: true }));
|
||||||
|
return async ({ result }) => {
|
||||||
|
boredState.update((n) => ({ ...n, loading: false }));
|
||||||
|
console.log(result);
|
||||||
|
// `result` is an `ActionResult` object
|
||||||
|
if (result.type === 'error') {
|
||||||
|
toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true });
|
||||||
|
await applyAction(result);
|
||||||
|
} else {
|
||||||
|
gameStore.removeAll();
|
||||||
|
gameStore.addAll(result?.data?.games);
|
||||||
|
totalItems = result?.data?.totalCount;
|
||||||
|
console.log(`Frontend result: ${JSON.stringify(result)}`);
|
||||||
|
toast.send('Sucess!', { duration: 3000, type: ToastType.INFO, dismissible: true });
|
||||||
|
await applyAction(result);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextSearch showButton />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if $gameStore?.length > 0}
|
{#if $gameStore?.length > 0}
|
||||||
<div class="games">
|
<div class="games">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue