From 689c21b69ab994b92f14640192750ab0adcfac16 Mon Sep 17 00:00:00 2001 From: tobias Date: Mon, 24 Jun 2024 13:52:06 +0200 Subject: [PATCH] Separate posts & pages previews --- payload.config.ts | 6 +++-- .../{ => pages}/preview/[[...path]]/page.tsx | 0 .../(app)/posts/preview/[[...path]]/page.tsx | 25 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) rename src/app/(app)/{ => pages}/preview/[[...path]]/page.tsx (100%) create mode 100644 src/app/(app)/posts/preview/[[...path]]/page.tsx diff --git a/payload.config.ts b/payload.config.ts index dc708e0..26fa61b 100644 --- a/payload.config.ts +++ b/payload.config.ts @@ -42,8 +42,10 @@ export default buildConfig({ prefillOnly: true, }, livePreview: { - url: ({ data, locale }) => - `${process.env.BASE_URL}/preview${data.path}${locale ? `?locale=${locale.code}` : ''}`, + url: ({ data, locale, collectionConfig }) => + `${process.env.BASE_URL}/${collectionConfig?.slug || ''}/preview${data.path}${ + locale ? `?locale=${locale.code}` : '' + }`, collections: [COLLECTION_SLUG_PAGE, COLLECTION_SLUG_POST], }, }, diff --git a/src/app/(app)/preview/[[...path]]/page.tsx b/src/app/(app)/pages/preview/[[...path]]/page.tsx similarity index 100% rename from src/app/(app)/preview/[[...path]]/page.tsx rename to src/app/(app)/pages/preview/[[...path]]/page.tsx diff --git a/src/app/(app)/posts/preview/[[...path]]/page.tsx b/src/app/(app)/posts/preview/[[...path]]/page.tsx new file mode 100644 index 0000000..11eb5a2 --- /dev/null +++ b/src/app/(app)/posts/preview/[[...path]]/page.tsx @@ -0,0 +1,25 @@ +import PreviewBlocks from '@/components/PreviewBlocks' +import { getCurrentUser } from '@/lib/payload' +import { COLLECTION_SLUG_POST } from '@payload/collections/config' +import { getDocument } from '@/utils/getDocument' +import { unstable_noStore as noStore } from 'next/cache' +import { notFound } from 'next/navigation' +import PreviewPostPage from '@/components/PreviewPostPage' + +const PreviewCatchAllPage = async ({ params }: { params: { path: string[] } }) => { + noStore() + const [user, page] = await Promise.all([ + getCurrentUser(), + getDocument({ + collection: COLLECTION_SLUG_POST, + path: params.path, + depth: 3, + cache: false, + }), + ]) + if (!user || !page) notFound() + + return +} + +export default PreviewCatchAllPage