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