Skeleton: Delegate data fetching to specific routes and only load what's needed
This commit is contained in:
@ -1,38 +1,22 @@
|
|||||||
import {
|
import { fetch_graphics } from "$lib/fetch";
|
||||||
fetch_drivers,
|
|
||||||
fetch_graphics,
|
|
||||||
fetch_raceresults,
|
|
||||||
fetch_races,
|
|
||||||
fetch_substitutions,
|
|
||||||
fetch_teams,
|
|
||||||
} from "$lib/fetch";
|
|
||||||
import { pbUser } from "$lib/pocketbase";
|
import { pbUser } from "$lib/pocketbase";
|
||||||
|
import type { LayoutLoad } from "./$types";
|
||||||
|
|
||||||
// This makes the page client-side rendered
|
// This makes the page client-side rendered
|
||||||
export const ssr = false;
|
export const ssr = false;
|
||||||
|
|
||||||
import type { Driver, Graphic, Race, RaceResult, Substitution, Team } from "$lib/schema";
|
|
||||||
import type { LayoutLoad } from "./$types";
|
|
||||||
|
|
||||||
// On each page load (every route), this function runs serverside.
|
// On each page load (every route), this function runs serverside.
|
||||||
// The "locals.user" object is only available on the server,
|
// The "locals.user" object is only available on the server,
|
||||||
// since it's populated inside hooks.server.ts per request.
|
// since it's populated inside hooks.server.ts per request.
|
||||||
// It will populate the "user" attribute of each page's "data" object,
|
// It will populate the "user" attribute of each page's "data" object,
|
||||||
// so each page has access to the current user (or knows if no one is signed in).
|
// so each page has access to the current user (or knows if no one is signed in).
|
||||||
export const load: LayoutLoad = () => {
|
export const load: LayoutLoad = async () => {
|
||||||
return {
|
return {
|
||||||
// User information (synchronous)
|
// User information (synchronous)
|
||||||
user: pbUser,
|
user: pbUser,
|
||||||
admin: pbUser?.admin ?? false,
|
admin: pbUser?.admin ?? false,
|
||||||
|
|
||||||
// Return static data
|
// Return static data
|
||||||
graphics: fetch_graphics(fetch),
|
graphics: await fetch_graphics(fetch),
|
||||||
teams: fetch_teams(fetch),
|
|
||||||
drivers: fetch_drivers(fetch),
|
|
||||||
races: fetch_races(fetch),
|
|
||||||
substitutions: fetch_substitutions(fetch),
|
|
||||||
|
|
||||||
// Return other data
|
|
||||||
raceresults: fetch_raceresults(fetch),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
10
src/routes/data/raceresults/+page.ts
Normal file
10
src/routes/data/raceresults/+page.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { fetch_drivers, fetch_raceresults, fetch_races } from "$lib/fetch";
|
||||||
|
import type { PageLoad } from "../../$types";
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
return {
|
||||||
|
drivers: fetch_drivers(fetch),
|
||||||
|
races: fetch_races(fetch),
|
||||||
|
raceresults: fetch_raceresults(fetch),
|
||||||
|
};
|
||||||
|
};
|
9
src/routes/data/season/drivers/+page.ts
Normal file
9
src/routes/data/season/drivers/+page.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { fetch_drivers, fetch_teams } from "$lib/fetch";
|
||||||
|
import type { PageLoad } from "../../../$types";
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
return {
|
||||||
|
teams: fetch_teams(fetch),
|
||||||
|
drivers: fetch_drivers(fetch),
|
||||||
|
};
|
||||||
|
};
|
8
src/routes/data/season/races/+page.ts
Normal file
8
src/routes/data/season/races/+page.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { fetch_races } from "$lib/fetch";
|
||||||
|
import type { PageLoad } from "../../../$types";
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
return {
|
||||||
|
races: fetch_races(fetch),
|
||||||
|
};
|
||||||
|
};
|
10
src/routes/data/season/substitutions/+page.ts
Normal file
10
src/routes/data/season/substitutions/+page.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { fetch_drivers, fetch_races, fetch_substitutions } from "$lib/fetch";
|
||||||
|
import type { PageLoad } from "../../../$types";
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
return {
|
||||||
|
races: fetch_races(fetch),
|
||||||
|
drivers: fetch_drivers(fetch),
|
||||||
|
substitutions: fetch_substitutions(fetch),
|
||||||
|
};
|
||||||
|
};
|
8
src/routes/data/season/teams/+page.ts
Normal file
8
src/routes/data/season/teams/+page.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { fetch_teams } from "$lib/fetch";
|
||||||
|
import type { PageLoad } from "../../../$types";
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
|
return {
|
||||||
|
teams: fetch_teams(fetch),
|
||||||
|
};
|
||||||
|
};
|
@ -1,10 +1,20 @@
|
|||||||
import { fetch_currentpickedusers, fetch_currentrace, fetch_racepicks } from "$lib/fetch";
|
import {
|
||||||
|
fetch_currentpickedusers,
|
||||||
|
fetch_currentrace,
|
||||||
|
fetch_drivers,
|
||||||
|
fetch_racepicks,
|
||||||
|
fetch_raceresults,
|
||||||
|
fetch_races,
|
||||||
|
} from "$lib/fetch";
|
||||||
import type { PageLoad } from "../$types";
|
import type { PageLoad } from "../$types";
|
||||||
|
|
||||||
export const load: PageLoad = async ({ fetch }) => {
|
export const load: PageLoad = async ({ fetch }) => {
|
||||||
return {
|
return {
|
||||||
racepicks: fetch_racepicks(fetch),
|
racepicks: fetch_racepicks(fetch),
|
||||||
currentpickedusers: fetch_currentpickedusers(fetch),
|
currentpickedusers: fetch_currentpickedusers(fetch),
|
||||||
|
raceresults: fetch_raceresults(fetch),
|
||||||
|
drivers: fetch_drivers(fetch),
|
||||||
|
races: fetch_races(fetch),
|
||||||
|
|
||||||
currentrace: await fetch_currentrace(fetch),
|
currentrace: await fetch_currentrace(fetch),
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user