diff --git a/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx b/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx index bdba3722fe..eb6c334803 100644 --- a/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx +++ b/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx @@ -33,30 +33,8 @@ export function Page(props: PageProps) { const { page_id } = useParams(); const { showSpaceSidebar, fixedDisplay, setSpaceSidebarVisible } = useShowSpaceSidebar(); - const { user } = useUserAndSpaces(); const dailyNotesFlag = useFlag('BooleanDailyNotes', false); - useEffect(() => { - if (!user?.id || !page_id) return; - const updateRecentPages = async () => { - // TODO: deal with it temporarily - await services.api.editorBlock.getWorkspaceDbBlock( - props.workspace, - { - userId: user.id, - } - ); - - await services.api.userConfig.addRecentPage( - props.workspace, - user.id, - page_id - ); - await services.api.editorBlock.clearUndoRedo(props.workspace); - }; - updateRecentPages(); - }, [user, props.workspace, page_id]); - return ( diff --git a/libs/components/layout/src/workspace-sidebar/activities/activities.tsx b/libs/components/layout/src/workspace-sidebar/activities/activities.tsx index 4e5a9de413..195bc1fa09 100644 --- a/libs/components/layout/src/workspace-sidebar/activities/activities.tsx +++ b/libs/components/layout/src/workspace-sidebar/activities/activities.tsx @@ -64,30 +64,34 @@ export const Activities = () => { const [recentPages, setRecentPages] = useState([]); const userId = user?.id; - /* temporarily remove:show recently viewed documents */ - const fetchRecentPages = useCallback(async () => { + /* show recently edit documents */ + const getRecentEditPages = useCallback(async () => { if (!userId || !currentSpaceId) { return; } - const recent_pages = await services.api.userConfig.getRecentPages( - currentSpaceId, - userId - ); - setRecentPages(recent_pages); - }, [userId, currentSpaceId]); + + console.log('不执行吗'); + + const RecentEditPages = + (await services.api.userConfig.getRecentEditedPages( + currentSpaceId + )) || []; + + setRecentPages(RecentEditPages); + }, [currentSpaceId, userId]); useEffect(() => { (async () => { - await fetchRecentPages(); + await getRecentEditPages(); })(); - }, [fetchRecentPages]); + }, [getRecentEditPages]); useEffect(() => { let unobserve: () => void; const observe = async () => { unobserve = await services.api.userConfig.observe( { workspace: currentSpaceId }, - fetchRecentPages + getRecentEditPages ); }; observe(); @@ -95,12 +99,13 @@ export const Activities = () => { return () => { unobserve?.(); }; - }, [currentSpaceId, fetchRecentPages]); + }, [currentSpaceId, getRecentEditPages]); return ( - {recentPages.map(({ id, title, lastOpenTime }) => { + {recentPages.map(item => { + const { id, title, updated } = item; return ( { /> diff --git a/libs/datasource/db-service/src/services/workspace/user-config.ts b/libs/datasource/db-service/src/services/workspace/user-config.ts index 001eaca18b..6fb96bb04c 100644 --- a/libs/datasource/db-service/src/services/workspace/user-config.ts +++ b/libs/datasource/db-service/src/services/workspace/user-config.ts @@ -3,6 +3,7 @@ import { ServiceBaseClass } from '../base'; import { ObserveCallback, ReturnUnobserve } from '../database'; import { PageTree } from './page-tree'; import { PageConfigItem } from './types'; +import { QueryIndexMetadata } from '@toeverything/datasource/jwt'; /** Operate the user configuration at the workspace level */ export class UserConfig extends ServiceBaseClass { @@ -122,4 +123,20 @@ export class UserConfig extends ServiceBaseClass { const workspaceDbBlock = await this.getWorkspaceDbBlock(workspace); workspaceDbBlock.setDecoration(WORKSPACE_CONFIG, workspaceName); } + + async getRecentEditedPages(workspace: string) { + const db = await this.database.getDatabase(workspace); + const recentEditedPages = + (await db.queryBlocks({ + $sort: 'lastUpdated', + $desc: false /* sort rule: true(default)(ASC), or false(DESC) */, + $limit: 4, + flavor: 'page', + } as QueryIndexMetadata)) || []; + + return recentEditedPages.map(item => { + item['title'] = item.content || 'Untitled'; + return item; + }); + } }