2020-04-10 17:46:00 +00:00
|
|
|
import { action, Action } from 'easy-peasy';
|
2022-02-27 17:35:27 +00:00
|
|
|
import { Schedule } from '@definitions/user';
|
2020-04-10 17:46:00 +00:00
|
|
|
|
|
|
|
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;
|