mirror of https://gitlab.com/ceda_ei/sonzai.git
Add addTimetableEntry action and reducer. Add removeTimetableEntry action.
This commit is contained in:
parent
dee71bec11
commit
883c44a01b
17
actions.js
17
actions.js
|
@ -20,3 +20,20 @@ export function setTheme(theme) {
|
||||||
theme: theme,
|
theme: theme,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function addTimetableEntry(day, entry) {
|
||||||
|
return {
|
||||||
|
type: "ADD_TIMETABLE_ENTRY",
|
||||||
|
day,
|
||||||
|
entry,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function removeTimetableEntry(id) {
|
||||||
|
return {
|
||||||
|
type: "REMOVE_TIMETABLE_ENTRY",
|
||||||
|
id: id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
export default function timetable(state) {
|
import { v4 } from "react-native-uuid";
|
||||||
|
|
||||||
|
export default function timetable(state, action) {
|
||||||
if (typeof state === "undefined")
|
if (typeof state === "undefined")
|
||||||
// Array of days starting with Sunday
|
// Array of days starting with Sunday
|
||||||
return [
|
return [
|
||||||
|
@ -10,5 +12,17 @@ export default function timetable(state) {
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
];
|
];
|
||||||
|
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;
|
return state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue