feat(SW-66, SW-348): search functionality and ui

This commit is contained in:
Simon Emanuelsson
2024-08-28 10:47:57 +02:00
parent b9dbcf7d90
commit af850c90e7
437 changed files with 7663 additions and 9881 deletions

View File

@@ -6,23 +6,23 @@ import { batchRequest } from "@/lib/graphql/batchRequest"
import {
GetDaDeEnUrlsAccountPage,
GetFiNoSvUrlsAccountPage,
} from "@/lib/graphql/Query/AccountPage.graphql"
} from "@/lib/graphql/Query/AccountPage/AccountPage.graphql"
import {
GetDaDeEnUrlsContentPage,
GetFiNoSvUrlsContentPage,
} from "@/lib/graphql/Query/ContentPage.graphql"
import {
GetDaDeEnUrlsHotelPage,
GetFiNoSvUrlsHotelPage,
} from "@/lib/graphql/Query/HotelPage.graphql"
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
import {
GetDaDeEnUrlsCurrentBlocksPage,
GetFiNoSvUrlsCurrentBlocksPage,
} from "@/lib/graphql/Query/LanguageSwitcherCurrent.graphql"
} from "@/lib/graphql/Query/Current/LanguageSwitcher.graphql"
import {
GetDaDeEnUrlsHotelPage,
GetFiNoSvUrlsHotelPage,
} from "@/lib/graphql/Query/HotelPage/HotelPage.graphql"
import {
GetDaDeEnUrlsLoyaltyPage,
GetFiNoSvUrlsLoyaltyPage,
} from "@/lib/graphql/Query/LoyaltyPage.graphql"
} from "@/lib/graphql/Query/LoyaltyPage/LoyaltyPage.graphql"
import { internalServerError } from "@/server/errors/trpc"
import { publicProcedure, router } from "@/server/trpc"
@@ -65,128 +65,61 @@ async function getLanguageSwitcher(options: LanguageSwitcherVariables) {
generateTag(Lang.no, options.uid, languageSwitcherAffix),
generateTag(Lang.sv, options.uid, languageSwitcherAffix),
]
let daDeEnDocument = null
let fiNoSvDocument = null
switch (options.contentType) {
case PageTypeEnum.accountPage:
return await batchRequest<LanguageSwitcherQueryDataRaw>([
{
document: GetDaDeEnUrlsAccountPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsDaDeEn,
},
},
},
{
document: GetFiNoSvUrlsAccountPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsFiNoSv,
},
},
},
])
daDeEnDocument = GetDaDeEnUrlsAccountPage
fiNoSvDocument = GetFiNoSvUrlsAccountPage
break
case PageTypeEnum.currentBlocksPage:
return await batchRequest<LanguageSwitcherQueryDataRaw>([
{
document: GetDaDeEnUrlsCurrentBlocksPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsDaDeEn,
},
},
},
{
document: GetFiNoSvUrlsCurrentBlocksPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsFiNoSv,
},
},
},
])
daDeEnDocument = GetDaDeEnUrlsCurrentBlocksPage
fiNoSvDocument = GetFiNoSvUrlsCurrentBlocksPage
break
case PageTypeEnum.loyaltyPage:
return await batchRequest<LanguageSwitcherQueryDataRaw>([
{
document: GetDaDeEnUrlsLoyaltyPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsDaDeEn,
},
},
},
{
document: GetFiNoSvUrlsLoyaltyPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsFiNoSv,
},
},
},
])
daDeEnDocument = GetDaDeEnUrlsLoyaltyPage
fiNoSvDocument = GetFiNoSvUrlsLoyaltyPage
break
case PageTypeEnum.hotelPage:
return await batchRequest<LanguageSwitcherQueryDataRaw>([
{
document: GetDaDeEnUrlsHotelPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsDaDeEn,
},
},
},
{
document: GetFiNoSvUrlsHotelPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsFiNoSv,
},
},
},
])
daDeEnDocument = GetDaDeEnUrlsHotelPage
fiNoSvDocument = GetFiNoSvUrlsHotelPage
break
case PageTypeEnum.contentPage:
return await batchRequest<LanguageSwitcherQueryDataRaw>([
{
document: GetDaDeEnUrlsContentPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsDaDeEn,
},
},
},
{
document: GetFiNoSvUrlsContentPage,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsFiNoSv,
},
},
},
])
daDeEnDocument = GetDaDeEnUrlsContentPage
fiNoSvDocument = GetFiNoSvUrlsContentPage
break
default:
console.error(`type: [${options.contentType}]`)
console.error(`Trying to get a content type that is not supported`)
throw internalServerError()
}
if (daDeEnDocument && fiNoSvDocument) {
return await batchRequest<LanguageSwitcherQueryDataRaw>([
{
document: daDeEnDocument,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsDaDeEn,
},
},
},
{
document: fiNoSvDocument,
variables,
options: {
cache: "force-cache",
next: {
tags: tagsFiNoSv,
},
},
},
])
}
throw internalServerError()
}
export const languageSwitcherQueryRouter = router({
@@ -213,9 +146,10 @@ export const languageSwitcherQueryRouter = router({
contentType: ctx.contentType!,
uid: ctx.uid,
})
const urls = Object.keys(res.data).reduce<LanguageSwitcherData>(
(acc, key) => {
const item = res.data[key as Lang]?.items[0]
const item = res.data[key as Lang]
const url = item
? item.web?.original_url || `/${key}${item.url}`
: undefined