feat: implement loaders
This commit is contained in:
11
src/lib/loaders/LoaderYear.ts
Normal file
11
src/lib/loaders/LoaderYear.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { DB } from '$lib/integrations/db';
|
||||||
|
|
||||||
|
export const LoaderYear = (year?: number) => {
|
||||||
|
year = year ?? new Date().getFullYear();
|
||||||
|
|
||||||
|
return () => DB.getYear(year);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LoaderYears = () => {
|
||||||
|
return () => DB.getYears();
|
||||||
|
};
|
||||||
3
src/lib/loaders/index.ts
Normal file
3
src/lib/loaders/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const orchestrateLoaders = (loaders: (() => Promise<any>)[]) => {
|
||||||
|
return Promise.all(loaders.map((loader) => loader()));
|
||||||
|
};
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { DB } from '$lib/integrations/db';
|
import { orchestrateLoaders } from '$lib/loaders';
|
||||||
|
import { LoaderYear } from '$lib/loaders/LoaderYear';
|
||||||
|
import { LoaderYears } from '$lib/loaders/LoaderYear';
|
||||||
|
|
||||||
export const load = async () => {
|
export const load = async () => {
|
||||||
const year = new Date().getFullYear();
|
const [yearData, yearsData] = await orchestrateLoaders([LoaderYear(), LoaderYears()]);
|
||||||
const yearData = await DB.getYear(year);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
year: yearData
|
year: yearData,
|
||||||
|
years: yearsData
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
<script>
|
<script>
|
||||||
import YearOverview from '$lib/components/organisms/YearOverview.svelte';
|
import YearOverview from '$lib/components/organisms/YearOverview.svelte';
|
||||||
|
import YearNav from '$lib/components/molecules/YearNav.svelte';
|
||||||
|
|
||||||
let { data } = $props();
|
let { data } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>{data.year.year}</h1>
|
<h1>{data.year.year}</h1>
|
||||||
<YearOverview heading="Podsumowanie roku" data={data.year} />
|
<YearOverview heading="Podsumowanie roku" data={data.year} />
|
||||||
|
<YearNav years={data.years} />
|
||||||
|
|||||||
Reference in New Issue
Block a user