mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 05:56:59 +00:00
Tried some updates
This commit is contained in:
parent
ac9d8c4386
commit
524b9c5818
@ -2,9 +2,10 @@ import getQueryFromSlug from '@/helpers/get-query-from-slug';
|
||||
import { clientFetch } from 'lib/sanity/sanity.client';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import CategoryPage from './components/category-page';
|
||||
import ProductPage from './components/product-page';
|
||||
import SinglePage from './components/single-page';
|
||||
import CategoryPage from './pages/category-page';
|
||||
import HomePage from './pages/home-page';
|
||||
import ProductPage from './pages/product-page';
|
||||
import SinglePage from './pages/single-page';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
@ -48,6 +49,7 @@ export default async function Page({ params }: PageParams) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{docType === 'home' && <HomePage query={query} queryParams={queryParams} />}
|
||||
{docType === 'page' && <SinglePage query={query} queryParams={queryParams} />}
|
||||
{docType === 'product' && <ProductPage query={query} queryParams={queryParams} />}
|
||||
{docType === 'category' && <CategoryPage query={query} queryParams={queryParams} />}
|
22
app/[locale]/[[...slug]]/pages/home-page.tsx
Normal file
22
app/[locale]/[[...slug]]/pages/home-page.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import DynamicContentManager from '@/components/layout/dynamic-content-manager/dynamic-content-manager';
|
||||
import { clientFetch } from '@/lib/sanity/sanity.client';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
interface HomePageParams {
|
||||
query: string;
|
||||
queryParams: {
|
||||
locale: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function HomePage({ query = '', queryParams }: HomePageParams) {
|
||||
const homePage = await clientFetch(query, queryParams);
|
||||
|
||||
if (!homePage) return notFound();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<DynamicContentManager content={homePage?.content} />;
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
const getParamsFromSlug = (slugArray: string[], locale: string) => {
|
||||
let docType = ''
|
||||
|
||||
const [slugStart] = slugArray
|
||||
|
||||
// We now have to re-combine the slug array to match our slug in Sanity.
|
||||
const queryParams = {
|
||||
slug: `/${slugArray.join('/')}`,
|
||||
locale: locale
|
||||
}
|
||||
|
||||
if (slugStart === `produkt` || slugStart === `product`) {
|
||||
docType = `product`
|
||||
} else if (slugStart === `kategori` || slugStart === `category`) {
|
||||
docType = `category`
|
||||
} else {
|
||||
docType = `page`
|
||||
}
|
||||
|
||||
return {
|
||||
docType,
|
||||
queryParams,
|
||||
}
|
||||
}
|
||||
|
||||
export default getParamsFromSlug
|
@ -1,17 +1,29 @@
|
||||
import {
|
||||
categoryQuery,
|
||||
homePageQuery,
|
||||
pageQuery,
|
||||
productQuery
|
||||
} from '@/lib/sanity/queries'
|
||||
import { groq } from 'next-sanity'
|
||||
} from '@/lib/sanity/queries';
|
||||
import { groq } from 'next-sanity';
|
||||
|
||||
const getQueryFromSlug = (slugArray: string[], locale: string) => {
|
||||
const docQuery: { [index: string]: string } = {
|
||||
'home': groq`${homePageQuery}`,
|
||||
'product': groq`${productQuery}`,
|
||||
'category': groq`${categoryQuery}`,
|
||||
'page': groq`${pageQuery}`,
|
||||
}
|
||||
|
||||
if (!slugArray) {
|
||||
return {
|
||||
docType: "home",
|
||||
queryParams: {
|
||||
locale: locale
|
||||
},
|
||||
query: docQuery.home,
|
||||
}
|
||||
}
|
||||
|
||||
let docType = ''
|
||||
|
||||
const [slugStart] = slugArray
|
||||
@ -21,7 +33,6 @@ const getQueryFromSlug = (slugArray: string[], locale: string) => {
|
||||
slug: `/${slugArray.join("/")}`,
|
||||
locale: locale
|
||||
};
|
||||
console.log(slugStart)
|
||||
|
||||
if (slugStart === `produkt` || slugStart === `product`) {
|
||||
docType = `product`
|
||||
|
@ -164,11 +164,9 @@ export const reusableSection = `
|
||||
export const homePageQuery = `*[_type == "home" && language == $locale][0] {
|
||||
_type,
|
||||
title,
|
||||
"slug": slug.current,
|
||||
"locale": language,
|
||||
"translations": *[_type == "translation.metadata" && references(^._id)].translations[].value->{
|
||||
title,
|
||||
"slug": slug.current,
|
||||
"locale": language
|
||||
},
|
||||
content[] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user