Skip to content

Commit

Permalink
Adjust Marathon API to account for fetching arrays
Browse files Browse the repository at this point in the history
Related to Issue #38
  • Loading branch information
BobChao87 committed Nov 17, 2021
1 parent ad503b6 commit 7ec982d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions store/api/marathon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ export const mutations: MutationTree<MarathonState> = {
addFrontPage(state, { value: frontPage }): void {
Vue.set(state, 'frontPage', frontPage);
},
addSchedule(state, { value: schedule, data }): void {
Vue.set(state.calendars, `${data.start}-${data.end}`, schedule);
addCalendar(state, { value: calendar, data }): void {
Vue.set(state.calendars, `${data.start}-${data.end}`, calendar);
},
};

export const actions: ActionTree<MarathonState, MarathonState> = {
get: MarathonOengusAPI.get<FullMarathon>({ key: 'marathons', mutation: 'addMarathon' }),
frontPage: MarathonOengusAPI.get<FrontPageMarathons>({ key: 'frontPage' }),
calendar: MarathonOengusAPI.get<Array<Marathon>>({ path: 'forDates', key: 'calendars' }),
calendar: MarathonOengusAPI.get<Array<Marathon>, { calendar: Array<Marathon> }>({
path: 'forDates',
key: 'calendars',
mutation: 'addCalendar',
transform: ({ value: calendar }) => ({ calendar }),
}),
};
6 changes: 5 additions & 1 deletion types/api/marathon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ export interface FrontPageMarathons {
live: Array<Marathon>;
}

export interface Calendars {
[date: string]: { calendar: Array<Marathon> };
}

export interface MarathonState extends OengusState {
marathons: { [id: string]: FullMarathon };
calendars: { [date: string]: Array<Marathon> };
calendars: Calendars;
frontPage?: FrontPageMarathons;
}

Expand Down

0 comments on commit 7ec982d

Please sign in to comment.