From 585aeee97f3c99fbb804ad97d18103e756364019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Sun, 5 Jan 2025 12:28:44 +0100 Subject: [PATCH 1/2] fix(search): remove unused stats from being requested --- src/routes/(dashboard)/+page.server.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/routes/(dashboard)/+page.server.ts b/src/routes/(dashboard)/+page.server.ts index 1f3713a..5a573b9 100644 --- a/src/routes/(dashboard)/+page.server.ts +++ b/src/routes/(dashboard)/+page.server.ts @@ -1,8 +1,4 @@ -import { - togglePersonState, - getPersonsCountPerBuilding, - getPersonsCountPerDepartment -} from '$lib/server/db/person'; +import { togglePersonState } from '$lib/server/db/person'; import { fail, redirect, type Actions } from '@sveltejs/kit'; import type { PageServerLoad } from './$types'; import { invalidateSession } from '$lib/server/db/session'; @@ -11,18 +7,9 @@ import { search } from '$lib/utils/search'; export const load: PageServerLoad = async () => { try { - const personsP = search(); - const personsCountP = getPersonsCountPerDepartment(); - const personsInsideCountP = getPersonsCountPerBuilding(); - - const persons = await personsP; - const personsCount = await personsCountP; - const personsInsideCount = await personsInsideCountP; - + const persons = await search(); return { - persons, - personsCount, - personsInsideCount + persons }; } catch (err: unknown) { console.debug(`Failed to get persons: ${(err as Error).message}`); From 80c00f347224d2f2cd4f24b1e2f01f3957237991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Sun, 5 Jan 2025 12:28:57 +0100 Subject: [PATCH 2/2] fix(stats): toast on success and error --- src/routes/(dashboard)/statistics/+page.server.ts | 11 ++++++----- src/routes/(dashboard)/statistics/+page.svelte | 13 +++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/routes/(dashboard)/statistics/+page.server.ts b/src/routes/(dashboard)/statistics/+page.server.ts index fe310d6..2446f29 100644 --- a/src/routes/(dashboard)/statistics/+page.server.ts +++ b/src/routes/(dashboard)/statistics/+page.server.ts @@ -15,9 +15,9 @@ export const load: PageServerLoad = async () => { personsInsideCount }; } catch (err: unknown) { - console.debug(`Failed to get persons: ${(err as Error).message}`); + console.debug(`Failed to get statistics: ${(err as Error).message}`); return fail(500, { - message: 'Failed to get persons' + message: 'Failed to get statistics' }); } }; @@ -33,12 +33,13 @@ export const actions: Actions = { return { personsCount, - personsInsideCount + personsInsideCount, + message: 'Successfully refreshed statistics' }; } catch (err: unknown) { - console.debug(`Failed to get persons: ${(err as Error).message}`); + console.debug(`Failed to get statistics: ${(err as Error).message}`); return fail(500, { - message: 'Failed to get persons' + message: 'Failed to get statistics' }); } } diff --git a/src/routes/(dashboard)/statistics/+page.svelte b/src/routes/(dashboard)/statistics/+page.svelte index 5fed84d..b011b5b 100644 --- a/src/routes/(dashboard)/statistics/+page.svelte +++ b/src/routes/(dashboard)/statistics/+page.svelte @@ -4,10 +4,23 @@ import CountPerDepartment from '$lib/components/custom/stats/countPerDepartment.svelte'; import InsideCountPerBuilding from '$lib/components/custom/stats/insideCountPerBuilding.svelte'; import Button from '$lib/components/ui/button/button.svelte'; + import { toast } from 'svelte-sonner'; + import { page } from '$app/stores'; import { enhance } from '$app/forms'; let { data, form: actionData } = $props(); + $effect(() => { + const msg = actionData?.message; + if (msg !== undefined) { + if ($page.status === 200) { + toast.success(msg); + } else { + toast.error(msg); + } + } + }); + const personsCount = $derived(actionData?.personsCount ?? data.personsCount ?? []); const personsInsideCount = $derived( actionData?.personsInsideCount ?? data.personsInsideCount ?? []