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
)
}

View File

@@ -0,0 +1,7 @@
import { z } from "zod"
import { Country } from "@/types/enums/country"
export const getCityPagesInput = z.object({
country: z.nativeEnum(Country),
})

View File

@@ -4,11 +4,16 @@ import {
} from "@/lib/graphql/Query/DestinationCountryPage/DestinationCountryPage.graphql"
import { request } from "@/lib/graphql/request"
import { notFound } from "@/server/errors/trpc"
import { contentStackUidWithServiceProcedure, router } from "@/server/trpc"
import {
contentStackBaseWithServiceProcedure,
contentStackUidWithServiceProcedure,
router,
} from "@/server/trpc"
import { toApiLang } from "@/server/utils"
import { generateTag } from "@/utils/generateTag"
import { getCityPagesInput } from "./input"
import {
destinationCountryPageRefsSchema,
destinationCountryPageSchema,
@@ -151,12 +156,8 @@ export const destinationCountryPageQueryRouter = router({
)
return null
}
const cities = await getCityPages(
lang,
serviceToken,
const country =
validatedResponse.data.destinationCountryPage.destination_settings.country
)
getDestinationCountryPageSuccessCounter.add(1, { lang, uid: `${uid}` })
console.info(
@@ -168,12 +169,17 @@ export const destinationCountryPageQueryRouter = router({
return {
...validatedResponse.data,
translatedCountry:
ApiCountry[lang][
validatedResponse.data.destinationCountryPage.destination_settings
.country
],
cities,
translatedCountry: ApiCountry[lang][country],
}
}),
cityPages: contentStackBaseWithServiceProcedure
.input(getCityPagesInput)
.query(async ({ ctx, input }) => {
const { lang, serviceToken } = ctx
const { country } = input
const cities = await getCityPages(lang, serviceToken, country)
return cities
}),
})

View File

@@ -6,6 +6,7 @@ import { env } from "@/env/server"
import * as api from "@/lib/api"
import { toApiLang } from "@/server/utils"
import { getHotelPageUrl } from "../contentstack/hotelPage/utils"
import { metrics } from "./metrics"
import {
citiesByCountrySchema,
@@ -14,10 +15,12 @@ import {
getHotelIdsSchema,
locationsSchema,
} from "./output"
import { getHotel } from "./query"
import type { Country } from "@/types/enums/country"
import { PointOfInterestGroupEnum } from "@/types/enums/pointOfInterest"
import type { RequestOptionsWithOutBody } from "@/types/fetch"
import type { HotelData } from "@/types/hotel"
import type {
CitiesGroupedByCountry,
CityLocation,
@@ -477,3 +480,29 @@ export async function getCityIdByCityIdentifier(
return cityId ?? null
}
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
)
}