web: fix potential crash when saving note

This commit is contained in:
Abdullah Atta
2024-04-16 23:36:32 +05:00
parent 424073298e
commit d5cf65e568
3 changed files with 10 additions and 10 deletions

View File

@@ -42,17 +42,17 @@ function DiffViewer(props: DiffViewerProps) {
const [content, setContent] = useState(session.content);
const [conflictedContent, setConflictedContent] = useState(
content.conflicted
content?.conflicted
);
useLayoutEffect(() => {
setConflictedContent((c) => {
if (c?.dateEdited === session.content.conflicted?.dateEdited) return c;
return session.content.conflicted;
if (c?.dateEdited === session.content?.conflicted?.dateEdited) return c;
return session.content?.conflicted;
});
}, [session]);
if (!conflictedContent) return null;
if (!conflictedContent || !content) return null;
return (
<Flex

View File

@@ -317,7 +317,7 @@ function InternalLinkItem({
const { items, tabIndex, noteId, isExpanded, toggleExpand } = context;
const item = useResolvedItem({ items, index });
if (!item || item.item.type !== "note") return null;
if (!item || item.item?.type !== "note") return null;
if (tabIndex === InternalLinksTabs.LINKED_NOTES)
return (
@@ -325,7 +325,7 @@ function InternalLinkItem({
item={item.item}
noteId={noteId}
isExpanded={isExpanded(item.item.id)}
toggleExpand={() => toggleExpand(item.item.id)}
toggleExpand={() => toggleExpand(item.item!.id)}
/>
);
return (
@@ -333,7 +333,7 @@ function InternalLinkItem({
item={item.item}
noteId={noteId}
isExpanded={isExpanded(item.item.id)}
toggleExpand={() => toggleExpand(item.item.id)}
toggleExpand={() => toggleExpand(item.item!.id)}
/>
);
}

View File

@@ -119,7 +119,7 @@ export type NewEditorSession = BaseEditorSession & {
export type ConflictedEditorSession = BaseEditorSession & {
type: "conflicted" | "diff";
note: Note;
content: ContentItem;
content?: ContentItem;
};
export type EditorSession =
@@ -771,12 +771,12 @@ class EditorStore extends BaseStore<EditorStore> {
const session = state.sessions.find(
(s): s is ConflictedEditorSession =>
(s.type === "diff" || s.type === "conflicted") &&
!!s.content.conflicted &&
!!s.content?.conflicted &&
s.content.conflicted.id === currentSession.note.contentId &&
s.content.conflicted.dateEdited ===
currentSession.note.dateEdited
);
if (!session || !session.content.conflicted) return;
if (!session || !session.content?.conflicted) return;
session.content.conflicted.data = partial.content!.data;
session.content.conflicted.dateEdited = note.dateEdited;
});