feat: SW-693 Moved state changes to reducer
This commit is contained in:
@@ -115,14 +115,21 @@ export default function Search({ locations }: SearchProps) {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
state.searchData =
|
||||
const searchData =
|
||||
typeof window !== "undefined"
|
||||
? JSON.parse(sessionStorage.getItem(sessionStorageKey) || "")
|
||||
: undefined
|
||||
state.searchHistory =
|
||||
const searchHistory =
|
||||
typeof window !== "undefined"
|
||||
? JSON.parse(localStorage.getItem(localStorageKey) || "")
|
||||
: null
|
||||
dispatch({
|
||||
payload: {
|
||||
searchData,
|
||||
searchHistory,
|
||||
},
|
||||
type: ActionType.SET_STORAGE_DATA,
|
||||
})
|
||||
}, [state])
|
||||
|
||||
return (
|
||||
|
||||
@@ -68,6 +68,13 @@ export function reducer(state: State, action: Action) {
|
||||
searchHistory: action.payload.searchHistory,
|
||||
}
|
||||
}
|
||||
case ActionType.SET_STORAGE_DATA: {
|
||||
return {
|
||||
...state,
|
||||
searchData: action.payload.searchData,
|
||||
searchHistory: action.payload.searchHistory,
|
||||
}
|
||||
}
|
||||
default:
|
||||
const unhandledActionType: never = type
|
||||
console.info(`Unhandled type: ${unhandledActionType}`)
|
||||
|
||||
Reference in New Issue
Block a user