feat(SW-885): ancillary and book next stay

This commit is contained in:
Simon Emanuelsson
2024-12-12 13:39:49 +01:00
parent f531350e2e
commit 9d4998c9c5
12 changed files with 114 additions and 51 deletions

View File

@@ -10,11 +10,20 @@ export const localStorageKey = "searchHistory"
export const sessionStorageKey = "searchData"
export function init(initState: InitState): State {
const locations = []
if (initState.initialValue) {
const location = initState.defaultLocations.find(
(loc) => loc.name.toLowerCase() === initState.initialValue!.toLowerCase()
)
if (location) {
locations.push(location)
}
}
return {
defaultLocations: initState.defaultLocations,
locations: [],
search: "",
searchData: undefined,
locations,
search: locations.length ? locations[0].name : "",
searchData: locations.length ? locations[0] : undefined,
searchHistory: null,
}
}
@@ -73,8 +82,12 @@ export function reducer(state: State, action: Action) {
case ActionType.SET_STORAGE_DATA: {
return {
...state,
searchData: action.payload.searchData,
searchHistory: action.payload.searchHistory,
searchData: action.payload.searchData
? action.payload.searchData
: state.searchData,
searchHistory: action.payload.searchHistory
? action.payload.searchHistory
: state.searchHistory,
}
}
default: