diff --git a/actions.js b/actions.js index 49ca980..0415239 100644 --- a/actions.js +++ b/actions.js @@ -20,3 +20,20 @@ export function setTheme(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 + }; +} diff --git a/reducers/timetable.js b/reducers/timetable.js index 0d5b032..70e175e 100644 --- a/reducers/timetable.js +++ b/reducers/timetable.js @@ -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") // Array of days starting with Sunday 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; + } }