mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Added preview functionality for home page
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import CategoryPage from '@/components/pages/category-page';
|
||||
import ProductPage from '@/components/pages/product-page';
|
||||
import SinglePage from '@/components/pages/single-page';
|
||||
import getQueryFromSlug from '@/helpers/get-query-from-slug';
|
||||
import { clientFetch } from 'lib/sanity/sanity.client';
|
||||
import { getCachedClient } from 'lib/sanity/sanity.client';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import CategoryPage from './pages/category-page';
|
||||
import ProductPage from './pages/product-page';
|
||||
import SinglePage from './pages/single-page';
|
||||
|
||||
export const revalidate = 43200; // 12 hours in seconds
|
||||
|
||||
@@ -17,7 +17,7 @@ export async function generateMetadata({
|
||||
|
||||
const { query = '', queryParams } = getQueryFromSlug(slug, locale);
|
||||
|
||||
const page = await clientFetch(query, queryParams);
|
||||
const page = await getCachedClient()(query, queryParams);
|
||||
|
||||
if (!page) return notFound();
|
||||
|
||||
@@ -47,11 +47,11 @@ export default async function Page({ params }: PageParams) {
|
||||
let pageData;
|
||||
|
||||
if (docType === 'page') {
|
||||
pageData = await clientFetch(query, queryParams);
|
||||
pageData = await getCachedClient()(query, queryParams);
|
||||
} else if (docType === 'product') {
|
||||
pageData = await clientFetch(query, queryParams);
|
||||
pageData = await getCachedClient()(query, queryParams);
|
||||
} else if (docType === 'category') {
|
||||
pageData = await clientFetch(query, queryParams);
|
||||
pageData = await getCachedClient()(query, queryParams);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@@ -1,26 +0,0 @@
|
||||
import Search from '@/components/search/search';
|
||||
import SearchResult from '@/components/search/search-result';
|
||||
import Text from '@/components/ui/text/text';
|
||||
|
||||
interface CategoryPageParams {
|
||||
data: object | any;
|
||||
}
|
||||
|
||||
export default function CategoryPage({ data }: CategoryPageParams) {
|
||||
const category = data;
|
||||
|
||||
const { title } = category;
|
||||
|
||||
return (
|
||||
<div className="my-8 flex w-full flex-col px-4 lg:my-12 lg:px-8 2xl:px-16">
|
||||
{title && (
|
||||
<Text className="mb-8 lg:mb-12" variant="pageHeading">
|
||||
{title}
|
||||
</Text>
|
||||
)}
|
||||
<Search isCategory placeholder={title.toLowerCase()}>
|
||||
<SearchResult />
|
||||
</Search>
|
||||
</div>
|
||||
);
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
import ProductView from '@/components/product/product-view';
|
||||
interface ProductPageParams {
|
||||
data: object | any;
|
||||
}
|
||||
|
||||
export default function ProductPage({ data }: ProductPageParams) {
|
||||
const product = data;
|
||||
|
||||
const productJsonLd = {
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'Product',
|
||||
name: product.name,
|
||||
description: product.description,
|
||||
image: product.images[0].asset.url
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify(productJsonLd)
|
||||
}}
|
||||
/>
|
||||
<ProductView product={product} relatedProducts={[]} />;
|
||||
</>
|
||||
);
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
import DynamicContentManager from '@/components/layout/dynamic-content-manager/dynamic-content-manager';
|
||||
|
||||
interface SinglePageParams {
|
||||
data: object | any;
|
||||
}
|
||||
|
||||
export default function SinglePage({ data }: SinglePageParams) {
|
||||
return (
|
||||
<>
|
||||
<DynamicContentManager content={data?.content} />;
|
||||
</>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user