feat: SW-693 Moved borwser storage code in useEffect of component
This commit is contained in:
@@ -4,33 +4,18 @@ import {
|
||||
type InitState,
|
||||
type State,
|
||||
} from "@/types/components/form/bookingwidget"
|
||||
import type { Location, Locations } from "@/types/trpc/routers/hotel/locations"
|
||||
import type { Locations } from "@/types/trpc/routers/hotel/locations"
|
||||
|
||||
export const localStorageKey = "searchHistory"
|
||||
export function getSearchHistoryFromLocalStorage() {
|
||||
if (typeof window !== "undefined") {
|
||||
const storageSearchHistory = window.localStorage.getItem(localStorageKey)
|
||||
if (storageSearchHistory) {
|
||||
const parsedStorageSearchHistory: Locations =
|
||||
JSON.parse(storageSearchHistory)
|
||||
if (parsedStorageSearchHistory?.length) {
|
||||
return parsedStorageSearchHistory
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export const sessionStorageKey = "searchData"
|
||||
|
||||
export function init(initState: InitState): State {
|
||||
const searchHistory = getSearchHistoryFromLocalStorage()
|
||||
return {
|
||||
defaultLocations: initState.defaultLocations,
|
||||
locations: [],
|
||||
search: "",
|
||||
searchData: initState.searchData,
|
||||
searchHistory,
|
||||
searchData: undefined,
|
||||
searchHistory: null,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user