From 5d2587efc42355a67edc6d028c45e0eb4640f9eb Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 9 Nov 2023 15:50:57 -0800 Subject: [PATCH] Clear TS issues on lib --- app/[...slug]/page.tsx | 11 +++--- app/api/draft/route.tsx | 2 +- app/layout.tsx | 6 +-- app/page.tsx | 4 +- src/components/global/page-header.tsx | 4 +- src/components/layouts/interior-page.tsx | 4 +- src/components/paragraphs/paragraph.tsx | 4 +- src/components/paragraphs/rows/rows.tsx | 31 ++++++++++------ src/lib/drupal/deserialize.tsx | 4 +- src/lib/drupal/get-access-token.tsx | 2 +- src/lib/drupal/get-menu.tsx | 47 ++++++++++-------------- src/lib/drupal/get-paths.tsx | 40 ++++---------------- src/lib/drupal/get-resource.tsx | 36 ++++++++++-------- src/lib/drupal/get-search-index.tsx | 15 +------- src/lib/drupal/get-view.tsx | 2 +- src/lib/drupal/translate-path.tsx | 1 + src/lib/drupal/utils.tsx | 46 +++++++++++------------ 17 files changed, 115 insertions(+), 144 deletions(-) diff --git a/app/[...slug]/page.tsx b/app/[...slug]/page.tsx index 5234e0a0..4322cd2f 100644 --- a/app/[...slug]/page.tsx +++ b/app/[...slug]/page.tsx @@ -30,18 +30,19 @@ class RedirectError extends Error { } const getPageData = async(params: Params): Promise => { - const draftDev = isDraftMode() - const accessToken = draftDev ? await getAccessToken(true) : null; + const draftMode = isDraftMode() + const accessToken = draftMode ? await getAccessToken(true) : null; const path = await translatePathFromContext({params}, accessToken ? {accessToken} : {}); // Check for redirect. - if (path?.redirect?.[0].to) { + if (path?.redirect && path?.redirect?.[0].to) { const currentPath = '/' + (typeof params?.slug === 'object' ? params.slug.join('/') : params?.slug); - const [destination] = path.redirect; + const [destination] = path.redirect; if (destination.to != currentPath) { throw new RedirectError(destination.to); } + } if (!path || !path.jsonapi) { @@ -51,7 +52,7 @@ const getPageData = async(params: Params): Promise => if (params?.slug?.[0] === 'node' && path?.entity?.path) { throw new RedirectError(path.entity.path); } - return getResourceFromContext(path.jsonapi.resourceName, {params}, {}, draftDev) + return getResourceFromContext(path.jsonapi.resourceName, {params}, {draftMode}) } export const generateStaticParams = async () => { diff --git a/app/api/draft/route.tsx b/app/api/draft/route.tsx index b6365505..8719307c 100644 --- a/app/api/draft/route.tsx +++ b/app/api/draft/route.tsx @@ -20,7 +20,7 @@ export async function GET(request: Request) { // Fetch the headless CMS to check if the provided `slug` exists // getPostBySlug would implement the required fetching logic to the headless CMS - const node = await getResourceByPath(slug, {}, true) + const node = await getResourceByPath(slug, {draftMode: true}) // If the slug doesn't exist prevent draft mode from being enabled if (!node) { diff --git a/app/layout.tsx b/app/layout.tsx index 2796afd2..280d2ebf 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -14,11 +14,11 @@ export const metadata = { export const revalidate = 3600; const RootLayout = ({children, modal}: { children: React.ReactNode, modal?: React.ReactNode }) => { - const draftDev = isDraftMode(); + const draftMode = isDraftMode(); return ( - {draftDev && } - {(!draftDev && process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID) && + {draftMode && } + {(!draftMode && process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID) && <>