diff --git a/src/routes/resultats/+page.svelte b/src/routes/resultats/+page.svelte index 3065cc0..77b62df 100644 --- a/src/routes/resultats/+page.svelte +++ b/src/routes/resultats/+page.svelte @@ -1,4 +1,13 @@ -resultats +
+ {#each $events as year} + + {/each} +
diff --git a/src/routes/resultats/+page.ts b/src/routes/resultats/+page.ts new file mode 100644 index 0000000..963f07c --- /dev/null +++ b/src/routes/resultats/+page.ts @@ -0,0 +1,34 @@ +import { events } from './EventsStore'; +import type { PageLoad } from './$types'; +import type { Events, Event } from './EventsStore'; + +export const load = (async ({ fetch }) => { + events.reset(); + const years_response = await fetch( + 'https://www.thebluealliance.com/api/v3/team/frc5618/years_participated', + { + method: 'GET', + headers: { + 'X-TBA-Auth-Key': '6oQL4iTAIFO0tc5xmRSWVQoNlgm5jpB5x4YZBdqhGTFJjqfqM6XV53s8FBAEiXOJ' + } + } + ); + const years: Array = await years_response.json(); + years.reverse().forEach(async (year) => { + const events_response = await fetch( + `https://www.thebluealliance.com/api/v3/team/frc5618/events/${year}/simple`, + { + method: 'GET', + headers: { + 'X-TBA-Auth-Key': '6oQL4iTAIFO0tc5xmRSWVQoNlgm5jpB5x4YZBdqhGTFJjqfqM6XV53s8FBAEiXOJ' + } + } + ); + const year_events: Array = await events_response.json(); + const response: Events = { year, events_list: year_events }; + events.insert(response); + }); + return { + events + }; +}) satisfies PageLoad; diff --git a/src/routes/resultats/Event.svelte b/src/routes/resultats/Event.svelte new file mode 100644 index 0000000..8f0affe --- /dev/null +++ b/src/routes/resultats/Event.svelte @@ -0,0 +1,7 @@ + + +
{event.name}
diff --git a/src/routes/resultats/EventsStore.ts b/src/routes/resultats/EventsStore.ts new file mode 100644 index 0000000..1a46aac --- /dev/null +++ b/src/routes/resultats/EventsStore.ts @@ -0,0 +1,39 @@ +import { writable } from 'svelte/store'; + +function createCount() { + const { subscribe, set, update } = writable(new Array()); + + return { + subscribe, + insert: (events: Events) => { + update((n) => [...n, events]); + }, + reset: () => set([]) + }; +} + +export const events = createCount(); + +export type Event = { + key: string; + name: string; + event_code: string; + event_type: string; + district: { + abbreviation: string; + display_name: string; + key: string; + year: number; + }; + city: string; + state_prov: string; + country: string; + start_date: string; + end_date: string; + year: number; +}; + +export type Events = { + year: number; + events_list: Array; +}; diff --git a/src/routes/resultats/Year.svelte b/src/routes/resultats/Year.svelte new file mode 100644 index 0000000..377bc08 --- /dev/null +++ b/src/routes/resultats/Year.svelte @@ -0,0 +1,16 @@ + + +
+
+
{year.year}
+ {#each year.events_list as event} + + {/each} +
+