Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: do not update dateEdited if ignoring edits

Abdullah Atta993b8460bfb4
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 57add579b..51f6785b8 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -72,11 +72,12 @@ type DocumentPreview = {
function onEditorChange(
noteId: string | undefined,
sessionId: number,
- content: string
+ content: string,
+ ignoreEdit: boolean
) {
if (!content) return;
- editorstore.get().saveSessionContent(noteId, sessionId, {
+ editorstore.get().saveSessionContent(noteId, sessionId, ignoreEdit, {
type: "tiptap",
data: content
});
@@ -535,7 +536,7 @@ function PreviewModeNotice(props: PreviewModeNoticeProps) {
async (cancelled: boolean) => {
const { id, sessionId } = editorstore.get().session;
if (!cancelled) {
- await editorstore.saveSessionContent(id, sessionId, content);
+ await editorstore.saveSessionContent(id, sessionId, false, content);
}
onDiscard();
},
diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsx
index 1021b1836..3a185db7a 100644
--- a/apps/web/src/components/editor/tiptap.tsx
+++ b/apps/web/src/components/editor/tiptap.tsx
@@ -61,7 +61,8 @@ import { useStore as useThemeStore } from "../../stores/theme-store";
type OnChangeHandler = (
id: string | undefined,
sessionId: number,
- content: string
+ content: string,
+ ignoreEdit: boolean
) => void;
type TipTapProps = {
editorContainer: HTMLElement;
@@ -92,6 +93,7 @@ function save(
editor: Editor,
content: Fragment,
preventSave: boolean,
+ ignoreEdit: boolean,
onChange?: OnChangeHandler
) {
configureEditor({
@@ -105,7 +107,7 @@ function save(
if (preventSave) return;
const html = getHTMLFromFragment(content, editor.schema);
- onChange?.(noteId, sessionId, html);
+ onChange?.(noteId, sessionId, html, ignoreEdit);
}
const deferredSave = debounceWithId(save, SAVE_INTERVAL);
@@ -211,7 +213,8 @@ function TipTap(props: TipTapProps) {
onUpdate: ({ editor, transaction }) => {
onContentChange?.();
- const preventSave = transaction?.getMeta("preventSave") as boolean;
+ const preventSave = transaction.getMeta("preventSave") as boolean;
+ const ignoreEdit = transaction.getMeta("ignoreEdit") as boolean;
const { id, sessionId } = editorstore.get().session;
const content = editor.state.doc.content;
deferredSave(
@@ -221,6 +224,7 @@ function TipTap(props: TipTapProps) {
editor as Editor,
content,
preventSave || !editor.isEditable,
+ ignoreEdit,
onChange
);
},
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 9eb9a4cd2..6fdbe1d83 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -306,8 +306,17 @@ class EditorStore extends BaseStore {
return this.saveSession(noteId, { [name]: value });
};
- saveSessionContent = (noteId, sessionId, content) => {
- return this.saveSession(noteId, { sessionId, content });
+ /**
+ *
+ * @param {*} noteId
+ * @param {*} sessionId
+ * @param {boolean} ignoreEdit if this is set to true, we save the content but do not update the dateEdited. Useful for metadata only changes in content.
+ * @param {*} content
+ * @returns
+ */
+ saveSessionContent = (noteId, sessionId, ignoreEdit, content) => {
+ const dateEdited = ignoreEdit ? this.get().session.dateEdited : undefined;
+ return this.saveSession(noteId, { sessionId, content, dateEdited });
};
setTag = (tag) => {