Added base tba api
This commit is contained in:
parent
377b7810cf
commit
5327aa8269
@ -1,4 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type { PageData } from './$types';
|
||||||
|
import Year from './Year.svelte';
|
||||||
|
|
||||||
|
export let data: PageData;
|
||||||
|
const events = data.events;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
resultats
|
<div class="container">
|
||||||
|
{#each $events as year}
|
||||||
|
<Year {year} />
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
34
src/routes/resultats/+page.ts
Normal file
34
src/routes/resultats/+page.ts
Normal file
@ -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<number> = 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<Event> = await events_response.json();
|
||||||
|
const response: Events = { year, events_list: year_events };
|
||||||
|
events.insert(response);
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
events
|
||||||
|
};
|
||||||
|
}) satisfies PageLoad;
|
7
src/routes/resultats/Event.svelte
Normal file
7
src/routes/resultats/Event.svelte
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import type { Event } from './EventsStore';
|
||||||
|
|
||||||
|
export let event: Event;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>{event.name}</div>
|
39
src/routes/resultats/EventsStore.ts
Normal file
39
src/routes/resultats/EventsStore.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
function createCount() {
|
||||||
|
const { subscribe, set, update } = writable(new Array<Events>());
|
||||||
|
|
||||||
|
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<Event>;
|
||||||
|
};
|
16
src/routes/resultats/Year.svelte
Normal file
16
src/routes/resultats/Year.svelte
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { each } from 'svelte/internal';
|
||||||
|
import Event from './Event.svelte';
|
||||||
|
import type { Events } from './EventsStore';
|
||||||
|
|
||||||
|
export let year: Events;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<article>
|
||||||
|
<header>{year.year}</header>
|
||||||
|
{#each year.events_list as event}
|
||||||
|
<Event {event} />
|
||||||
|
{/each}
|
||||||
|
</article>
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user