A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: support ignoring edits
Ammar Ahmed372da979e1f1
diff --git a/apps/mobile/app/hooks/use-app-events.js b/apps/mobile/app/hooks/use-app-events.jsindex 998d41d11..4a521a98f 100644--- a/apps/mobile/app/hooks/use-app-events.js+++ b/apps/mobile/app/hooks/use-app-events.js@@ -623,15 +623,20 @@ export const useAppEvents = () => {}, [loading, onUserUpdated]);const initializeDatabase = useCallback(async () => {- if (!db.isInitialized) {- RNBootSplash.hide({ fade: true });- DatabaseLogger.info("Initializing database");- await db.init();+ try {+ if (!db.isInitialized) {+ RNBootSplash.hide({ fade: true });+ DatabaseLogger.info("Initializing database");+ await db.init();+ }+ if (IsDatabaseMigrationRequired()) return;+ initialize();+ setLoading(false);+ Walkthrough.init();+ } catch (e) {+ DatabaseLogger.error(e);+ ToastEvent.error(e, "Error initializing database", "global");}- if (IsDatabaseMigrationRequired()) return;- initialize();- setLoading(false);- Walkthrough.init();}, [IsDatabaseMigrationRequired]);useEffect(() => {diff --git a/apps/mobile/app/screens/editor/tiptap/types.ts b/apps/mobile/app/screens/editor/tiptap/types.tsindex 59c678062..154dbb332 100644--- a/apps/mobile/app/screens/editor/tiptap/types.ts+++ b/apps/mobile/app/screens/editor/tiptap/types.ts@@ -97,6 +97,7 @@ export type SavePayload = {type?: Content["type"];sessionId?: string | null;sessionHistoryId?: number;+ ignoreEdit: boolean;};export type AppState = {diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsindex 230beb7c6..c32cac079 100644--- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts+++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.ts@@ -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});}diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.tsindex a6ce82e87..932c1b72d 100644--- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts+++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts@@ -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]diff --git a/apps/mobile/native/android/app/src/main/res/values-night/styles.xml b/apps/mobile/native/android/app/src/main/res/values-night/styles.xmlindex 3ec36cbe9..f7ae8b102 100644--- a/apps/mobile/native/android/app/src/main/res/values-night/styles.xml+++ b/apps/mobile/native/android/app/src/main/res/values-night/styles.xml@@ -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">diff --git a/apps/mobile/native/android/app/src/main/res/values/styles.xml b/apps/mobile/native/android/app/src/main/res/values/styles.xmlindex 109154a7c..493644f5c 100644--- a/apps/mobile/native/android/app/src/main/res/values/styles.xml+++ b/apps/mobile/native/android/app/src/main/res/values/styles.xml@@ -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">diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsxindex 6abf91120..8b830c60c 100644--- a/packages/editor-mobile/src/components/editor.tsx+++ b/packages/editor-mobile/src/components/editor.tsx@@ -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);diff --git a/packages/editor-mobile/src/hooks/useEditorController.ts b/packages/editor-mobile/src/hooks/useEditorController.tsindex da70c9cfe..ef07a06e3 100644--- a/packages/editor-mobile/src/hooks/useEditorController.ts+++ b/packages/editor-mobile/src/hooks/useEditorController.ts@@ -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(() => {- htmlContentRef.current = editor.getHTML();- post(EventTypes.content, htmlContentRef.current, currentSessionId);- }, 300);+ timers.current.change = setTimeout(+ () => {+ htmlContentRef.current = editor.getHTML();+ post(+ EventTypes.content,+ {+ html: htmlContentRef.current,+ ignoreEdit: ignoreEdit+ },+ currentSessionId+ );+ },+ ignoreEdit ? 0 : 300+ );countWords(5000);},