mirror of
				https://gitlab.com/ceda_ei/sonzai.git
				synced 2025-11-04 00:50:05 +01:00 
			
		
		
		
	Add addTimetableEntry action and reducer. Add removeTimetableEntry action.
This commit is contained in:
		
							
								
								
									
										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) {
 | 
				
			|||||||
			[],
 | 
								[],
 | 
				
			||||||
			[],
 | 
								[],
 | 
				
			||||||
		];
 | 
							];
 | 
				
			||||||
	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