diff --git a/src/Store.js b/src/Store.js index 2d5aaa81d7419740f6f4a34618975773ea836cac..cda6dc3eb2a6f60b70ba26e6bdbf7ebd83935565 100644 --- a/src/Store.js +++ b/src/Store.js @@ -21,102 +21,104 @@ import React from 'react' export const Store = React.createContext() const initialState = { - searchOpen: false, - userIsLoggedIn : false, - userAgreedToPublicationTerms: false, - userAgreedToPublicationPermissions: false, - modalColaborarPlataformaOpen : false, - search: { - query: '*', - class: 'LearningObject' - }, - windowSize: { - width: 0, - height: 0 -}, - currentUser: { - askTeacherQuestion : true, - id : '', - username : '', - email : '', - accessToken : '', - clientToken : '', - userAvatar : '', - userCover : '', - uid : '', - followCount : 0, - collectionsCount : 0, - submitter_request : 'default', - roles : [] - } + searchOpen: false, + userIsLoggedIn: false, + userAgreedToPublicationTerms: false, + userAgreedToPublicationPermissions: false, + modalColaborarPlataformaOpen: false, + search: { + query: '*', + class: 'LearningObject' + }, + windowSize: { + width: 0, + height: 0 + }, + currentUser: { + askTeacherQuestion: true, + id: '', + username: '', + email: '', + accessToken: '', + clientToken: '', + userAvatar: '', + userCover: '', + uid: '', + followCount: 0, + collectionsCount: 0, + submitter_request: 'default', + roles: [] + } } + + function reducer(state, action) { - switch (action.type){ - case 'SAVE_SEARCH': - return { - ...state, - search: action.newSearch - } - case 'HANDLE_SEARCH_BAR': - return { - ...state, - searchOpen: action.opened - } - case 'WINDOW_SIZE': - return { - ...state, - windowSize: action.innerWindow - } - case 'USER_LOGGED_IN': - return { - ...state, - userIsLoggedIn:action.userLoggedIn, - currentUser:action.login - } - case 'USER_SIGNED_UP': - return { - ...state, - userIsLoggedIn:action.userLoggedIn, - currentUser:action.login + switch (action.type) { + case 'SAVE_SEARCH': + return { + ...state, + search: action.newSearch + } + case 'HANDLE_SEARCH_BAR': + return { + ...state, + searchOpen: action.opened + } + case 'WINDOW_SIZE': + return { + ...state, + windowSize: action.innerWindow + } + case 'USER_LOGGED_IN': + return { + ...state, + userIsLoggedIn: action.userLoggedIn, + currentUser: action.login + } + case 'USER_SIGNED_UP': + return { + ...state, + userIsLoggedIn: action.userLoggedIn, + currentUser: action.login + } + case 'USER_LOGGED_OUT': + return { + ...state, + userIsLoggedIn: action.userLoggedOut, + currentUser: action.login + } + case 'USER_AGREED_TO_PUBLICATION_TERMS': + return { + ...state, + userAgreedToPublicationTerms: action.userAgreement + } + case 'USER_AGREED_TO_PUBLICATION_PERMISSIONS': + return { + ...state, + userAgreedToPublicationPermissions: action.userAgreement + } + case 'USER_ACCESSED_USER_PAGE': + return { + ...state, + currentUser: action.set + } + case 'USER_CHANGED_COVER': + return { + ...state, + currentUser: action.currUser + } + default: + return state } - case 'USER_LOGGED_OUT': - return { - ...state, - userIsLoggedIn:action.userLoggedOut, - currentUser:action.login - } - case 'USER_AGREED_TO_PUBLICATION_TERMS': - return { - ...state, - userAgreedToPublicationTerms: action.userAgreement - } - case 'USER_AGREED_TO_PUBLICATION_PERMISSIONS': - return { - ...state, - userAgreedToPublicationPermissions : action.userAgreement - } - case 'USER_ACCESSED_USER_PAGE': - return { - ...state, - currentUser : action.set - } - case 'USER_CHANGED_COVER': - return { - ...state, - currentUser : action.currUser - } - default: - return state - } } export function StoreProvider(props) { - const [state, dispatch] = React.useReducer(reducer, initialState); - const value = { state, dispatch }; - return ( - <Store.Provider value={value}> - {props.children} - </Store.Provider> - ) + const [state, dispatch] = React.useReducer(reducer, initialState); + const value = { state, dispatch }; + return ( + <Store.Provider value={value}> + {props.children} + </Store.Provider> + ) }