@@ -4,62 +4,44 @@ import { Popover } from '@/components/_shared/popover';
44import PageIcon from '@/components/_shared/view-icon/PageIcon' ;
55import { useAppHandlers , useUserWorkspaceInfo } from '@/components/app/app.hooks' ;
66import { PublishNameSetting } from '@/components/app/publish-manage/PublishNameSetting' ;
7- import { useCurrentUser , useService } from '@/components/main/app.hooks' ;
7+ import { useCurrentUser } from '@/components/main/app.hooks' ;
88import { copyTextToClipboard } from '@/utils/copy' ;
99import { openUrl } from '@/utils/url' ;
1010import { Button , CircularProgress , IconButton , Tooltip } from '@mui/material' ;
1111import dayjs from 'dayjs' ;
12- import React , { useCallback , useEffect , useMemo } from 'react' ;
12+ import React , { useEffect , useMemo } from 'react' ;
1313import { useTranslation } from 'react-i18next' ;
1414import { ReactComponent as MoreIcon } from '@/assets/more.svg' ;
1515import { ReactComponent as GlobalIcon } from '@/assets/publish.svg' ;
1616import { ReactComponent as CopyIcon } from '@/assets/copy.svg' ;
1717import { ReactComponent as TrashIcon } from '@/assets/trash.svg' ;
1818import { ReactComponent as SettingIcon } from '@/assets/settings.svg' ;
1919
20- function PublishedPageItem ( { onClose, view, onUnPublish, onPublish } : {
20+ function PublishedPageItem ( { namespace , onClose, view, onUnPublish, onPublish } : {
2121 view : View ,
2222 onClose ?: ( ) => void ;
2323 onUnPublish : ( viewId : string ) => Promise < void > ;
2424 onPublish : ( view : View , publishName : string ) => Promise < void >
25+ namespace : string ;
2526} ) {
2627 const { t } = useTranslation ( ) ;
2728 const [ openSetting , setOpenSetting ] = React . useState < boolean > ( false ) ;
2829 const [ anchorEl , setAnchorEl ] = React . useState < null | HTMLElement > ( null ) ;
29- const [ publishInfo , setPublishInfo ] = React . useState < {
30- namespace : string ,
31- publishName : string ,
32- publisherEmail : string
33- publishedAt : string
34- } | undefined > ( undefined ) ;
30+ const [ publishName , setPublishName ] = React . useState < string > ( view . publish_name || '' ) ;
3531 const toView = useAppHandlers ( ) . toView ;
36- const service = useService ( ) ;
3732 const [ unPublishLoading , setUnPublishLoading ] = React . useState < boolean > ( false ) ;
3833 const userWorkspaceInfo = useUserWorkspaceInfo ( ) ;
3934 const currentUser = useCurrentUser ( ) ;
4035 const isOwner = userWorkspaceInfo ?. selectedWorkspace ?. owner ?. uid . toString ( ) === currentUser ?. uid . toString ( ) ;
41- const isPublisher = publishInfo ?. publisherEmail === currentUser ?. email ;
36+ const isPublisher = view ?. publisher_email === currentUser ?. email ;
4237
43- const getPublishInfo = useCallback ( async ( viewId : string ) => {
44- if ( ! service ) return ;
45-
46- try {
47- const res = await service ?. getPublishInfo ( viewId ) ;
48-
49- setPublishInfo ( res ) ;
50- return res ;
51- } catch ( e ) {
52- console . error ( e ) ;
53- }
54- } , [ service ] ) ;
38+ useEffect ( ( ) => {
39+ setPublishName ( view . publish_name || '' ) ;
40+ } , [ view . publish_name ] ) ;
5541
5642 const url = useMemo ( ( ) => {
57- return `${ window . origin } /${ publishInfo ?. namespace } /${ publishInfo ?. publishName } ` ;
58- } , [ publishInfo ] ) ;
59-
60- useEffect ( ( ) => {
61- void getPublishInfo ( view . view_id ) ;
62- } , [ getPublishInfo , view . view_id ] ) ;
43+ return `${ window . origin } /${ namespace } /${ publishName } ` ;
44+ } , [ namespace , publishName ] ) ;
6345
6446 const actions = useMemo ( ( ) => {
6547 return [
@@ -156,7 +138,7 @@ function PublishedPageItem ({ onClose, view, onUnPublish, onPublish }: {
156138 < Tooltip
157139 disableInteractive = { true }
158140 title = { < div className = { 'whitespace-pre-wrap break-words' } >
159- { `Open Page in New Tab \n${ publishInfo ?. publishName || '' } ` }
141+ { `Open Page in New Tab \n${ publishName || '' } ` }
160142 </ div > }
161143 >
162144 < Button
@@ -169,13 +151,13 @@ function PublishedPageItem ({ onClose, view, onUnPublish, onPublish }: {
169151 className = { 'w-full p-1 px-2 justify-start overflow-hidden' }
170152 >
171153 < span className = { 'truncate' } >
172- { publishInfo ?. publishName }
154+ { publishName }
173155 </ span >
174156 </ Button >
175157 </ Tooltip >
176158 </ div >
177159 < div className = { 'flex-1 overflow-hidden flex gap-2 justify-between' } >
178- { dayjs ( publishInfo ?. publishedAt ) . format ( 'MMM D, YYYY' ) }
160+ { view ?. publish_timestamp ? dayjs ( view . publish_timestamp ) . format ( 'MMM D, YYYY' ) : '' }
179161 < IconButton
180162 onClick = { ( e ) => {
181163 setAnchorEl ( e . currentTarget ) ;
@@ -204,27 +186,30 @@ function PublishedPageItem ({ onClose, view, onUnPublish, onPublish }: {
204186 onClick = { action . onClick }
205187 size = { 'small' }
206188 className = { 'justify-start' }
207- startIcon = { < action . IconComponent className = { 'w-4 h-4' } /> }
189+ startIcon = { < action . IconComponent
190+ size = { 14 }
191+ className = { 'w-4 h-4' }
192+ /> }
208193 color = { 'inherit' }
209194 > { action . label } </ Button >
210195 </ Tooltip > ;
211196 } ) }
212197 </ div >
213198 </ Popover >
214- { openSetting && publishInfo && < PublishNameSetting
199+ { openSetting && < PublishNameSetting
215200 onUnPublish = { ( ) => {
216201 return onUnPublish ( view . view_id ) ;
217202 } }
218203 onPublish = { async ( publishName : string ) => {
219204 await onPublish ( view , publishName ) ;
220- void getPublishInfo ( view . view_id ) ;
205+ setPublishName ( publishName ) ;
221206 } }
222207 onClose = { ( ) => {
223208 setOpenSetting ( false ) ;
224209 } }
225210 url = { url }
226211 open = { openSetting }
227- defaultName = { publishInfo . publishName }
212+ defaultName = { publishName }
228213 /> }
229214 </ div >
230215 ) ;
0 commit comments