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
handle intent from editor
ammarahm-ed0d5961ac9a9f
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex 154962b03..51d654d1a 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -1,40 +1,44 @@-import React, { useEffect } from 'react';-import { BackHandler, Keyboard, Platform, View } from 'react-native';-import { useSafeAreaInsets } from 'react-native-safe-area-context';-import { ActionIcon } from '../../components/ActionIcon';+import React, {useEffect} from 'react';+import {BackHandler, Keyboard, Platform, View} from 'react-native';+import RNExitApp from 'react-native-exit-app';+import {useSafeAreaInsets} from 'react-native-safe-area-context';+import {ActionIcon} from '../../components/ActionIcon';import {ActionSheetEvent,- simpleDialogEvent+ simpleDialogEvent,} from '../../components/DialogManager/recievers';-import { TEMPLATE_EXIT_FULLSCREEN } from '../../components/DialogManager/Templates';-import { useTracked } from '../../provider';-import { DDS } from '../../services/DeviceDetection';+import {TEMPLATE_EXIT_FULLSCREEN} from '../../components/DialogManager/Templates';+import {useTracked} from '../../provider';+import {DDS} from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,eUnSubscribeEvent,- ToastEvent+ ToastEvent,} from '../../services/EventManager';-import { editing } from '../../utils';-import { exitEditorAnimation } from '../../utils/Animations';+import {editing} from '../../utils';+import {exitEditorAnimation} from '../../utils/Animations';import {eClearEditor,eCloseFullscreenEditor,eOnLoadNote,- eOpenFullscreenEditor+ eOpenFullscreenEditor,} from '../../utils/Events';-import { tabBarRef } from '../../utils/Refs';-import { EditorTitle } from './EditorTitle';+import {sideMenuRef, tabBarRef} from '../../utils/Refs';+import {EditorTitle} from './EditorTitle';import {checkNote,clearEditor,clearTimer,EditorWebView,+ getIntent,getNote,+ isFromIntent,isNotedEdited,loadNote,post,- setColors+ saveNote,+ setColors,} from './Functions';import HistoryComponent from './HistoryComponent';@@ -78,7 +82,6 @@ const EditorHeader = () => {}, [fullscreen]);const load = async (item) => {-await loadNote(item);Keyboard.addListener('keyboardDidShow', () => {post('keyboard');@@ -106,32 +109,35 @@ const EditorHeader = () => {if (editing.currentlyEditing) {await _onBackPress();return true;- /*+ }+ };++ const _onBackPress = async () => {+ if (getIntent() && sideMenuRef.current === null) {if (tapCount > 0) {-+ console.log('called here');+ tapCount = 0;+ RNExitApp.exitApp();} else {+ await saveNote();tapCount = 1;+ console.log('tapped once');setTimeout(() => {tapCount = 0;}, 3000);- ToastEvent.show('Press back again to exit editor', 'success');- return true;- } */+ ToastEvent.show('Note saved, press back again to exit app.', 'success');+ }+ return true;}- };-- const _onBackPress = async () => {editing.currentlyEditing = false;if (DDS.isLargeTablet()) {if (fullscreen) {eSendEvent(eCloseFullscreenEditor);}} else {- /* exitEditorAnimation(); */if (DDS.isPhone || DDS.isSmallTab) {tabBarRef.current?.goToPage(0);}-eSendEvent('historyEvent', {undo: 0,redo: 0,@@ -167,44 +173,19 @@ const EditorHeader = () => {marginTop: Platform.OS === 'ios' ? 0 : insets.top,zIndex: 10,}}>- {!fullscreen ? (- DDS.isLargeTablet() ? (- <View />- ) : null- ) : (+ {DDS.isLargeTablet() && !fullscreen ? null : (<ActionIconname="arrow-left"color={colors.heading}onPress={_onBackPress}bottom={5}- iconStyle={{- textAlignVertical: 'center',- }}customStyle={{marginLeft: -5,- position: 'absolute',- marginTop: Platform.OS === 'ios' ? 0 : insets.top + 5,- zIndex: 11,- left: 0,- justifyContent: 'center',- alignItems: 'center',}}/>)}- {DDS.isLargeTablet() ? (- <EditorTitle />- ) : (- <ActionIcon- name="arrow-left"- color={colors.heading}- onPress={_onBackPress}- bottom={5}- customStyle={{- marginLeft: -5,- }}- />- )}+ {DDS.isLargeTablet() && <EditorTitle />}<Viewstyle={{diff --git a/apps/mobile/src/views/Editor/EditorTitle.js b/apps/mobile/src/views/Editor/EditorTitle.jsindex 3173d27b5..9047490f5 100644--- a/apps/mobile/src/views/Editor/EditorTitle.js+++ b/apps/mobile/src/views/Editor/EditorTitle.js@@ -49,7 +49,8 @@ export const EditorTitle = () => {<Animated.Viewstyle={{opacity: opacityVal,- maxWidth: DDS.isLargeTablet() ? '65%' : '40%',+ maxWidth: DDS.isLargeTablet() ? '100%' : '100%',+ paddingLeft:20,transform: [{translateY: translateY,diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex e204ed12f..1ef207266 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -3,7 +3,7 @@ import {Linking, Platform} from 'react-native';import {updateEvent} from '../../components/DialogManager/recievers';import {Actions} from '../../provider/Actions';import {eSendEvent, sendNoteEditedEvent} from '../../services/EventManager';-import {refreshNotesPage} from '../../utils/Events';+import {eOnLoadNote, refreshNotesPage} from '../../utils/Events';import {editing} from '../../utils';import {sleep, timeConverter} from '../../utils/TimeUtils';import {normalize} from '../../utils/SizeUtils';@@ -11,6 +11,11 @@ import {db} from '../../utils/DB';import {COLORS_NOTE, COLOR_SCHEME} from '../../utils/Colors';import {hexToRGBA} from '../../utils/ColorUtils';import {DDS} from '../../services/DeviceDetection';+import {sideMenuRef, tabBarRef} from '../../utils/Refs';+import {MMKV} from '../../utils/mmkv';+import IntentService from '../../services/IntentService';+import Navigation from '../../services/Navigation';+import SplashScreen from 'react-native-splash-screen';export const EditorWebView = createRef();@@ -27,9 +32,6 @@ export const injectedJS = ` setTimeout(() => {},100);`;---let noteEdited = false;let note = null;let id = null;@@ -79,7 +81,6 @@ export function clearTimer() {}}-export const INJECTED_JAVASCRIPT = (premium) =>premium? `(function() {@@ -151,13 +152,12 @@ function clearNote() {let currentEditingTimer = null;export async function loadNote(item) {-editing.currentlyEditing = true;post('blur');if (item && item.type === 'new') {+ intent = false;await clearEditor();clearNote();- intent = false;noteEdited = false;id = null;if (Platform.OS === 'android') {@@ -190,6 +190,15 @@ export async function loadNote(item) {}}+export function setIntentNote(item) {+ id = null;+ intent = true;+ content = {+ data: item.data,+ type: 'delta',+ };+}+export const _onMessage = async (evt) => {if (!evt || !evt.nativeEvent || !evt.nativeEvent.data) return;let message = evt.nativeEvent.data;@@ -226,6 +235,7 @@ export const _onMessage = async (evt) => {function onNoteChange() {clearTimeout(timer);timer = null;+noteEdited = true;timer = setTimeout(() => {if (noteEdited) {@@ -248,6 +258,7 @@ export async function clearEditor() {});saveCounter = 0;clearNote();+ intent = false;}function checkIfContentIsSavable() {@@ -363,27 +374,61 @@ export async function saveNote(canPost = true) {}}-export async function onWebViewLoad( premium, colors) {+export async function onWebViewLoad(premium, colors, event) {EditorWebView.current?.injectJavaScript(INJECTED_JAVASCRIPT(premium, false));if (!checkNote()) {post('blur');Platform.OS === 'android' ? EditorWebView.current?.requestFocus() : null;}post('blur');- await sleep(1000);setColors(colors);+ await loadEditorState();await loadNoteInEditor();webviewInit = true;}+async function loadEditorState() {+ if (sideMenuRef.current !== null) {+ if (intent) {+ MMKV.removeItem('appState');+ return;+ }+ console.log('checking for app state');+ let appState = await MMKV.getItem('appState');+ if (appState) {+ appState = JSON.parse(appState);+ if (appState.editing && appState.note.id !== null) {+ console.log('loading in editor');+ eSendEvent(eOnLoadNote, appState.note);+ tabBarRef.current?.goToPage(1);+ MMKV.removeItem('appState');+ }+ }+ } else {+ IntentService.check((event) => {+ if (event) {+ intent = true;+ eSendEvent(eOnLoadNote, event);+ Navigation.closeDrawer();+ tabBarRef.current?.goToPage(1);+ SplashScreen.hide();+ } else {+ eSendEvent('nointent');+ }+ });+ }+}++export let isFromIntent = false;const loadNoteInEditor = async () => {saveCounter = 0;if (intent) {post('delta', content.data);+ intent = true;await saveNote();- intent = false;} else if (note?.id) {post('title', title);+ intent = false;post('dateEdited', timeConverter(note.dateEdited));setColors();post('delta', content.data);