@@ -199,7 +206,7 @@
Data
diff --git a/src/routes/data/season/+page.server.ts b/src/routes/data/season/+page.server.ts
new file mode 100644
index 0000000..79b2c06
--- /dev/null
+++ b/src/routes/data/season/+page.server.ts
@@ -0,0 +1,113 @@
+import type { Actions, PageServerLoad } from "./$types";
+import { form_data_clean, form_data_ensure_keys, form_data_get_and_remove_id } from "$lib/form";
+import type { Team, Driver, Race, Substitution } from "$lib/schema";
+
+// These "actions" run serverside only, as they're located inside +page.server.ts
+export const actions = {
+ create_team: async ({ request, locals }) => {
+ if (!locals.admin) return { unauthorized: true };
+
+ const data: FormData = form_data_clean(await request.formData());
+ form_data_ensure_keys(data, ["name", "logo"]);
+
+ const record: Team = await locals.pb.collection("teams").create(data);
+
+ return { tab: 0 };
+ },
+
+ update_team: async ({ request, locals }) => {
+ if (!locals.admin) return { unauthorized: true };
+
+ const data: FormData = form_data_clean(await request.formData());
+ const id: string = form_data_get_and_remove_id(data);
+
+ const record: Team = await locals.pb.collection("teams").update(id, data);
+
+ return { tab: 0 };
+ },
+
+ delete_team: async ({ request, locals }) => {
+ if (!locals.admin) return { unauthorized: true };
+
+ const data: FormData = form_data_clean(await request.formData());
+ const id: string = form_data_get_and_remove_id(data);
+
+ await locals.pb.collection("teams").delete(id);
+
+ return { tab: 0 };
+ },
+
+ create_driver: async ({ request, locals }) => {
+ return { tab: 1 };
+ },
+ update_driver: async ({ request, locals }) => {
+ return { tab: 1 };
+ },
+ delete_driver: async ({ request, locals }) => {
+ return { tab: 1 };
+ },
+
+ create_race: async ({ request, locals }) => {
+ return { tab: 2 };
+ },
+ update_race: async ({ request, locals }) => {
+ return { tab: 2 };
+ },
+ delete_race: async ({ request, locals }) => {
+ return { tab: 2 };
+ },
+
+ create_substitution: async ({ request, locals }) => {
+ return { tab: 2 };
+ },
+ update_substitution: async ({ request, locals }) => {
+ return { tab: 2 };
+ },
+ delete_substitution: async ({ request, locals }) => {
+ return { tab: 2 };
+ },
+} satisfies Actions;
+
+// This "load" function runs serverside only, as it's located inside +page.server.ts
+export const load: PageServerLoad = async ({ fetch, locals }) => {
+ const fetch_teams = async (): Promise
> => {
+ const teams: Array = await locals.pb.collection("teams").getFullList({
+ sort: "+name",
+ fetch: fetch,
+ });
+
+ teams.map((team: Team) => {
+ team.logo_url = locals.pb.files.getURL(team, team.logo);
+ });
+
+ return teams;
+ };
+
+ const fetch_drivers = async (): Promise> => {
+ const drivers: Array = await locals.pb.collection("drivers").getFullList({
+ sort: "+lastname",
+ fetch: fetch,
+ });
+
+ drivers.map((driver: Driver) => {
+ driver.headshot_url = locals.pb.files.getURL(driver, driver.headshot);
+ });
+
+ return drivers;
+ };
+
+ const fetch_races = async (): Promise> => {
+ return [];
+ };
+
+ const fetch_substitutions = async (): Promise> => {
+ return [];
+ };
+
+ return {
+ teams: await fetch_teams(),
+ drivers: await fetch_drivers(),
+ races: await fetch_races(),
+ substitutions: await fetch_substitutions(),
+ };
+};
diff --git a/src/routes/data/season/+page.svelte b/src/routes/data/season/+page.svelte
new file mode 100644
index 0000000..57bfec0
--- /dev/null
+++ b/src/routes/data/season/+page.svelte
@@ -0,0 +1,262 @@
+
+
+
+ F11 - Season Data
+
+
+
+ Teams
+ Drivers
+ Races
+ Substitutions
+
+
+ {#if current_tab === 0}
+
+
+
+
+
+ {#each data.teams as team}
+
+
+
+ {/each}
+
+
+ {#if data.admin}
+
+
+
+ {/if}
+
+ {:else if current_tab === 1}
+
+
+
+
+
+
+
+
+ {#each data.drivers as driver}
+
+
+
+ {/each}
+
+
+ {#if data.admin}
+
+
+
+ {/if}
+
+ {:else if current_tab === 2}
+
+
+
+
+ Races
+ {:else if current_tab === 3}
+
+
+
+
+ Substitutions
+ {/if}
+
+
diff --git a/src/routes/data/seasondata/+layout.svelte b/src/routes/data/seasondata/+layout.svelte
deleted file mode 100644
index 472ed5f..0000000
--- a/src/routes/data/seasondata/+layout.svelte
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-Season Data
-
-
- Teams
- Drivers
- Races
-
-
-
- {@render children()}
-
diff --git a/src/routes/data/seasondata/drivers/+page.svelte b/src/routes/data/seasondata/drivers/+page.svelte
deleted file mode 100644
index 8b13789..0000000
--- a/src/routes/data/seasondata/drivers/+page.svelte
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/routes/data/seasondata/races/+page.svelte b/src/routes/data/seasondata/races/+page.svelte
deleted file mode 100644
index e69de29..0000000
diff --git a/src/routes/data/seasondata/teams/+page.server.ts b/src/routes/data/seasondata/teams/+page.server.ts
deleted file mode 100644
index 56838e3..0000000
--- a/src/routes/data/seasondata/teams/+page.server.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import type { Actions, PageServerLoad } from "./$types";
-import { form_data_clean, form_data_ensure_keys, form_data_get_and_remove_id } from "$lib/form";
-
-// These "actions" run serverside only, as they're located inside +page.server.ts
-export const actions = {
- // We destructure the RequestEvent with ({cookies, request}).
- // Alternatively use (event) and event.cookies or event.request to access.
- create: async ({ cookies, request, locals }) => {
- if (!locals.admin) return { success: false };
-
- const data = form_data_clean(await request.formData());
- form_data_ensure_keys(data, ["name", "logo"]);
-
- const record = await locals.pb.collection("teams").create(data);
-
- return { success: true };
- },
-
- update: async ({ cookies, request, locals }) => {
- if (!locals.admin) return { success: false };
-
- const data = form_data_clean(await request.formData());
- const id = form_data_get_and_remove_id(data);
-
- // Destructure the FormData object
- const record = await locals.pb.collection("teams").update(id, data);
-
- return { success: true };
- },
-
- delete: async ({ cookies, request, locals }) => {
- if (!locals.admin) return { success: false };
-
- const data: FormData = form_data_clean(await request.formData());
- const id = form_data_get_and_remove_id(data);
-
- await locals.pb.collection("teams").delete(id);
-
- return { success: true };
- },
-} satisfies Actions;
-
-// This "load" function runs serverside only, as it's located inside +page.server.ts
-export const load: PageServerLoad = async ({ fetch, locals }) => {
- const fetch_teams = async () => {
- const teams = await locals.pb.collection("teams").getFullList({
- sort: "+name",
- fetch: fetch,
- });
-
- // Fill in the file URLs
- teams.map((team) => {
- team.logo_url = locals.pb.files.getURL(team, team.logo);
- });
-
- return teams;
- };
-
- return {
- teams: await fetch_teams(),
- };
-};
diff --git a/src/routes/data/seasondata/teams/+page.svelte b/src/routes/data/seasondata/teams/+page.svelte
deleted file mode 100644
index 9d23153..0000000
--- a/src/routes/data/seasondata/teams/+page.svelte
+++ /dev/null
@@ -1,100 +0,0 @@
-
-
-
- F11 - Teams
-
-
-
-
- {#each data.teams as team}
-
-
-
-
-
-
- {/each}
-
-
- {#if data.admin}
-
-
-
-
-
- {/if}
-
diff --git a/src/routes/data/userdata/+page.svelte b/src/routes/data/user/+page.svelte
similarity index 100%
rename from src/routes/data/userdata/+page.svelte
rename to src/routes/data/user/+page.svelte
diff --git a/src/routes/profile/+page.server.ts b/src/routes/profile/+page.server.ts
index d504cbf..bfa2f60 100644
--- a/src/routes/profile/+page.server.ts
+++ b/src/routes/profile/+page.server.ts
@@ -1,13 +1,9 @@
-import {
- form_data_clean,
- form_data_ensure_keys,
- form_data_get_and_remove_id,
-} from "$lib/form";
+import { form_data_clean, form_data_ensure_keys, form_data_get_and_remove_id } from "$lib/form";
import { error, redirect } from "@sveltejs/kit";
import type { Actions } from "./$types";
export const actions = {
- create: async ({ cookies, request, locals }) => {
+ create_profile: async ({ request, locals }) => {
const data = form_data_clean(await request.formData());
form_data_ensure_keys(data, ["username", "password"]);
@@ -22,16 +18,13 @@ export const actions = {
// Directly login after registering
await locals.pb
.collection("users")
- .authWithPassword(
- data.get("username")?.toString(),
- data.get("password")?.toString(),
- );
+ .authWithPassword(data.get("username")?.toString(), data.get("password")?.toString());
redirect(303, "/");
},
// TODO: PocketBase API rule: Only the active user should be able to modify itself
- update: async ({ cookies, request, locals }) => {
+ update_profile: async ({ request, locals }) => {
const data = form_data_clean(await request.formData());
const id = form_data_get_and_remove_id(data);
@@ -40,7 +33,7 @@ export const actions = {
redirect(303, "/");
},
- login: async ({ cookies, request, locals }) => {
+ login: async ({ request, locals }) => {
if (locals.user) {
console.log("Already logged in!");
return;
@@ -52,10 +45,7 @@ export const actions = {
try {
await locals.pb
.collection("users")
- .authWithPassword(
- data.get("username")?.toString(),
- data.get("password")?.toString(),
- );
+ .authWithPassword(data.get("username")?.toString(), data.get("password")?.toString());
} catch (err) {
console.log(`Failed to login: ${err}`);
error(400, "Failed to login!");
@@ -65,7 +55,7 @@ export const actions = {
redirect(303, "/");
},
- logout: async ({ cookies, request, locals }) => {
+ logout: async ({ locals }) => {
locals.pb.authStore.clear();
locals.user = undefined;