forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedules.ts
More file actions
31 lines (25 loc) · 983 Bytes
/
schedules.ts
File metadata and controls
31 lines (25 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;