mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
fix: doc update time outdated (#7344)
Fix issue [BS-603](https://linear.app/affine-design/issue/BS-603). - Move observe `blockUpdated` logic in `blocksuite-editor` component, so it can be excuted on both page-detail and center-peek mode. - Remove useless `getDocUpdatedAt` service, because blocksuite can get `docMeta` directly. https://github.com/toeverything/blocksuite/pull/7434 https://github.com/toeverything/AFFiNE/assets/12724894/e01e3f97-f1d0-4d1d-a8ed-e70e27e39bdb
This commit is contained in:
@@ -88,6 +88,17 @@ const BlockSuiteEditorImpl = forwardRef<AffineEditorContainer, EditorProps>(
|
|||||||
[onLoadEditor, ref]
|
[onLoadEditor, ref]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const disposable = page.slots.blockUpdated.once(() => {
|
||||||
|
page.collection.setDocMeta(page.id, {
|
||||||
|
updatedDate: Date.now(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
disposable.dispose();
|
||||||
|
};
|
||||||
|
}, [page]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
editorDisposeRef.current();
|
editorDisposeRef.current();
|
||||||
|
|||||||
@@ -75,13 +75,6 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
// debug current detail editor
|
// debug current detail editor
|
||||||
globalThis.currentEditor = editor;
|
globalThis.currentEditor = editor;
|
||||||
const disposableGroup = new DisposableGroup();
|
const disposableGroup = new DisposableGroup();
|
||||||
disposableGroup.add(
|
|
||||||
page.slots.blockUpdated.once(() => {
|
|
||||||
page.collection.setDocMeta(page.id, {
|
|
||||||
updatedDate: Date.now(),
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
localStorage.setItem('last_page_id', page.id);
|
localStorage.setItem('last_page_id', page.id);
|
||||||
|
|
||||||
if (onLoad) {
|
if (onLoad) {
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
const activeTabName = useLiveData(rightSidebar.activeTabName$);
|
const activeTabName = useLiveData(rightSidebar.activeTabName$);
|
||||||
|
|
||||||
const doc = useService(DocService).doc;
|
const doc = useService(DocService).doc;
|
||||||
const docRecordList = useService(DocsService).list;
|
|
||||||
const { openPage, jumpToPageBlock, jumpToTag } = useNavigateHelper();
|
const { openPage, jumpToPageBlock, jumpToTag } = useNavigateHelper();
|
||||||
const [editor, setEditor] = useState<AffineEditorContainer | null>(null);
|
const [editor, setEditor] = useState<AffineEditorContainer | null>(null);
|
||||||
const workspace = useService(WorkspaceService).workspace;
|
const workspace = useService(WorkspaceService).workspace;
|
||||||
@@ -200,15 +199,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
editorHost.std.spec.getService<PageRootService>('affine:page');
|
editorHost.std.spec.getService<PageRootService>('affine:page');
|
||||||
const disposable = new DisposableGroup();
|
const disposable = new DisposableGroup();
|
||||||
|
|
||||||
pageService.getDocUpdatedAt = (pageId: string) => {
|
|
||||||
const linkedPage = docRecordList.doc$(pageId).value;
|
|
||||||
if (!linkedPage) return new Date();
|
|
||||||
|
|
||||||
const updatedDate = linkedPage.meta$.value.updatedDate;
|
|
||||||
const createDate = linkedPage.meta$.value.createDate;
|
|
||||||
return new Date(updatedDate || createDate || Date.now());
|
|
||||||
};
|
|
||||||
|
|
||||||
doc.setMode(mode);
|
doc.setMode(mode);
|
||||||
disposable.add(
|
disposable.add(
|
||||||
pageService.slots.docLinkClicked.on(({ docId, blockId }) => {
|
pageService.slots.docLinkClicked.on(({ docId, blockId }) => {
|
||||||
@@ -232,7 +222,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
[
|
[
|
||||||
doc,
|
doc,
|
||||||
mode,
|
mode,
|
||||||
docRecordList,
|
|
||||||
jumpToPageBlock,
|
jumpToPageBlock,
|
||||||
docCollection.id,
|
docCollection.id,
|
||||||
openPage,
|
openPage,
|
||||||
|
|||||||
Reference in New Issue
Block a user