fix(core): fix meta.xxx is undefined (#6321)
This commit is contained in:
@@ -14,7 +14,7 @@ export class PageRecord {
|
|||||||
private readonly localState: WorkspaceLocalState
|
private readonly localState: WorkspaceLocalState
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
meta$ = LiveData.from<DocMeta>(
|
meta$ = LiveData.from<Partial<DocMeta>>(
|
||||||
new Observable<DocMeta>(subscriber => {
|
new Observable<DocMeta>(subscriber => {
|
||||||
const emit = () => {
|
const emit = () => {
|
||||||
const meta = this.workspace.docCollection.meta.docMetas.find(
|
const meta = this.workspace.docCollection.meta.docMetas.find(
|
||||||
@@ -60,5 +60,5 @@ export class PageRecord {
|
|||||||
return this.mode$.value;
|
return this.mode$.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
title$ = this.meta$.map(meta => meta.title);
|
title$ = this.meta$.map(meta => meta.title ?? '');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ export const CMDKContainer = ({
|
|||||||
open: boolean;
|
open: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
query: string;
|
query: string;
|
||||||
pageMeta?: DocMeta;
|
pageMeta?: Partial<DocMeta>;
|
||||||
groups: ReturnType<typeof useCMDKCommandGroups>;
|
groups: ReturnType<typeof useCMDKCommandGroups>;
|
||||||
onQueryChange: (query: string) => void;
|
onQueryChange: (query: string) => void;
|
||||||
}>) => {
|
}>) => {
|
||||||
@@ -234,7 +234,7 @@ const CMDKQuickSearchModalInner = ({
|
|||||||
pageMeta,
|
pageMeta,
|
||||||
open,
|
open,
|
||||||
...props
|
...props
|
||||||
}: CMDKModalProps & { pageMeta?: DocMeta }) => {
|
}: CMDKModalProps & { pageMeta?: Partial<DocMeta> }) => {
|
||||||
const [query, setQuery] = useAtom(cmdkQueryAtom);
|
const [query, setQuery] = useAtom(cmdkQueryAtom);
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (open) {
|
if (open) {
|
||||||
@@ -260,7 +260,7 @@ export const CMDKQuickSearchModal = ({
|
|||||||
pageMeta,
|
pageMeta,
|
||||||
open,
|
open,
|
||||||
...props
|
...props
|
||||||
}: CMDKModalProps & { pageMeta?: DocMeta }) => {
|
}: CMDKModalProps & { pageMeta?: Partial<DocMeta> }) => {
|
||||||
return (
|
return (
|
||||||
<CMDKModal open={open} {...props}>
|
<CMDKModal open={open} {...props}>
|
||||||
<Suspense fallback={<Command.Loading />}>
|
<Suspense fallback={<Command.Loading />}>
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ const ConflictList = ({
|
|||||||
setTrashModal({
|
setTrashModal({
|
||||||
open: true,
|
open: true,
|
||||||
pageIds: [pageRecord.id],
|
pageIds: [pageRecord.id],
|
||||||
pageTitles: [pageRecord.meta$.value.title],
|
pageTitles: [pageRecord.title$.value],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[setTrashModal]
|
[setTrashModal]
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export class Tag {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pageRecord?.setMeta({
|
pageRecord?.setMeta({
|
||||||
tags: [...pageRecord.meta$.value.tags, this.id],
|
tags: [...(pageRecord.meta$.value.tags ?? []), this.id],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,14 +60,14 @@ export class Tag {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pageRecord?.setMeta({
|
pageRecord?.setMeta({
|
||||||
tags: pageRecord.meta$.value.tags.filter(tagId => tagId !== this.id),
|
tags: pageRecord.meta$.value.tags?.filter(tagId => tagId !== this.id),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly pageIds$ = LiveData.computed(get => {
|
readonly pageIds$ = LiveData.computed(get => {
|
||||||
const pages = get(this.pageRecordList.records$);
|
const pages = get(this.pageRecordList.records$);
|
||||||
return pages
|
return pages
|
||||||
.filter(page => get(page.meta$).tags.includes(this.id))
|
.filter(page => get(page.meta$).tags?.includes(this.id))
|
||||||
.map(page => page.id);
|
.map(page => page.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export class TagService {
|
|||||||
if (!pageRecord) return [];
|
if (!pageRecord) return [];
|
||||||
const tagIds = get(pageRecord.meta$).tags;
|
const tagIds = get(pageRecord.meta$).tags;
|
||||||
|
|
||||||
return get(this.tags$).filter(tag => tagIds.includes(tag.id));
|
return get(this.tags$).filter(tag => (tagIds ?? []).includes(tag.id));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
|
|
||||||
const updatedDate = linkedPage.meta$.value.updatedDate;
|
const updatedDate = linkedPage.meta$.value.updatedDate;
|
||||||
const createDate = linkedPage.meta$.value.createDate;
|
const createDate = linkedPage.meta$.value.createDate;
|
||||||
return updatedDate ? new Date(updatedDate) : new Date(createDate);
|
return new Date(updatedDate || createDate || Date.now());
|
||||||
};
|
};
|
||||||
|
|
||||||
page.setMode(mode);
|
page.setMode(mode);
|
||||||
|
|||||||
Reference in New Issue
Block a user