From e566c1f451d80f0ebfbe70d095cc1b472af6dc4d Mon Sep 17 00:00:00 2001 From: Henrik Larsson Date: Tue, 8 Aug 2023 22:36:13 +0200 Subject: [PATCH] Dynamic imports --- app/[locale]/globals.css | 4 +- app/[locale]/page.tsx | 22 +++++--- .../dynamic-content-manager.tsx | 21 ++++++-- components/layout/footer/footer.tsx | 2 +- components/layout/header/header.tsx | 2 +- .../modules/blurb-section/blurb-section.tsx | 6 +-- .../filtered-product-list.tsx | 24 ++++----- components/modules/hero/hero.tsx | 4 +- components/modules/slider/slider.tsx | 43 +++++++-------- components/product/product-view.tsx | 54 ++++++++++--------- components/ui/product-card/product-card.tsx | 5 +- 11 files changed, 99 insertions(+), 88 deletions(-) diff --git a/app/[locale]/globals.css b/app/[locale]/globals.css index 2d7943a69..c59a0eb76 100644 --- a/app/[locale]/globals.css +++ b/app/[locale]/globals.css @@ -153,11 +153,11 @@ body { } .glider-prev { - @apply !-top-10 !left-auto !right-12 text-high-contrast !transition-transform !duration-100 hover:scale-110 hover:!text-high-contrast lg:!-top-10 lg:!right-16 2xl:!-top-12 2xl:!right-[100px]; + @apply !-top-10 !left-auto !right-12 text-high-contrast !transition-transform !duration-100 hover:scale-110 hover:!text-high-contrast lg:!-top-12 lg:!right-16 2xl:!right-[100px]; } .glider-next { - @apply !-top-10 !right-4 text-high-contrast !transition-transform !duration-100 hover:scale-110 hover:!text-high-contrast lg:!-top-10 lg:!right-8 2xl:!-top-12 2xl:!right-16; + @apply !-top-10 !right-4 text-high-contrast !transition-transform !duration-100 hover:scale-110 hover:!text-high-contrast lg:!-top-12 lg:!right-8 2xl:!right-16; } .pdp .glider-prev { diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index 4cdfde43d..53c2e6fb8 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -1,14 +1,24 @@ import DynamicContentManager from 'components/layout/dynamic-content-manager/dynamic-content-manager'; import { homePageQuery } from 'lib/sanity/queries'; import { clientFetch } from 'lib/sanity/sanity.client'; +import { Metadata } from 'next'; +import { notFound } from 'next/navigation'; export const runtime = 'edge'; -export const metadata = { - description: 'High-performance ecommerce store built with Next.js, Vercel, Sanity and Storm.', - openGraph: { - type: 'website' - } -}; +export async function generateMetadata({ + params +}: { + params: { slug: string; locale: string }; +}): Promise { + const homePage = await clientFetch(homePageQuery, params); + + if (!homePage) return notFound(); + + return { + title: homePage.seo.title || homePage.title, + description: homePage.seo.description || homePage.description + }; +} interface HomePageParams { params: { diff --git a/components/layout/dynamic-content-manager/dynamic-content-manager.tsx b/components/layout/dynamic-content-manager/dynamic-content-manager.tsx index c674264e5..81dedaf88 100644 --- a/components/layout/dynamic-content-manager/dynamic-content-manager.tsx +++ b/components/layout/dynamic-content-manager/dynamic-content-manager.tsx @@ -1,13 +1,12 @@ 'use client'; -import { InfoCircledIcon } from '@radix-ui/react-icons'; - import BlurbSection from '@/components/modules/blurb-section/blurb-section'; import FilteredProductList from '@/components/modules/filtered-product-list/filtered-product-list'; import Hero from '@/components/modules/hero'; import ReusableSection from '@/components/modules/reusable-section/reusable-section'; import Slider from '@/components/modules/slider/slider'; import USPSection from '@/components/modules/usp-section/usp-section'; +import { InfoCircledIcon } from '@radix-ui/react-icons'; interface getContentComponentProps { _type: string; _key: number; @@ -19,13 +18,25 @@ const getContentComponent = ({ _type, _key, disabled, ...rest }: getContentCompo switch (_type) { case 'hero': - Component = Hero; + if (disabled !== true) { + Component = Hero; + } else { + return; + } break; case 'slider': - Component = Slider; + if (disabled !== true) { + Component = Slider; + } else { + return; + } break; case 'filteredProductList': - Component = FilteredProductList; + if (disabled !== true) { + Component = FilteredProductList; + } else { + return; + } break; case 'blurbSection': if (disabled !== true) { diff --git a/components/layout/footer/footer.tsx b/components/layout/footer/footer.tsx index 0362e1c66..e4722895a 100644 --- a/components/layout/footer/footer.tsx +++ b/components/layout/footer/footer.tsx @@ -21,7 +21,7 @@ export default async function Footer({ locale }: FooterProps) {