mirror of
				https://gitlab.com/ceda_ei/sonzai.git
				synced 2025-11-04 09:00:05 +01:00 
			
		
		
		
	Add ADD_SUBJECT and REMOVE_SUBJECT action creators and reducer.
This commit is contained in:
		@@ -1,5 +1,14 @@
 | 
			
		||||
export default function subjects(state) {
 | 
			
		||||
import { v4 } from "react-native-uuid";
 | 
			
		||||
 | 
			
		||||
export default function subjects(state, action) {
 | 
			
		||||
	if (typeof state === "undefined")
 | 
			
		||||
		return [];
 | 
			
		||||
	return state;
 | 
			
		||||
	switch(action.type) {
 | 
			
		||||
	case "ADD_SUBJECT":
 | 
			
		||||
		return [ ...state, { name: action.subject, id: v4() } ];
 | 
			
		||||
	case "REMOVE_SUBJECT":
 | 
			
		||||
		return state.filter(item => item.id != action.id);
 | 
			
		||||
	default:
 | 
			
		||||
		return state;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user