From f8183a5a698b0a9c6caabea1cb634111d4add66d Mon Sep 17 00:00:00 2001 From: Henrik Larsson Date: Fri, 18 Aug 2023 15:31:44 +0200 Subject: [PATCH] Intitial commit --- app/(site)/[locale]/page.tsx | 39 ++--- components/layout/footer/footer.tsx | 11 +- components/layout/header/header.tsx | 18 +-- components/modules/hero/hero.tsx | 7 +- components/pages/home-page.tsx | 6 +- components/ui/sanity-image/sanity-image.tsx | 150 ++++++++++++-------- lib/sanity/sanity.api.ts | 33 +++++ lib/sanity/sanity.client.ts | 45 ++---- lib/sanity/sanity.fetch.ts | 61 ++++++++ lib/sanity/sanity.image.ts | 7 +- lib/sanity/sanity.types.ts | 12 ++ package.json | 2 +- pnpm-lock.yaml | 18 +-- 13 files changed, 268 insertions(+), 141 deletions(-) create mode 100644 lib/sanity/sanity.api.ts create mode 100644 lib/sanity/sanity.fetch.ts create mode 100644 lib/sanity/sanity.types.ts diff --git a/app/(site)/[locale]/page.tsx b/app/(site)/[locale]/page.tsx index 494659740..786bccd44 100644 --- a/app/(site)/[locale]/page.tsx +++ b/app/(site)/[locale]/page.tsx @@ -1,9 +1,9 @@ import HomePage from '@/components/pages/home-page'; import HomePagePreview from '@/components/pages/home-page-preview'; -import PreviewProvider from '@/components/preview-provider'; -import { homePageQuery } from 'lib/sanity/queries'; -import { getCachedClient } from 'lib/sanity/sanity.client'; +import { homePageQuery } from '@/lib/sanity/queries'; +import { getHomePage } from '@/lib/sanity/sanity.fetch'; import { Metadata } from 'next'; +import { LiveQuery } from 'next-sanity/preview/live-query'; import { draftMode } from 'next/headers'; import { notFound } from 'next/navigation'; @@ -13,15 +13,15 @@ export const dynamic = 'force-dynamic'; export async function generateMetadata({ params }: { - params: { slug: string; locale: string }; + params: { locale: string }; }): Promise { - const homePage = await getCachedClient()(homePageQuery, params); + const homePage = await getHomePage(params.locale); if (!homePage) return notFound(); return { - title: homePage.seo.title || homePage.title, - description: homePage.seo.description || homePage.description + title: homePage?.seo?.title || homePage.title, + description: homePage?.seo?.description }; } interface HomePageParams { @@ -31,19 +31,22 @@ interface HomePageParams { } export default async function IndexPage({ params }: HomePageParams) { - const preview = draftMode().isEnabled ? { token: process.env.SANITY_API_READ_TOKEN } : undefined; + // const preview = draftMode().isEnabled ? { token: process.env.SANITY_API_READ_TOKEN } : undefined; - const data = await getCachedClient(preview)(homePageQuery, params); + const data = await getHomePage(params.locale); - if (!data) return notFound(); - - if (preview && preview.token) { - return ( - - - - ); + if (!data && !draftMode().isEnabled) { + notFound(); } - return ; + return ( + + + + ); } diff --git a/components/layout/footer/footer.tsx b/components/layout/footer/footer.tsx index 27155e3f1..8f9a9d3b0 100644 --- a/components/layout/footer/footer.tsx +++ b/components/layout/footer/footer.tsx @@ -1,6 +1,5 @@ -import Text from '@/components/ui/text'; -import { footerMenusQuery } from '@/lib/sanity/queries'; -import { getCachedClient } from '@/lib/sanity/sanity.client'; +// import { footerMenusQuery } from '@/lib/sanity/queries'; +// import { getCachedClient } from '@/lib/sanity/sanity.client'; import LocaleSwitcher from 'components/ui/locale-switcher/locale-switcher'; import Logo from 'components/ui/logo/logo'; import Link from 'next/link'; @@ -15,7 +14,7 @@ export default async function Footer({ locale }: FooterProps) { locale: locale }; - const footerMenus = await getCachedClient()(footerMenusQuery, params); + // const footerMenus = await getCachedClient()(footerMenusQuery, params); return (