|
1 |
| -import type { |
2 |
| - EditViewComponent, |
3 |
| - LivePreviewConfig, |
4 |
| - PayloadServerReactComponent, |
5 |
| - TypeWithID, |
6 |
| -} from 'payload' |
| 1 | +import type { EditViewComponent, LivePreviewConfig, PayloadServerReactComponent } from 'payload' |
7 | 2 |
|
8 |
| -import { notFound } from 'next/navigation.js' |
9 | 3 | import React from 'react'
|
10 | 4 |
|
11 |
| -import { LivePreviewClient } from './index.client.js' |
12 | 5 | import './index.scss'
|
| 6 | +import { LivePreviewClient } from './index.client.js' |
13 | 7 |
|
14 | 8 | export const LivePreviewView: PayloadServerReactComponent<EditViewComponent> = async (props) => {
|
15 |
| - const { initPageResult } = props |
16 |
| - |
17 |
| - const { |
18 |
| - collectionConfig, |
19 |
| - docID, |
20 |
| - globalConfig, |
21 |
| - locale, |
22 |
| - req: { |
23 |
| - payload: { |
24 |
| - config: { |
25 |
| - admin: { livePreview: topLevelLivePreviewConfig }, |
26 |
| - }, |
27 |
| - } = {}, |
28 |
| - } = {}, |
29 |
| - } = initPageResult |
30 |
| - |
31 |
| - let data: Record<string, unknown> | TypeWithID |
| 9 | + const { doc, initPageResult } = props |
32 | 10 |
|
33 |
| - try { |
34 |
| - if (collectionConfig) { |
35 |
| - data = await initPageResult.req.payload.findByID({ |
36 |
| - id: docID, |
37 |
| - collection: collectionConfig.slug, |
38 |
| - depth: 0, |
39 |
| - draft: true, |
40 |
| - fallbackLocale: false, |
41 |
| - locale: locale?.code, |
42 |
| - }) |
43 |
| - } |
44 |
| - |
45 |
| - if (globalConfig) { |
46 |
| - data = await initPageResult.req.payload.findGlobal({ |
47 |
| - slug: globalConfig.slug, |
48 |
| - depth: 0, |
49 |
| - draft: true, |
50 |
| - fallbackLocale: false, |
51 |
| - locale: locale?.code, |
52 |
| - }) |
53 |
| - } |
54 |
| - } catch (error) { |
55 |
| - notFound() |
56 |
| - } |
| 11 | + const { collectionConfig, globalConfig, locale, req } = initPageResult |
57 | 12 |
|
58 |
| - let livePreviewConfig: LivePreviewConfig = topLevelLivePreviewConfig |
| 13 | + let livePreviewConfig: LivePreviewConfig = req.payload.config?.admin?.livePreview |
59 | 14 |
|
60 | 15 | if (collectionConfig) {
|
61 | 16 | livePreviewConfig = {
|
@@ -85,12 +40,12 @@ export const LivePreviewView: PayloadServerReactComponent<EditViewComponent> = a
|
85 | 40 | typeof livePreviewConfig?.url === 'function'
|
86 | 41 | ? await livePreviewConfig.url({
|
87 | 42 | collectionConfig,
|
88 |
| - data, |
| 43 | + data: doc, |
89 | 44 | globalConfig,
|
90 | 45 | locale,
|
91 | 46 | payload: initPageResult.req.payload,
|
92 | 47 | })
|
93 | 48 | : livePreviewConfig?.url
|
94 | 49 |
|
95 |
| - return <LivePreviewClient breakpoints={breakpoints} initialData={data} url={url} /> |
| 50 | + return <LivePreviewClient breakpoints={breakpoints} initialData={doc} url={url} /> |
96 | 51 | }
|
0 commit comments