Merged in feature/bookingwidget-client-side (pull request #1481)
Move more of BookingWidget to client SW-1639 * feat: move getLocations in booking widget to client side so that it's also cached on the client reducing the blinking when switching urls (and reducing duplicate calls) Approved-by: Linus Flood
This commit is contained in:
@@ -3,6 +3,7 @@ import { notFound } from "next/navigation"
|
||||
import { getLocations } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import { generateChildrenString } from "@/components/HotelReservation/utils"
|
||||
import { safeTry } from "@/utils/safeTry"
|
||||
import { convertSearchParamsToObj, type SelectHotelParams } from "@/utils/url"
|
||||
|
||||
import type {
|
||||
@@ -46,13 +47,14 @@ export async function getHotelSearchDetails<
|
||||
): Promise<HotelSearchDetails<T> | null> {
|
||||
const selectHotelParams = convertSearchParamsToObj<T>(searchParams)
|
||||
|
||||
const locations = await getLocations()
|
||||
|
||||
if (!locations || "error" in locations) return null
|
||||
const [locations, error] = await safeTry(getLocations())
|
||||
if (!locations || error) {
|
||||
return null
|
||||
}
|
||||
|
||||
const hotel =
|
||||
("hotelId" in selectHotelParams &&
|
||||
(locations.data.find(
|
||||
(locations.find(
|
||||
(location) =>
|
||||
isHotelLocation(location) &&
|
||||
"operaId" in location &&
|
||||
@@ -72,7 +74,7 @@ export async function getHotelSearchDetails<
|
||||
|
||||
const city =
|
||||
(typeof cityName === "string" &&
|
||||
locations.data.find(
|
||||
locations.find(
|
||||
(location) => location.name.toLowerCase() === cityName.toLowerCase()
|
||||
)) ||
|
||||
null
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { env } from "@/env/server"
|
||||
import { getHotel, getHotelPage } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import BookingWidget, { preload } from "@/components/BookingWidget"
|
||||
import BookingWidget from "@/components/BookingWidget"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import type { BookingWidgetSearchData } from "@/types/components/bookingWidget"
|
||||
@@ -16,8 +16,6 @@ export default async function BookingWidgetPage({
|
||||
return null
|
||||
}
|
||||
|
||||
preload()
|
||||
|
||||
if (params.contentType === PageContentTypeEnum.hotelPage) {
|
||||
const hotelPageData = await getHotelPage()
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import BookingWidget, { preload } from "@/components/BookingWidget"
|
||||
import BookingWidget from "@/components/BookingWidget"
|
||||
|
||||
import type { BookingWidgetSearchData } from "@/types/components/bookingWidget"
|
||||
import type { LangParams, PageArgs } from "@/types/params"
|
||||
@@ -12,7 +12,5 @@ export default async function BookingWidgetPage({
|
||||
return null
|
||||
}
|
||||
|
||||
preload()
|
||||
|
||||
return <BookingWidget bookingWidgetSearchParams={searchParams} />
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { env } from "@/env/server"
|
||||
|
||||
import BookingWidget, { preload } from "@/components/BookingWidget"
|
||||
import BookingWidget from "@/components/BookingWidget"
|
||||
|
||||
import type { BookingWidgetSearchData } from "@/types/components/bookingWidget"
|
||||
import type { PageArgs } from "@/types/params"
|
||||
@@ -12,7 +12,5 @@ export default async function BookingWidgetPage({
|
||||
return null
|
||||
}
|
||||
|
||||
preload()
|
||||
|
||||
return <BookingWidget bookingWidgetSearchParams={searchParams} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user