From c47966f9941da73ae0f20ae37ee6482b50ea1ec3 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Fri, 31 May 2024 09:23:37 +0200 Subject: [PATCH] fix: caching --- .../(live-current)/@languageSwitcher/page.tsx | 8 +++---- .../Header/MainMenu/mainMenu.module.css | 4 ++-- .../Current/Header/TopMenu/topMenu.module.css | 2 +- components/Current/Header/header.module.css | 2 +- lib/graphql/Query/AccountPage.graphql | 4 ++-- lib/graphql/Query/CurrentHeader.graphql | 11 +++++++++ .../Query/LanguageSwitcherCurrent.graphql | 4 ++-- lib/graphql/Query/LoyaltyPage.graphql | 4 ++-- .../routers/contentstack/accountPage/query.ts | 8 +++---- server/routers/contentstack/config/output.ts | 15 ++++++++++++ server/routers/contentstack/config/query.ts | 23 +++++++++++++++++-- .../routers/contentstack/loyaltyPage/query.ts | 8 +++---- 12 files changed, 69 insertions(+), 24 deletions(-) diff --git a/app/[lang]/(live-current)/@languageSwitcher/page.tsx b/app/[lang]/(live-current)/@languageSwitcher/page.tsx index 24881aa47..6b94c5f4d 100644 --- a/app/[lang]/(live-current)/@languageSwitcher/page.tsx +++ b/app/[lang]/(live-current)/@languageSwitcher/page.tsx @@ -1,7 +1,7 @@ import { batchRequest } from "@/lib/graphql/batchRequest" import { - GetDaDeEnUrls, - GetFiNoSvUrls, + GetDaDeEnUrlsCurrentBlocksPage, + GetFiNoSvUrlsCurrentBlocksPage, } from "@/lib/graphql/Query/LanguageSwitcherCurrent.graphql" import Desktop from "@/components/Current/Header/LanguageSwitcher/Desktop" @@ -26,11 +26,11 @@ export default async function LanguageSwitcher({ const { data: urls } = await batchRequest([ { - document: GetDaDeEnUrls, + document: GetDaDeEnUrlsCurrentBlocksPage, variables, }, { - document: GetFiNoSvUrls, + document: GetFiNoSvUrlsCurrentBlocksPage, variables, }, ]) diff --git a/components/Current/Header/MainMenu/mainMenu.module.css b/components/Current/Header/MainMenu/mainMenu.module.css index 45671e428..5d9647f4b 100644 --- a/components/Current/Header/MainMenu/mainMenu.module.css +++ b/components/Current/Header/MainMenu/mainMenu.module.css @@ -190,7 +190,7 @@ Helvetica Neue, Helvetica, Arial, - sans-serif; + sans-serif !important; font-weight: 700; background-color: transparent !important; text-decoration: none; @@ -234,7 +234,7 @@ margin-right: 8px; } -@media screen and (min-width: 1367px) { +@media screen and (min-width: 950px) { .mainMenu { box-shadow: none; background-color: hsla(0, 0%, 100%, 0.95); diff --git a/components/Current/Header/TopMenu/topMenu.module.css b/components/Current/Header/TopMenu/topMenu.module.css index adf863751..a1c7ad2a2 100644 --- a/components/Current/Header/TopMenu/topMenu.module.css +++ b/components/Current/Header/TopMenu/topMenu.module.css @@ -55,7 +55,7 @@ } } -@media screen and (min-width: 1367px) { +@media screen and (min-width: 950px) { .topMenu { background-color: #3d3835; display: block; diff --git a/components/Current/Header/header.module.css b/components/Current/Header/header.module.css index 84aabe42a..13035f53a 100644 --- a/components/Current/Header/header.module.css +++ b/components/Current/Header/header.module.css @@ -2,7 +2,7 @@ display: grid; } -@media screen and (max-width: 1366px) { +@media screen and (max-width: 950px) { .header { height: 50px; } diff --git a/lib/graphql/Query/AccountPage.graphql b/lib/graphql/Query/AccountPage.graphql index 785627f42..d69fc2bbd 100644 --- a/lib/graphql/Query/AccountPage.graphql +++ b/lib/graphql/Query/AccountPage.graphql @@ -63,7 +63,7 @@ query GetAccountPageRefs($locale: String!, $uid: String!) { } } -query GetDaDeEnUrls($uid: String!) { +query GetDaDeEnUrlsAccountPage($uid: String!) { de: all_account_page(where: { uid: $uid }, locale: "de") { items { url @@ -81,7 +81,7 @@ query GetDaDeEnUrls($uid: String!) { } } -query GetFiNoSvUrls($uid: String!) { +query GetFiNoSvUrlsAccountPage($uid: String!) { fi: all_account_page(where: { uid: $uid }, locale: "fi") { items { url diff --git a/lib/graphql/Query/CurrentHeader.graphql b/lib/graphql/Query/CurrentHeader.graphql index 364d1f62b..dc65aba09 100644 --- a/lib/graphql/Query/CurrentHeader.graphql +++ b/lib/graphql/Query/CurrentHeader.graphql @@ -1,4 +1,5 @@ #import "../Fragments/Image.graphql" +#import "../Fragments/Refs/System.graphql" query GetCurrentHeader($locale: String!) { all_current_header(limit: 1, locale: $locale) { @@ -30,3 +31,13 @@ query GetCurrentHeader($locale: String!) { } } } + +query GetCurrentHeaderRef($locale: String!) { + all_current_header(limit: 1, locale: $locale) { + items { + system { + ...System + } + } + } +} diff --git a/lib/graphql/Query/LanguageSwitcherCurrent.graphql b/lib/graphql/Query/LanguageSwitcherCurrent.graphql index 821d2c52b..ca99ff148 100644 --- a/lib/graphql/Query/LanguageSwitcherCurrent.graphql +++ b/lib/graphql/Query/LanguageSwitcherCurrent.graphql @@ -1,4 +1,4 @@ -query GetDaDeEnUrls($uid: String!) { +query GetDaDeEnUrlsCurrentBlocksPage($uid: String!) { de: current_blocks_page(uid: $uid, locale: "de") { url: original_url } @@ -10,7 +10,7 @@ query GetDaDeEnUrls($uid: String!) { } } -query GetFiNoSvUrls($uid: String!) { +query GetFiNoSvUrlsCurrentBlocksPage($uid: String!) { fi: current_blocks_page(uid: $uid, locale: "fi") { url: original_url } diff --git a/lib/graphql/Query/LoyaltyPage.graphql b/lib/graphql/Query/LoyaltyPage.graphql index 7dd189e30..668640ae0 100644 --- a/lib/graphql/Query/LoyaltyPage.graphql +++ b/lib/graphql/Query/LoyaltyPage.graphql @@ -246,7 +246,7 @@ query GetLoyaltyPageRefs($locale: String!, $uid: String!) { } } -query GetDaDeEnUrls($uid: String!) { +query GetDaDeEnUrlsLoyaltyPage($uid: String!) { de: all_loyalty_page(where: { uid: $uid }, locale: "de") { items { web { @@ -273,7 +273,7 @@ query GetDaDeEnUrls($uid: String!) { } } -query GetFiNoSvUrls($uid: String!) { +query GetFiNoSvUrlsLoyaltyPage($uid: String!) { sv: all_loyalty_page(where: { uid: $uid }, locale: "sv") { items { web { diff --git a/server/routers/contentstack/accountPage/query.ts b/server/routers/contentstack/accountPage/query.ts index 4bb778a1f..e15d6b467 100644 --- a/server/routers/contentstack/accountPage/query.ts +++ b/server/routers/contentstack/accountPage/query.ts @@ -3,8 +3,8 @@ import { batchRequest } from "@/lib/graphql/batchRequest" import { GetAccountPage, GetAccountPageRefs, - GetDaDeEnUrls, - GetFiNoSvUrls, + GetDaDeEnUrlsAccountPage, + GetFiNoSvUrlsAccountPage, } from "@/lib/graphql/Query/AccountPage.graphql" import { request } from "@/lib/graphql/request" import { internalServerError, notFound } from "@/server/errors/trpc" @@ -147,11 +147,11 @@ export const accountPageQueryRouter = router({ const res = await batchRequest([ { - document: GetDaDeEnUrls, + document: GetDaDeEnUrlsAccountPage, variables, }, { - document: GetFiNoSvUrls, + document: GetFiNoSvUrlsAccountPage, variables, }, ]) diff --git a/server/routers/contentstack/config/output.ts b/server/routers/contentstack/config/output.ts index 388b9a82b..08e2c04fb 100644 --- a/server/routers/contentstack/config/output.ts +++ b/server/routers/contentstack/config/output.ts @@ -118,3 +118,18 @@ export type HeaderData = Omit< > & { logo: Image } + +const validateHeaderRefConfigSchema = z.object({ + all_current_header: z.object({ + items: z.array( + z.object({ + system: z.object({ + content_type_uid: z.string(), + uid: z.string(), + }), + }) + ), + }), +}) + +export type HeaderRefDataRaw = z.infer diff --git a/server/routers/contentstack/config/query.ts b/server/routers/contentstack/config/query.ts index 286d89524..00a87f019 100644 --- a/server/routers/contentstack/config/query.ts +++ b/server/routers/contentstack/config/query.ts @@ -1,13 +1,19 @@ import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql" -import { GetCurrentHeader } from "@/lib/graphql/Query/CurrentHeader.graphql" +import { + GetCurrentHeader, + GetCurrentHeaderRef, +} from "@/lib/graphql/Query/CurrentHeader.graphql" import { request } from "@/lib/graphql/request" import { internalServerError, notFound } from "@/server/errors/trpc" import { contentstackProcedure, publicProcedure, router } from "@/server/trpc" +import { generateTag } from "@/utils/generateTag" + import { type ContactConfigData, HeaderData, HeaderDataRaw, + HeaderRefDataRaw, validateContactConfigSchema, validateHeaderConfigSchema, } from "./output" @@ -35,10 +41,23 @@ export const configQueryRouter = router({ return validatedContactConfigConfig.data.all_contact_config.items[0] }), header: publicProcedure.query(async ({ ctx }) => { + const responseRef = await request(GetCurrentHeaderRef, { + locale: ctx.lang, + }) + const response = await request( GetCurrentHeader, { locale: ctx.lang }, - { next: { tags: [`header-${ctx.lang}`] } } + { + next: { + tags: [ + generateTag( + ctx.lang, + responseRef.data.all_current_header.items[0].system.uid + ), + ], + }, + } ) if (!response.data) { diff --git a/server/routers/contentstack/loyaltyPage/query.ts b/server/routers/contentstack/loyaltyPage/query.ts index e9d14fbcc..32d8800f3 100644 --- a/server/routers/contentstack/loyaltyPage/query.ts +++ b/server/routers/contentstack/loyaltyPage/query.ts @@ -1,8 +1,8 @@ import { Lang } from "@/constants/languages" import { batchRequest } from "@/lib/graphql/batchRequest" import { - GetDaDeEnUrls, - GetFiNoSvUrls, + GetDaDeEnUrlsLoyaltyPage, + GetFiNoSvUrlsLoyaltyPage, GetLoyaltyPage, GetLoyaltyPageRefs, } from "@/lib/graphql/Query/LoyaltyPage.graphql" @@ -188,11 +188,11 @@ export const loyaltyPageQueryRouter = router({ const res = await batchRequest([ { - document: GetDaDeEnUrls, + document: GetDaDeEnUrlsLoyaltyPage, variables, }, { - document: GetFiNoSvUrls, + document: GetFiNoSvUrlsLoyaltyPage, variables, }, ])