2020-03-20 10:55:06 +01:00
|
|
|
import { v4 } from "react-native-uuid";
|
|
|
|
|
|
|
|
export default function timetable(state, action) {
|
2020-03-16 03:23:03 +01:00
|
|
|
if (typeof state === "undefined")
|
|
|
|
// Array of days starting with Sunday
|
|
|
|
return [
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
];
|
2020-03-20 10:55:06 +01:00
|
|
|
switch (action.type) {
|
|
|
|
case "ADD_TIMETABLE_ENTRY":
|
|
|
|
return [
|
|
|
|
...(state.slice(0, action.day)),
|
|
|
|
[...state[action.day], {
|
|
|
|
...action.entry,
|
|
|
|
id: v4()
|
|
|
|
}],
|
|
|
|
...(state.slice(action.day + 1))
|
|
|
|
];
|
2020-03-24 19:17:54 +01:00
|
|
|
case "REMOVE_TIMETABLE_ENTRY":
|
|
|
|
return state.map(i => i.filter(j => j.id !== action.id));
|
2020-03-20 10:55:06 +01:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2020-03-16 03:23:03 +01:00
|
|
|
}
|