mirror of
				https://gitlab.com/ceda_ei/sonzai.git
				synced 2025-11-04 09:00:05 +01:00 
			
		
		
		
	Add addTimetableEntry action and reducer. Add removeTimetableEntry action.
This commit is contained in:
		@@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user