mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Updating store with update instead of set.
This commit is contained in:
parent
7aa5fadec3
commit
1a330b8ffe
4 changed files with 9 additions and 9 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
async function getRandomCollectionGame() {
|
async function getRandomCollectionGame() {
|
||||||
if ($collectionStore.length > 0) {
|
if ($collectionStore.length > 0) {
|
||||||
boredState.set({ loading: true });
|
boredState.update((n) => ({ ...n, loading: true }));
|
||||||
let randomNumber: number = Math.round(Math.random() * $collectionStore.length - 1);
|
let randomNumber: number = Math.round(Math.random() * $collectionStore.length - 1);
|
||||||
if ($collectionStore.at(randomNumber)) {
|
if ($collectionStore.at(randomNumber)) {
|
||||||
gameStore.removeAll();
|
gameStore.removeAll();
|
||||||
|
|
@ -19,11 +19,11 @@
|
||||||
const responseData = await response.json();
|
const responseData = await response.json();
|
||||||
console.log('responseData', responseData);
|
console.log('responseData', responseData);
|
||||||
gameStore.add(responseData?.game);
|
gameStore.add(responseData?.game);
|
||||||
boredState.set({ loading: false });
|
boredState.update((n) => ({ ...n, loading: false }));
|
||||||
} else {
|
} else {
|
||||||
toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true });
|
toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true });
|
||||||
}
|
}
|
||||||
boredState.set({ loading: false });
|
boredState.update((n) => ({ ...n, loading: false }));
|
||||||
} else {
|
} else {
|
||||||
toast.send('No items in your collection!', {
|
toast.send('No items in your collection!', {
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
async function handleSubmit(event: SubmitEvent) {
|
async function handleSubmit(event: SubmitEvent) {
|
||||||
// submitting = true;
|
// submitting = true;
|
||||||
boredState.set({ loading: true });
|
boredState.update((n) => ({ ...n, loading: true }));
|
||||||
const form = event.target as HTMLFormElement;
|
const form = event.target as HTMLFormElement;
|
||||||
console.log('form', form);
|
console.log('form', form);
|
||||||
const response = await fetch('/api/games', {
|
const response = await fetch('/api/games', {
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
});
|
});
|
||||||
const responseData = await response.json();
|
const responseData = await response.json();
|
||||||
// submitting = false;
|
// submitting = false;
|
||||||
boredState.set({ loading: false });
|
boredState.update((n) => ({ ...n, loading: false }));
|
||||||
gameStore.removeAll();
|
gameStore.removeAll();
|
||||||
gameStore.addAll(responseData?.games);
|
gameStore.addAll(responseData?.games);
|
||||||
// games = responseData?.games;
|
// games = responseData?.games;
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
$: {
|
$: {
|
||||||
if ($navigating) {
|
if ($navigating) {
|
||||||
debounce(() => {
|
debounce(() => {
|
||||||
boredState.set({ loading: true });
|
boredState.update((n) => ({ ...n, loading: true }));
|
||||||
}, 250);
|
}, 250);
|
||||||
}
|
}
|
||||||
if (!$navigating) {
|
if (!$navigating) {
|
||||||
boredState.set({ loading: false });
|
boredState.update((n) => ({ ...n, loading: false }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
import type { GameType, SavedGameType } from '$root/lib/types';
|
import type { GameType, SavedGameType } from '$root/lib/types';
|
||||||
|
|
||||||
async function handleSearch(event: SubmitEvent) {
|
async function handleSearch(event: SubmitEvent) {
|
||||||
boredState.set({ loading: true });
|
boredState.update((n) => ({ ...n, loading: true }));
|
||||||
const form = event.target as HTMLFormElement;
|
const form = event.target as HTMLFormElement;
|
||||||
console.log('form', form);
|
console.log('form', form);
|
||||||
const response = await fetch('/api/game', {
|
const response = await fetch('/api/game', {
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
body: new FormData(form)
|
body: new FormData(form)
|
||||||
});
|
});
|
||||||
const responseData = await response.json();
|
const responseData = await response.json();
|
||||||
boredState.set({ loading: false });
|
boredState.update((n) => ({ ...n, loading: false }));
|
||||||
gameStore.removeAll();
|
gameStore.removeAll();
|
||||||
gameStore.addAll(responseData?.games);
|
gameStore.addAll(responseData?.games);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue