Skeleton: Fetch RaceResults asynchronously in root layout
This commit is contained in:
@ -11,7 +11,11 @@
|
||||
const modalStore: ModalStore = getModalStore();
|
||||
|
||||
const result_handler = async (event: Event, id?: string) => {
|
||||
const result: RaceResult | undefined = get_by_value(data.results, "id", id ?? "Invalid");
|
||||
const result: RaceResult | undefined = get_by_value(
|
||||
await data.raceresults,
|
||||
"id",
|
||||
id ?? "Invalid",
|
||||
);
|
||||
|
||||
if (id && !result) return;
|
||||
|
||||
@ -90,4 +94,6 @@
|
||||
<span class="font-bold">Create Race Result</span>
|
||||
</Button>
|
||||
</div>
|
||||
<Table data={data.results} columns={results_columns} handler={result_handler} />
|
||||
{#await data.raceresults then results}
|
||||
<Table data={results} columns={results_columns} handler={result_handler} />
|
||||
{/await}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import type { RaceResult } from "$lib/schema";
|
||||
import type { PageLoad } from "../../$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
// TODO: Duplicated code from racepicks/+page.server.ts
|
||||
const fetch_raceresults = async (): Promise<RaceResult[]> => {
|
||||
const raceresults: RaceResult[] = await pb
|
||||
.collection("raceresultsdesc")
|
||||
.getFullList({ fetch: fetch });
|
||||
|
||||
return raceresults;
|
||||
};
|
||||
|
||||
return {
|
||||
results: await fetch_raceresults(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user