mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
web: do not update dateEdited if ignoring edits
This commit is contained in:
committed by
Abdullah Atta
parent
081201aa42
commit
993b8460bf
@@ -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();
|
||||
},
|
||||
|
||||
@@ -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
|
||||
);
|
||||
},
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user