mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
web: fix potential crash when saving note
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user