Add addTimetableEntry action and reducer. Add removeTimetableEntry action.

This commit is contained in:
Ceda EI 2020-03-20 15:25:06 +05:30
parent dee71bec11
commit 883c44a01b
2 changed files with 33 additions and 2 deletions

View File

@ -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
};
}

View File

@ -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) {
[], [],
[], [],
]; ];
return 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;
}
} }