mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
mobile: support ignoring edits
This commit is contained in:
committed by
Abdullah Atta
parent
d3371326f2
commit
372da979e1
@@ -623,6 +623,7 @@ export const useAppEvents = () => {
|
||||
}, [loading, onUserUpdated]);
|
||||
|
||||
const initializeDatabase = useCallback(async () => {
|
||||
try {
|
||||
if (!db.isInitialized) {
|
||||
RNBootSplash.hide({ fade: true });
|
||||
DatabaseLogger.info("Initializing database");
|
||||
@@ -632,6 +633,10 @@ export const useAppEvents = () => {
|
||||
initialize();
|
||||
setLoading(false);
|
||||
Walkthrough.init();
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e);
|
||||
ToastEvent.error(e, "Error initializing database", "global");
|
||||
}
|
||||
}, [IsDatabaseMigrationRequired]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -97,6 +97,7 @@ export type SavePayload = {
|
||||
type?: Content["type"];
|
||||
sessionId?: string | null;
|
||||
sessionHistoryId?: number;
|
||||
ignoreEdit: boolean;
|
||||
};
|
||||
|
||||
export type AppState = {
|
||||
|
||||
@@ -128,6 +128,8 @@ const showActionsheet = async (editor: useEditorType) => {
|
||||
}
|
||||
};
|
||||
|
||||
type ContentMessage = { html: string; ignoreEdit: boolean };
|
||||
|
||||
export const useEditorEvents = (
|
||||
editor: useEditorType,
|
||||
{ readonly: editorPropReadonly, noHeader, noToolbar }: Partial<EditorProps>
|
||||
@@ -331,14 +333,16 @@ export const useEditorEvents = (
|
||||
if (editorMessage.type === EventTypes.content) {
|
||||
editor.saveContent({
|
||||
type: editorMessage.type,
|
||||
content: editorMessage.value as string,
|
||||
content: (editorMessage.value as ContentMessage).html,
|
||||
ignoreEdit: (editorMessage.value as ContentMessage).ignoreEdit,
|
||||
forSessionId: editorMessage.sessionId
|
||||
});
|
||||
} else if (editorMessage.type === EventTypes.title) {
|
||||
editor.saveContent({
|
||||
type: editorMessage.type,
|
||||
title: editorMessage.value as string,
|
||||
forSessionId: editorMessage.sessionId
|
||||
forSessionId: editorMessage.sessionId,
|
||||
ignoreEdit: false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,8 @@ export const useEditor = (
|
||||
data,
|
||||
type,
|
||||
sessionId: currentSessionId,
|
||||
sessionHistoryId: currentSessionHistoryId
|
||||
sessionHistoryId: currentSessionHistoryId,
|
||||
ignoreEdit
|
||||
}: SavePayload) => {
|
||||
if (
|
||||
readonly ||
|
||||
@@ -194,6 +195,12 @@ export const useEditor = (
|
||||
};
|
||||
|
||||
noteData.title = title;
|
||||
|
||||
if (ignoreEdit) {
|
||||
console.log("Ignoring edits...");
|
||||
noteData.dateEdited = note?.dateEdited;
|
||||
}
|
||||
|
||||
if (data) {
|
||||
noteData.content = {
|
||||
data: data,
|
||||
@@ -454,12 +461,14 @@ export const useEditor = (
|
||||
title,
|
||||
content,
|
||||
type,
|
||||
forSessionId
|
||||
forSessionId,
|
||||
ignoreEdit
|
||||
}: {
|
||||
title?: string;
|
||||
content?: string;
|
||||
type: string;
|
||||
forSessionId: string;
|
||||
ignoreEdit: boolean;
|
||||
}) => {
|
||||
if (lock.current || lockedSessionId.current === forSessionId) return;
|
||||
lastContentChangeTime.current = Date.now();
|
||||
@@ -490,7 +499,8 @@ export const useEditor = (
|
||||
type: "tiptap",
|
||||
sessionId: forSessionId,
|
||||
id: noteId,
|
||||
sessionHistoryId: sessionHistoryId.current
|
||||
sessionHistoryId: sessionHistoryId.current,
|
||||
ignoreEdit
|
||||
};
|
||||
withTimer(
|
||||
noteId || "newnote",
|
||||
@@ -508,7 +518,7 @@ export const useEditor = (
|
||||
}
|
||||
saveNote(params);
|
||||
},
|
||||
150
|
||||
ignoreEdit ? 0 : 150
|
||||
);
|
||||
},
|
||||
[withTimer, onChange, saveNote]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:windowDisablePreview">true</item>
|
||||
<item name="android:editTextBackground">@drawable/edit_text</item>
|
||||
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
|
||||
</style>
|
||||
@@ -20,6 +20,7 @@
|
||||
<style name="BootTheme" parent="Theme.SplashScreen">
|
||||
<item name="windowSplashScreenBackground">@color/bootsplash_background</item>
|
||||
<item name="windowSplashScreenAnimatedIcon">@mipmap/bootsplash_logo_dark</item>
|
||||
<item name="android:navigationBarColor">@color/bootsplash_background</item>
|
||||
<item name="postSplashScreenTheme">@style/AppTheme</item>
|
||||
</style>
|
||||
|
||||
@@ -31,6 +32,7 @@
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
<item name="android:editTextBackground">@drawable/edit_text</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:windowDisablePreview">true</item>
|
||||
<item name="android:editTextBackground">@drawable/edit_text</item>
|
||||
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
<item name="android:datePickerDialogTheme">@style/DialogDatePicker.Theme</item>
|
||||
</style>
|
||||
@@ -20,6 +20,7 @@
|
||||
<style name="BootTheme" parent="Theme.SplashScreen">
|
||||
<item name="windowSplashScreenBackground">@color/bootsplash_background</item>
|
||||
<item name="windowSplashScreenAnimatedIcon">@mipmap/bootsplash_logo</item>
|
||||
<item name="android:navigationBarColor">@color/bootsplash_background</item>
|
||||
<item name="postSplashScreenTheme">@style/AppTheme</item>
|
||||
</style>
|
||||
|
||||
@@ -31,6 +32,7 @@
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
<item name="android:editTextBackground">@drawable/edit_text</item>
|
||||
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
<style name="DialogDatePicker.Theme" parent="Theme.AppCompat.Light.Dialog">
|
||||
|
||||
@@ -44,7 +44,7 @@ import Tags from "./tags";
|
||||
import Title from "./title";
|
||||
import { toBlobURL } from "@notesnook/editor/dist/utils/downloader";
|
||||
|
||||
globalThis.toBlobURL = toBlobURL;
|
||||
globalThis.toBlobURL = toBlobURL as typeof globalThis.toBlobURL;
|
||||
|
||||
const Tiptap = ({ settings }: { settings: Settings }) => {
|
||||
const [tick, setTick] = useState(0);
|
||||
@@ -61,8 +61,11 @@ const Tiptap = ({ settings }: { settings: Settings }) => {
|
||||
});
|
||||
const _editor = useTiptap(
|
||||
{
|
||||
onUpdate: ({ editor }) => {
|
||||
global.editorController.contentChange(editor as Editor);
|
||||
onUpdate: ({ editor, transaction }) => {
|
||||
global.editorController.contentChange(
|
||||
editor as Editor,
|
||||
transaction.getMeta("ignoreEdit")
|
||||
);
|
||||
},
|
||||
onOpenAttachmentPicker: (editor, type) => {
|
||||
global.editorController.openFilePicker(type);
|
||||
|
||||
@@ -32,7 +32,6 @@ import {
|
||||
} from "react";
|
||||
import { EventTypes, isReactNative, post, randId, saveTheme } from "../utils";
|
||||
import { injectCss, transform } from "../utils/css";
|
||||
|
||||
type Attachment = {
|
||||
hash: string;
|
||||
filename: string;
|
||||
@@ -88,7 +87,7 @@ function scrollIntoView(editor: Editor) {
|
||||
export type EditorController = {
|
||||
selectionChange: (editor: Editor) => void;
|
||||
titleChange: (title: string) => void;
|
||||
contentChange: (editor: Editor) => void;
|
||||
contentChange: (editor: Editor, ignoreEdit?: boolean) => void;
|
||||
scroll: (event: React.UIEvent<HTMLDivElement, UIEvent>) => void;
|
||||
title: string;
|
||||
setTitle: React.Dispatch<React.SetStateAction<string>>;
|
||||
@@ -139,17 +138,27 @@ export function useEditorController(update: () => void): EditorController {
|
||||
}, [colors]);
|
||||
|
||||
const contentChange = useCallback(
|
||||
(editor: Editor) => {
|
||||
(editor: Editor, ignoreEdit) => {
|
||||
const currentSessionId = globalThis.sessionId;
|
||||
post(EventTypes.contentchange);
|
||||
if (!editor) return;
|
||||
if (typeof timers.current.change === "number") {
|
||||
clearTimeout(timers.current?.change);
|
||||
}
|
||||
timers.current.change = setTimeout(() => {
|
||||
timers.current.change = setTimeout(
|
||||
() => {
|
||||
htmlContentRef.current = editor.getHTML();
|
||||
post(EventTypes.content, htmlContentRef.current, currentSessionId);
|
||||
}, 300);
|
||||
post(
|
||||
EventTypes.content,
|
||||
{
|
||||
html: htmlContentRef.current,
|
||||
ignoreEdit: ignoreEdit
|
||||
},
|
||||
currentSessionId
|
||||
);
|
||||
},
|
||||
ignoreEdit ? 0 : 300
|
||||
);
|
||||
|
||||
countWords(5000);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user