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))
|
|
|
|
];
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2020-03-16 03:23:03 +01:00
|
|
|
}
|