Clean up most of the schedules code to use server context

This commit is contained in:
Dane Everitt 2020-04-10 10:46:00 -07:00
parent 07d19ad326
commit 0ebf842757
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
9 changed files with 132 additions and 92 deletions

View file

@ -0,0 +1,31 @@
import { action, Action } from 'easy-peasy';
import { Schedule } from '@/api/server/schedules/getServerSchedules';
export interface ServerScheduleStore {
data: Schedule[];
setSchedules: Action<ServerScheduleStore, Schedule[]>;
appendSchedule: Action<ServerScheduleStore, Schedule>;
removeSchedule: Action<ServerScheduleStore, number>;
}
const schedules: ServerScheduleStore = {
data: [],
setSchedules: action((state, payload) => {
state.data = payload;
}),
appendSchedule: action((state, payload) => {
if (state.data.find(schedule => schedule.id === payload.id)) {
state.data = state.data.map(schedule => schedule.id === payload.id ? payload : schedule);
} else {
state.data = [ ...state.data, payload ];
}
}),
removeSchedule: action((state, payload) => {
state.data = [ ...state.data.filter(schedule => schedule.id !== payload) ];
}),
};
export default schedules;