Merged in feat/SW-1454-listing-skeletons (pull request #1301)

Feat/SW-1454 listing skeletons

* feat(SW-1453): added skeleton for city listning

* feat(SW-1454): added skeleton for hotel listning


Approved-by: Fredrik Thorsson
This commit is contained in:
Erik Tiekstra
2025-02-11 12:05:44 +00:00
parent 967c776ab8
commit ff820d1f31
17 changed files with 325 additions and 135 deletions

View File

@@ -0,0 +1,5 @@
import { z } from "zod"
export const getHotelListDataInput = z.object({
cityIdentifier: z.string(),
})

View File

@@ -8,6 +8,8 @@ import { contentStackUidWithServiceProcedure, router } from "@/server/trpc"
import { generateTag } from "@/utils/generateTag"
import { getHotelListData } from "../../hotels/utils"
import { getHotelListDataInput } from "./input"
import {
destinationCityPageRefsSchema,
destinationCityPageSchema,
@@ -20,7 +22,7 @@ import {
getDestinationCityPageRefsSuccessCounter,
getDestinationCityPageSuccessCounter,
} from "./telemetry"
import { generatePageTags, getHotelListData } from "./utils"
import { generatePageTags } from "./utils"
import type {
GetDestinationCityPageData,
@@ -147,12 +149,6 @@ export const destinationCityPageQueryRouter = router({
return null
}
const hotels = await getHotelListData(
lang,
serviceToken,
validatedResponse.data.destinationCityPage.destination_settings.city
)
getDestinationCityPageSuccessCounter.add(1, { lang, uid: `${uid}` })
console.info(
"contentstack.destinationCityPage success",
@@ -163,7 +159,18 @@ export const destinationCityPageQueryRouter = router({
return {
...validatedResponse.data,
hotels,
cityIdentifier:
validatedResponse.data.destinationCityPage.destination_settings.city,
}
}),
hotelList: contentStackUidWithServiceProcedure
.input(getHotelListDataInput)
.query(async ({ ctx, input }) => {
const { lang, serviceToken } = ctx
const { cityIdentifier } = input
const hotels = await getHotelListData(lang, serviceToken, cityIdentifier)
return hotels
}),
})

View File

@@ -1,11 +1,6 @@
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
import { getHotel } from "../../hotels/query"
import { getHotelIdsByCityIdentifier } from "../../hotels/utils"
import { getHotelPageUrl } from "../hotelPage/utils"
import { DestinationCityPageEnum } from "@/types/enums/destinationCityPage"
import type { HotelData } from "@/types/hotel"
import type { System } from "@/types/requests/system"
import type { DestinationCityPageRefs } from "@/types/trpc/routers/contentstack/destinationCityPage"
import type { Lang } from "@/constants/languages"
@@ -56,29 +51,3 @@ export function getConnections({
return connections
}
export async function getHotelListData(
lang: Lang,
serviceToken: string,
cityIdentifier: string
) {
const hotelIds = await getHotelIdsByCityIdentifier(
cityIdentifier,
serviceToken
)
const hotels = await Promise.all(
hotelIds.map(async (hotelId) => {
const [hotelData, url] = await Promise.all([
getHotel({ hotelId, language: lang }, serviceToken),
getHotelPageUrl(lang, hotelId),
])
return hotelData ? { ...hotelData, url } : null
})
)
return hotels.filter(
(hotel): hotel is HotelData & { url: string | null } => !!hotel
)
}