Skip to content

Commit

Permalink
fix(core): fix meta.xxx is undefined (#6321)
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Mar 26, 2024
1 parent b6bba52 commit 1606334
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/common/infra/src/page/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PageRecord {
private readonly localState: WorkspaceLocalState
) {}

meta$ = LiveData.from<DocMeta>(
meta$ = LiveData.from<Partial<DocMeta>>(
new Observable<DocMeta>(subscriber => {
const emit = () => {
const meta = this.workspace.docCollection.meta.docMetas.find(
Expand Down Expand Up @@ -60,5 +60,5 @@ export class PageRecord {
return this.mode$.value;
}

title$ = this.meta$.map(meta => meta.title);
title$ = this.meta$.map(meta => meta.title ?? '');
}
6 changes: 3 additions & 3 deletions packages/frontend/core/src/components/pure/cmdk/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const CMDKContainer = ({
open: boolean;
className?: string;
query: string;
pageMeta?: DocMeta;
pageMeta?: Partial<DocMeta>;
groups: ReturnType<typeof useCMDKCommandGroups>;
onQueryChange: (query: string) => void;
}>) => {
Expand Down Expand Up @@ -234,7 +234,7 @@ const CMDKQuickSearchModalInner = ({
pageMeta,
open,
...props
}: CMDKModalProps & { pageMeta?: DocMeta }) => {
}: CMDKModalProps & { pageMeta?: Partial<DocMeta> }) => {
const [query, setQuery] = useAtom(cmdkQueryAtom);
useLayoutEffect(() => {
if (open) {
Expand All @@ -260,7 +260,7 @@ export const CMDKQuickSearchModal = ({
pageMeta,
open,
...props
}: CMDKModalProps & { pageMeta?: DocMeta }) => {
}: CMDKModalProps & { pageMeta?: Partial<DocMeta> }) => {
return (
<CMDKModal open={open} {...props}>
<Suspense fallback={<Command.Loading />}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const ConflictList = ({
setTrashModal({
open: true,
pageIds: [pageRecord.id],
pageTitles: [pageRecord.meta$.value.title],
pageTitles: [pageRecord.title$.value],
});
},
[setTrashModal]
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/core/src/modules/tag/entities/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Tag {
return;
}
pageRecord?.setMeta({
tags: [...pageRecord.meta$.value.tags, this.id],
tags: [...(pageRecord.meta$.value.tags ?? []), this.id],
});
}

Expand All @@ -60,14 +60,14 @@ export class Tag {
return;
}
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 => {
const pages = get(this.pageRecordList.records$);
return pages
.filter(page => get(page.meta$).tags.includes(this.id))
.filter(page => get(page.meta$).tags?.includes(this.id))
.map(page => page.id);
});
}
2 changes: 1 addition & 1 deletion packages/frontend/core/src/modules/tag/service/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TagService {
if (!pageRecord) return [];
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));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const DetailPageImpl = memo(function DetailPageImpl() {

const updatedDate = linkedPage.meta$.value.updatedDate;
const createDate = linkedPage.meta$.value.createDate;
return updatedDate ? new Date(updatedDate) : new Date(createDate);
return new Date(updatedDate || createDate || Date.now());
};

page.setMode(mode);
Expand Down

0 comments on commit 1606334

Please sign in to comment.