@@ -13,7 +13,7 @@ import { notify } from '@/components/_shared/notify';
1313import { findAncestors , findView } from '@/components/_shared/outline/utils' ;
1414import { useService } from '@/components/main/app.hooks' ;
1515import { useLiveQuery } from 'dexie-react-hooks' ;
16- import { createContext , useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
16+ import React , { createContext , useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
1717import { useNavigate } from 'react-router-dom' ;
1818
1919export interface PublishContextType {
@@ -31,6 +31,8 @@ export interface PublishContextType {
3131 breadcrumbs : View [ ] ;
3232 rendered ?: boolean ;
3333 onRendered ?: ( ) => void ;
34+ commentEnabled ?: boolean ;
35+ duplicateEnabled ?: boolean ;
3436}
3537
3638export const PublishContext = createContext < PublishContextType | null > ( null ) ;
@@ -73,6 +75,13 @@ export const PublishProvider = ({
7375 } ;
7476 } , [ namespace , publishName , outline ] ) ;
7577
78+ const viewId = viewMeta ?. view_id ;
79+
80+ const [ publishInfo , setPublishInfo ] = React . useState < {
81+ commentEnabled : boolean ,
82+ duplicateEnabled : boolean ,
83+ } | undefined > ( ) ;
84+
7685 const originalCrumbs = useMemo ( ( ) => {
7786 if ( ! viewMeta || ! outline ) return [ ] ;
7887 const ancestors = findAncestors ( outline , viewMeta ?. view_id ) ;
@@ -175,6 +184,25 @@ export const PublishProvider = ({
175184 } ) ;
176185
177186 } , [ service , publishName ] ) ;
187+
188+ const loadPublishInfo = useCallback ( async ( ) => {
189+ if ( ! service || ! viewId ) return ;
190+ try {
191+ const res = await service . getPublishInfo ( viewId ) ;
192+
193+ setPublishInfo ( res ) ;
194+
195+ // eslint-disable-next-line
196+ } catch ( e : any ) {
197+ // do nothing
198+ }
199+
200+ } , [ viewId , service ] ) ;
201+
202+ useEffect ( ( ) => {
203+ void loadPublishInfo ( ) ;
204+ } , [ loadPublishInfo ] ) ;
205+
178206 const navigate = useNavigate ( ) ;
179207
180208 const loadViewMeta = useCallback (
@@ -385,6 +413,8 @@ export const PublishProvider = ({
385413 appendBreadcrumb,
386414 onRendered,
387415 rendered,
416+ commentEnabled : publishInfo ?. commentEnabled !== false ,
417+ duplicateEnabled : publishInfo ?. duplicateEnabled !== false ,
388418 } }
389419 >
390420 { children }
0 commit comments