diff --git a/src/application/types.ts b/src/application/types.ts index 65e97a22..7d90f393 100644 --- a/src/application/types.ts +++ b/src/application/types.ts @@ -846,6 +846,9 @@ export interface View { last_viewed_at?: string; created_at?: string; database_relations?: DatabaseRelations; + publisher_email?: string; + publish_name?: string; + publish_timestamp?: string; } export interface Invitation { diff --git a/src/components/app/publish-manage/PublishManage.tsx b/src/components/app/publish-manage/PublishManage.tsx index ab34d691..120b7e16 100644 --- a/src/components/app/publish-manage/PublishManage.tsx +++ b/src/components/app/publish-manage/PublishManage.tsx @@ -4,10 +4,11 @@ import { flattenViews } from '@/components/_shared/outline/utils'; import { useAppHandlers, useUserWorkspaceInfo } from '@/components/app/app.hooks'; import HomePageSetting from '@/components/app/publish-manage/HomePageSetting'; import PublishedPages from '@/components/app/publish-manage/PublishedPages'; +import PublishPagesSkeleton from '@/components/app/publish-manage/PublishPagesSkeleton'; import UpdateNamespace from '@/components/app/publish-manage/UpdateNamespace'; import { useCurrentUser, useService } from '@/components/main/app.hooks'; import { openUrl } from '@/utils/url'; -import { Button, Divider, IconButton, Tooltip } from '@mui/material'; +import { Button, CircularProgress, Divider, IconButton, Tooltip } from '@mui/material'; import React, { useCallback, useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { ReactComponent as EditIcon } from '@/assets/edit.svg'; @@ -64,8 +65,14 @@ export function PublishManage ({ setLoading(true); try { const outline = await service.getPublishOutline(namespace); - - setPublishViews(flattenViews(outline).filter(item => item.is_published)); + + setPublishViews(flattenViews(outline).filter(item => item.is_published).sort((a, b) => { + if (!a.publish_timestamp || !b.publish_timestamp) { + return 0; + } + + return new Date(b.publish_timestamp).getTime() - new Date(a.publish_timestamp).getTime(); + })); // eslint-disable-next-line } catch (e: any) { console.error(e); @@ -261,7 +268,10 @@ export function PublishManage ({ -
{t('settings.sites.publishedPage.title')}
+
+ {t('settings.sites.publishedPage.title')} + {loading && } +
{t('settings.sites.publishedPage.description')}
@@ -273,13 +283,14 @@ export function PublishManage ({
- + {loading && !publishViews.length ? : + } {updateOpen && + { + Array.from({ length: 5 }).map((_, index) => ( +
+ { + Array.from({ length: 3 }).map((_, i) => ( +
+ +
+ )) + } +
)) + } + + ); +} + +export default PublishPagesSkeleton; \ No newline at end of file diff --git a/src/components/app/publish-manage/PublishedPageItem.tsx b/src/components/app/publish-manage/PublishedPageItem.tsx index b35368ce..5ab6b904 100644 --- a/src/components/app/publish-manage/PublishedPageItem.tsx +++ b/src/components/app/publish-manage/PublishedPageItem.tsx @@ -4,12 +4,12 @@ import { Popover } from '@/components/_shared/popover'; import PageIcon from '@/components/_shared/view-icon/PageIcon'; import { useAppHandlers, useUserWorkspaceInfo } from '@/components/app/app.hooks'; import { PublishNameSetting } from '@/components/app/publish-manage/PublishNameSetting'; -import { useCurrentUser, useService } from '@/components/main/app.hooks'; +import { useCurrentUser } from '@/components/main/app.hooks'; import { copyTextToClipboard } from '@/utils/copy'; import { openUrl } from '@/utils/url'; import { Button, CircularProgress, IconButton, Tooltip } from '@mui/material'; import dayjs from 'dayjs'; -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { ReactComponent as MoreIcon } from '@/assets/more.svg'; import { ReactComponent as GlobalIcon } from '@/assets/publish.svg'; @@ -17,49 +17,31 @@ import { ReactComponent as CopyIcon } from '@/assets/copy.svg'; import { ReactComponent as TrashIcon } from '@/assets/trash.svg'; import { ReactComponent as SettingIcon } from '@/assets/settings.svg'; -function PublishedPageItem ({ onClose, view, onUnPublish, onPublish }: { +function PublishedPageItem ({ namespace, onClose, view, onUnPublish, onPublish }: { view: View, onClose?: () => void; onUnPublish: (viewId: string) => Promise; onPublish: (view: View, publishName: string) => Promise + namespace: string; }) { const { t } = useTranslation(); const [openSetting, setOpenSetting] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); - const [publishInfo, setPublishInfo] = React.useState<{ - namespace: string, - publishName: string, - publisherEmail: string - publishedAt: string - } | undefined>(undefined); + const [publishName, setPublishName] = React.useState(view.publish_name || ''); const toView = useAppHandlers().toView; - const service = useService(); const [unPublishLoading, setUnPublishLoading] = React.useState(false); const userWorkspaceInfo = useUserWorkspaceInfo(); const currentUser = useCurrentUser(); const isOwner = userWorkspaceInfo?.selectedWorkspace?.owner?.uid.toString() === currentUser?.uid.toString(); - const isPublisher = publishInfo?.publisherEmail === currentUser?.email; - - const getPublishInfo = useCallback(async (viewId: string) => { - if (!service) return; - - try { - const res = await service?.getPublishInfo(viewId); - - setPublishInfo(res); - return res; - } catch (e) { - console.error(e); - } - }, [service]); - - const url = useMemo(() => { - return `${window.origin}/${publishInfo?.namespace}/${publishInfo?.publishName}`; - }, [publishInfo]); + const isPublisher = view?.publisher_email === currentUser?.email; useEffect(() => { - void getPublishInfo(view.view_id); - }, [getPublishInfo, view.view_id]); + setPublishName(view.publish_name || ''); + }, [view.publish_name]); + + const url = useMemo(() => { + return `${window.origin}/${namespace}/${publishName}`; + }, [namespace, publishName]); const actions = useMemo(() => { return [ @@ -156,7 +138,7 @@ function PublishedPageItem ({ onClose, view, onUnPublish, onPublish }: { - {`Open Page in New Tab \n${publishInfo?.publishName || ''}`} + {`Open Page in New Tab \n${publishName || ''}`} } >
- {dayjs(publishInfo?.publishedAt).format('MMM D, YYYY')} + {view?.publish_timestamp ? dayjs(view.publish_timestamp).format('MMM D, YYYY') : ''} { setAnchorEl(e.currentTarget); @@ -204,27 +186,30 @@ function PublishedPageItem ({ onClose, view, onUnPublish, onPublish }: { onClick={action.onClick} size={'small'} className={'justify-start'} - startIcon={} + startIcon={} color={'inherit'} >{action.label} ; })}
- {openSetting && publishInfo && { return onUnPublish(view.view_id); }} onPublish={async (publishName: string) => { await onPublish(view, publishName); - void getPublishInfo(view.view_id); + setPublishName(publishName); }} onClose={() => { setOpenSetting(false); }} url={url} open={openSetting} - defaultName={publishInfo.publishName} + defaultName={publishName} />} ); diff --git a/src/components/app/publish-manage/PublishedPages.tsx b/src/components/app/publish-manage/PublishedPages.tsx index bf05b977..e73fc388 100644 --- a/src/components/app/publish-manage/PublishedPages.tsx +++ b/src/components/app/publish-manage/PublishedPages.tsx @@ -1,7 +1,7 @@ import { View } from '@/application/types'; import PublishedPageItem from '@/components/app/publish-manage/PublishedPageItem'; -import { CircularProgress, Divider } from '@mui/material'; +import { Divider } from '@mui/material'; import React from 'react'; @@ -9,33 +9,32 @@ function PublishedPages ({ publishViews, onUnPublish, onPublish, - loading, onClose, + namespace, }: { publishViews: View[]; - loading: boolean; onUnPublish: (viewId: string) => Promise; onPublish: (view: View, publishName: string) => Promise; - onClose?: () => void + onClose?: () => void; + namespace: string; }) { return (
- {loading ?
-
- : publishViews.map((view, index) => { - return - - {index !== publishViews.length - 1 && } + {publishViews.map((view, index) => { + return + + {index !== publishViews.length - 1 && } - ; - })} + ; + })}
);