mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-18 08:41:56 +03:00
fixbug: [issue76]when click activities button, throw error;
This commit is contained in:
parent
c63d5da4df
commit
9ec41c013b
@ -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 (
|
||||
<LigoApp>
|
||||
<LigoLeftContainer style={{ width: fixedDisplay ? '300px' : 0 }}>
|
||||
|
@ -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 (
|
||||
<StyledWrapper>
|
||||
<List style={{ padding: '0px' }}>
|
||||
{recentPages.map(({ id, title, lastOpenTime }) => {
|
||||
{recentPages.map(item => {
|
||||
const { id, title, updated } = item;
|
||||
return (
|
||||
<ListItem className="item" key={id}>
|
||||
<StyledItemContent
|
||||
@ -114,7 +119,7 @@ export const Activities = () => {
|
||||
/>
|
||||
<ListItemText
|
||||
className="itemRight"
|
||||
primary={formatDistanceToNow(lastOpenTime, {
|
||||
primary={formatDistanceToNow(updated, {
|
||||
includeSeconds: true,
|
||||
})}
|
||||
/>
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user