Click
Click save
const initialState = {
name: 'A welcoming canvas',
postIts: [
{ text: 'Hello!', position: { x: 0.1, y: 0.3 }, color: 'yellow' }
],
isEditorOpen: false,
}
export default function canvasReducer(state = initialState, action) {
switch (action.type) {
case "OPEN_POST_IT_EDITOR":
// change isEditorOpen to true
return { ...state, isEditorOpen: true, newPostItPosition: action.position }
case "CREATE_POST_IT":
// append post it, close editor, clear position of nerw post it
return { ...state, postIts: [].concat(state.postIts, action.postIt), isEditorOpen: false, newPostItPosition: {} }
default:
return state;
}
return state;
}