web: do not update dateEdited if ignoring edits

This commit is contained in:
Abdullah Atta
2024-01-29 17:59:10 +05:00
committed by Abdullah Atta
parent 081201aa42
commit 993b8460bf
3 changed files with 22 additions and 8 deletions

View File

@@ -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();
},

View File

@@ -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
);
},

View File

@@ -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) => {