Compare commits

...

1 Commits

Author SHA1 Message Date
ammarahm-ed
f1dca7324a mobile: fix image replaces content if note is locked
& app lock is also enabled
2023-06-16 10:02:03 +05:00
3 changed files with 15 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ export type EditorState = {
keyboardState: boolean; keyboardState: boolean;
ready: boolean; ready: boolean;
saveCount: 0; saveCount: 0;
isAwaitingResult: boolean;
}; };
export type Settings = { export type Settings = {

View File

@@ -248,8 +248,11 @@ export const useEditorEvents = (
} }
}); });
}, [onHardwareBackPress]); }, [onHardwareBackPress]);
const onCallClear = useCallback(
const onClearEditorSessionRequest = useCallback(
async (value: string) => { async (value: string) => {
if (editorState()?.isAwaitingResult) return;
if (value === "removeHandler") { if (value === "removeHandler") {
if (handleBack.current) { if (handleBack.current) {
handleBack.current.remove(); handleBack.current.remove();
@@ -291,12 +294,15 @@ export const useEditorEvents = (
useEffect(() => { useEffect(() => {
eSubscribeEvent(eOnLoadNote + editor.editorId, onLoadNote); eSubscribeEvent(eOnLoadNote + editor.editorId, onLoadNote);
eSubscribeEvent(eClearEditor + editor.editorId, onCallClear); eSubscribeEvent(
eClearEditor + editor.editorId,
onClearEditorSessionRequest
);
return () => { return () => {
eUnSubscribeEvent(eClearEditor, onCallClear); eUnSubscribeEvent(eClearEditor, onClearEditorSessionRequest);
eUnSubscribeEvent(eOnLoadNote, onLoadNote); eUnSubscribeEvent(eOnLoadNote, onLoadNote);
}; };
}, [editor.editorId, onCallClear, onLoadNote]); }, [editor.editorId, onClearEditorSessionRequest, onLoadNote]);
const onMessage = useCallback( const onMessage = useCallback(
(event: WebViewMessageEvent) => { (event: WebViewMessageEvent) => {
@@ -374,8 +380,12 @@ export const useEditorEvents = (
} }
break; break;
case EventTypes.filepicker: case EventTypes.filepicker:
editorState().isAwaitingResult = true;
const { pick } = require("./picker.js").default; const { pick } = require("./picker.js").default;
pick({ type: editorMessage.value }); pick({ type: editorMessage.value });
setTimeout(() => {
editorState().isAwaitingResult = false;
}, 1000);
break; break;
case EventTypes.download: { case EventTypes.download: {
const downloadAttachment = const downloadAttachment =

View File

@@ -206,7 +206,6 @@ export const useEditor = (
type: type type: type
}; };
} }
if (!locked) { if (!locked) {
id = await db.notes?.add(noteData); id = await db.notes?.add(noteData);
if (!note && id) { if (!note && id) {