Skip to content

Commit

Permalink
Merge pull request #127 from studentinovisad/as/fix/stats-toast
Browse files Browse the repository at this point in the history
fix(stats): toast
  • Loading branch information
aleksasiriski authored Jan 5, 2025
2 parents 4fec016 + 80c00f3 commit 53600b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
19 changes: 3 additions & 16 deletions src/routes/(dashboard)/+page.server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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}`);
Expand Down
11 changes: 6 additions & 5 deletions src/routes/(dashboard)/statistics/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
};
Expand All @@ -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'
});
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/routes/(dashboard)/statistics/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []
Expand Down

0 comments on commit 53600b3

Please sign in to comment.