Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

Merge branch 'develop' into tiptap-editor

ammarahm-ed252e1b6850f9
diff --cc apps/mobile/src/components/launcher/index.js
index ec0da4e80,7f5370116..97deebef7
--- a/apps/mobile/src/components/launcher/index.js
+++ b/apps/mobile/src/components/launcher/index.js
@@@ -2,23 -2,21 +2,22 @@@ import React, { useEffect, useRef, useS
import { NativeModules, Platform, StatusBar, View } from 'react-native';
import RNBootSplash from 'react-native-bootsplash';
import { checkVersion } from 'react-native-check-version';
++import { editorState } from '../../screens/editor/tiptap/utils';
import SettingsBackupAndRestore from '../../screens/settings/backup-restore';
++import BackupService from '../../services/backup';
import BiometricService from '../../services/biometrics';
import { DDS } from '../../services/device-detection';
import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
import { setRateAppMessage } from '../../services/message';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
- import {
- initialize,
- useFavoriteStore,
- useMessageStore,
- useNoteStore,
- useSettingStore,
- useUserStore
- } from '../../stores/stores';
- import { useThemeStore } from '../../stores/theme';
- import { editing } from '../../utils';
+ import { initialize } from '../../stores';
-import { useUserStore } from '../../stores/use-user-store';
-import { useMessageStore } from '../../stores/use-message-store';
-import { useSettingStore } from '../../stores/use-setting-store';
+ import { useFavoriteStore } from '../../stores/use-favorite-store';
++import { useMessageStore } from '../../stores/use-message-store';
+ import { useNoteStore } from '../../stores/use-notes-store';
++import { useSettingStore } from '../../stores/use-setting-store';
+ import { useThemeStore } from '../../stores/use-theme-store';
-import { editing } from '../../utils';
++import { useUserStore } from '../../stores/use-user-store';
import { db } from '../../utils/database';
import { MMKV } from '../../utils/database/mmkv';
import { eOpenAnnouncementDialog } from '../../utils/events';
@@@ -27,6 -25,6 +26,7 @@@ import { SIZE } from '../../utils/size'
import { sleep } from '../../utils/time';
import { SVG } from '../auth/background';
import Intro from '../intro';
++import NewFeature from '../sheets/new-feature/index';
import { Update } from '../sheets/update';
import { Button } from '../ui/button';
import { IconButton } from '../ui/icon-button';
@@@ -36,8 -34,8 +36,6 @@@ import { SvgView } from '../ui/svg'
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
import { Walkthrough } from '../walkthroughs';
--import NewFeature from '../sheets/new-feature/index';
- import { editorState } from '../../screens/editor/tiptap/utils';
-import BackupService from '../../services/backup';
const Launcher = React.memo(
() => {
diff --cc apps/mobile/src/components/mergeconflicts/index.js
index fd5336d44,e1f56bcf8..9d072e35a
--- a/apps/mobile/src/components/mergeconflicts/index.js
+++ b/apps/mobile/src/components/mergeconflicts/index.js
@@@ -156,14 -155,16 +156,15 @@@ const MergeConflicts = () =>
id: null
});
}
-- eSendEvent(refreshNotesPage);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
- if (getNote()?.id === note.id) {
- updateNoteInEditor();
+ if (editorController.current?.note?.id === note.id) {
- updateNoteInEditor();
++ //TODO
}
close();
await Sync.run();
diff --cc apps/mobile/src/components/notehistory/preview.js
index 9041e2101,36b8c23b8..29223044e
--- a/apps/mobile/src/components/notehistory/preview.js
+++ b/apps/mobile/src/components/notehistory/preview.js
@@@ -1,12 -1,10 +1,12 @@@
import React, { useRef } from 'react';
-import { Alert, Platform, View } from 'react-native';
+import { Platform, View } from 'react-native';
import WebView from 'react-native-webview';
- import { getNote, sourceUri } from '../../screens/editor/Functions';
-import { useThemeStore } from '../../stores/use-theme-store';
-import { useEditorStore } from '../../stores/use-editor-store';
++import { sourceUri } from '../../screens/editor/Functions';
+import { editorController } from '../../screens/editor/tiptap/utils';
import { eSendEvent, ToastEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
- import { useEditorStore } from '../../stores/stores';
- import { useThemeStore } from '../../stores/theme';
++import { useEditorStore } from '../../stores/use-editor-store';
++import { useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import { eCloseProgressDialog, eOnLoadNote } from '../../utils/events';
import { openLinkInBrowser } from '../../utils/functions';
diff --cc apps/mobile/src/components/premium/premiumtoast.js
index 36f8e8318,d8ac2ebb0..cd3dccad0
--- a/apps/mobile/src/components/premium/premiumtoast.js
+++ b/apps/mobile/src/components/premium/premiumtoast.js
@@@ -11,20 -13,11 +13,12 @@@ import { sleep } from '../../utils/time
import { Button } from '../ui/button';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
+import { editorState } from '../../screens/editor/tiptap/utils';
- export const translatePrem = new Animated.Value(-dWidth);
- export const opacityPrem = new Animated.Value(0);
- let timer = null;
- let currentMsg = {
- title: '',
- desc: ''
- };
export const PremiumToast = ({ close, context = 'global', offset = 0 }) => {
const colors = useThemeStore(state => state.colors);
- const [msg, setMsg] = useState(currentMsg);
+ const [msg, setMsg] = useState(null);
+ const timer = useRef();
const open = event => {
if (!event) {
diff --cc apps/mobile/src/navigation/tabsholder.js
index ebfbcad8d,bf75e357f..90045e2ea
--- a/apps/mobile/src/navigation/tabsholder.js
+++ b/apps/mobile/src/navigation/tabsholder.js
@@@ -6,15 -6,17 +6,16 @@@ import Animated, { useAnimatedStyle, us
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { notesnook } from '../../e2e/test.ids';
import { SideMenu } from '../components/side-menu';
- import Tabs from '../components/tabs';
+ import { NewTabs } from '../components/tabs';
import { EditorWrapper } from '../screens/editor/EditorWrapper';
-import { checkStatus, EditorWebView, getNote } from '../screens/editor/Functions';
-import tiny from '../screens/editor/tiny/tiny';
+import { editorState } from '../screens/editor/tiptap/utils';
import { DDS } from '../services/device-detection';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../services/event-manager';
- import { useEditorStore, useSettingStore } from '../stores/stores';
- import { useThemeStore } from '../stores/theme';
+ import { useEditorStore } from '../stores/use-editor-store';
+ import { useSettingStore } from '../stores/use-setting-store';
+ import { useThemeStore } from '../stores/use-theme-store';
import { editing, setWidthHeight } from '../utils';
-import { updateStatusBarColor } from '../utils/color-scheme';
+import { db } from '../utils/database';
import {
eClearEditor,
eCloseFullscreenEditor,
diff --cc apps/mobile/src/screens/editor/EditorHeader.js
index 3c0c5ae28,53291d672..21e315c58
--- a/apps/mobile/src/screens/editor/EditorHeader.js
+++ b/apps/mobile/src/screens/editor/EditorHeader.js
@@@ -1,10 -1,14 +1,13 @@@
import { EV, EVENTS } from 'notes-core/common';
import React, { useEffect, useRef } from 'react';
-import { BackHandler, InteractionManager, Keyboard, Platform, Vibration, View } from 'react-native';
+import { BackHandler, InteractionManager, Platform, Vibration, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { notesnook } from '../../../e2e/test.ids';
-import { IconButton } from '../../components/ui/icon-button';
import { Properties } from '../../components/properties';
- import { IconButton } from '../../components/ui/icon-button';
+ import { useThemeStore } from '../../stores/use-theme-store';
+ import { useUserStore } from '../../stores/use-user-store';
+ import { useEditorStore } from '../../stores/use-editor-store';
+ import { useSettingStore } from '../../stores/use-setting-store';
import { DDS } from '../../services/device-detection';
import {
eSendEvent,
@@@ -13,9 -17,7 +16,7 @@@
ToastEvent
} from '../../services/event-manager';
import Navigation from '../../services/navigation';
- import { useEditorStore, useSettingStore, useUserStore } from '../../stores/stores';
- import { useThemeStore } from '../../stores/theme';
-import { editing } from '../../utils';
+import umami from '../../utils/analytics';
import { SUBSCRIPTION_STATUS } from '../../utils/constants';
import { db } from '../../utils/database';
import {
@@@ -27,15 -29,18 +28,16 @@@
eOpenPremiumDialog,
eOpenPublishNoteDialog
} from '../../utils/events';
-import useEditorTags from '../../utils/hooks/useEditorTags';
import { tabBarRef } from '../../utils/global-refs';
-import umami from '../../utils/analytics';
import { EditorTitle } from './EditorTitle';
-import { clearEditor, getNote, loadNote, setColors, startClosingSession } from './Functions';
import { ProgressCircle } from './ProgressCircle';
-import tiny, { safeKeyboardDismiss } from './tiny/tiny';
+import { safeKeyboardDismiss } from './tiny/tiny';
import { endSearch } from './tiny/toolbar/commands';
-import { toolbarRef } from './tiny/toolbar/constants';
import picker from './tiny/toolbar/picker';
+import { editorController, editorState } from './tiptap/utils';
++import { IconButton } from '../../components/ui/icon-button';
-const EditorHeader = () => {
+const EditorHeader = ({ editor }) => {
const colors = useThemeStore(state => state.colors);
const deviceMode = useSettingStore(state => state.deviceMode);
const currentlyEditingNote = useEditorStore(state => state.currentEditingNote);
diff --cc apps/mobile/src/screens/editor/EditorOverlay.js
index 389544478,09f935287..2c68b5d90
--- a/apps/mobile/src/screens/editor/EditorOverlay.js
+++ b/apps/mobile/src/screens/editor/EditorOverlay.js
@@@ -4,13 -4,12 +4,12 @@@ import Animated, { useAnimatedStyle, us
import { Button } from '../../components/ui/button';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
- import { useThemeStore } from '../../stores/theme';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
- import { editing } from '../../utils';
+ import { useThemeStore } from '../../stores/use-theme-store';
-import { editing } from '../../utils';
import { eOnLoadNote } from '../../utils/events';
import { SIZE } from '../../utils/size';
- import { sleep, timeConverter } from '../../utils/time';
+ import { timeConverter } from '../../utils/time';
+import { editorState } from './tiptap/utils';
let timer = null;
let timerError = null;
@@@ -19,10 -18,16 +18,16 @@@ const EditorOverlay = () =>
const colors = useThemeStore(state => state.colors);
const [loading, setLoading] = useState(null);
const [error, setError] = useState(false);
- const opacity = useValue(1);
+ const opacity = useSharedValue(1);
+
+ const animatedStyle = useAnimatedStyle(() => {
+ return {
+ opacity: opacity.value
+ };
+ });
const load = async _loading => {
- editing.overlay = true;
+ editorState().overlay = true;
clearTimeout(timer);
clearTimeout(timerError);
clearTimeout(timerClosing);
@@@ -43,14 -47,9 +47,9 @@@
clearTimeout(timerError);
clearTimeout(timerClosing);
setError(false);
- editing.overlay = false;
+ editorState().overlay = false;
- timing(opacity, {
- toValue: 0,
- duration: 150,
- easing: Easing.in(Easing.ease)
- }).start();
+ opacity.value = withTiming(0, { duration: 150 });
timerClosing = setTimeout(() => {
- opacity.setValue(1);
setLoading(null);
}, 150);
}
diff --cc apps/mobile/src/screens/editor/EditorWrapper.js
index 5d356e5aa,fd2e576e7..7d4b21465
--- a/apps/mobile/src/screens/editor/EditorWrapper.js
+++ b/apps/mobile/src/screens/editor/EditorWrapper.js
@@@ -11,8 -11,10 +11,9 @@@ import { useSafeAreaInsets } from 'reac
import Editor from '.';
import { PremiumToast } from '../../components/premium/premium-toast';
import { DDS } from '../../services/device-detection';
- import { useNoteStore, useSettingStore } from '../../stores/stores';
- import { useThemeStore } from '../../stores/theme';
-import { useSettingStore } from '../../stores/use-setting-store';
+ import { useNoteStore } from '../../stores/use-notes-store';
++import { useSettingStore } from '../../stores/use-setting-store';
+ import { useThemeStore } from '../../stores/use-theme-store';
-import { editing } from '../../utils';
import { editorRef } from '../../utils/global-refs';
import useIsFloatingKeyboard from '../../utils/hooks/use-is-floating-keyboard';
import EditorOverlay from './EditorOverlay';
diff --cc apps/mobile/src/screens/editor/HistoryComponent.js
index f7b179252,51e1d3ced..532b8a435
--- a/apps/mobile/src/screens/editor/HistoryComponent.js
+++ b/apps/mobile/src/screens/editor/HistoryComponent.js
@@@ -1,13 -1,13 +1,13 @@@
import React, { useEffect, useState } from 'react';
import { Platform, View } from 'react-native';
import { IconButton } from '../../components/ui/icon-button';
+ import { useThemeStore } from '../../stores/use-theme-store';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
- import { useThemeStore } from '../../stores/theme';
-import { editing } from '../../utils';
-import { SIZE } from '../../utils/size';
import useKeyboard from '../../utils/hooks/use-keyboard';
+import { SIZE } from '../../utils/size';
import { EditorWebView } from './Functions';
import tiny, { safeKeyboardDismiss } from './tiny/tiny';
+import { editorState } from './tiptap/utils';
const HistoryComponent = () => {
const colors = useThemeStore(state => state.colors);
diff --cc apps/mobile/src/screens/editor/index.js
index cf1c6bf4d,3353d9d9d..4706ecfed
--- a/apps/mobile/src/screens/editor/index.js
+++ b/apps/mobile/src/screens/editor/index.js
@@@ -2,11 -2,26 +2,11 @@@ import React from 'react'
import { Platform, View } from 'react-native';
import WebView from 'react-native-webview';
import { notesnook } from '../../../e2e/test.ids';
- import { useUserStore } from '../../stores/stores';
+ import { useUserStore } from '../../stores/use-user-store';
-import { useEditorStore } from '../../stores/use-editor-store';
-import { DDS } from '../../services/device-detection';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { getCurrentColors } from '../../utils/color-scheme';
-import { eOnLoadNote } from '../../utils/events';
-import { tabBarRef } from '../../utils/global-refs';
-import { sleep } from '../../utils/time';
import EditorHeader from './EditorHeader';
-import {
- disableEditing,
- EditorWebView,
- getNote,
- onWebViewLoad,
- sourceUri,
- _onMessage,
- _onShouldStartLoadWithRequest
-} from './Functions';
-import tiny from './tiny/tiny';
-import EditorToolbar from './tiny/toolbar';
+import { sourceUri, _onShouldStartLoadWithRequest } from './Functions';
+import { useEditor } from './tiptap/use-editor';
+import { editorController } from './tiptap/utils';
const source = { uri: sourceUri + 'index.html' };
diff --cc apps/mobile/src/screens/editor/tiny/toolbar/picker.js
index 80e30e7a1,f012ed207..6ed1910f3
--- a/apps/mobile/src/screens/editor/tiny/toolbar/picker.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/picker.js
@@@ -10,9 -10,9 +10,10 @@@ import PremiumService from '../../../..
import { editing } from '../../../../utils';
import { db } from '../../../../utils/database';
import { eCloseProgressDialog } from '../../../../utils/events';
+ import filesystem from '../../../../utils/filesystem';
import { sleep } from '../../../../utils/time';
import { EditorWebView, getNote } from '../../Functions';
+import { editorController, editorState } from '../../tiptap/utils';
import tiny, { safeKeyboardDismiss } from '../tiny';
const FILE_SIZE_LIMIT = 500 * 1024 * 1024;
diff --cc apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js
index fc65c4d88,99025dd38..af303d9db
--- a/apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js
@@@ -1,7 -1,8 +1,7 @@@
import React, { useEffect, useState } from 'react';
import { ScrollView, View } from 'react-native';
+ import { useThemeStore } from '../../../../stores/use-theme-store';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../../services/event-manager';
- import { useThemeStore } from '../../../../stores/theme';
-import { editing } from '../../../../utils';
import layoutmanager from '../../../../utils/layout-manager';
import { normalize } from '../../../../utils/size';
import { EditorWebView } from '../../Functions';
diff --cc apps/mobile/src/screens/editor/tiptap/types.ts
index 4f122b3da,000000000..4db13ee2a
mode 100644,000000..100644
--- a/apps/mobile/src/screens/editor/tiptap/types.ts
+++ b/apps/mobile/src/screens/editor/tiptap/types.ts
@@@ -1,50 -1,0 +1,50 @@@
+import { useEditor } from './use-editor';
+
+export type useEditorType = ReturnType<typeof useEditor>;
+
+export type EditorState = {
+ currentlyEditing: boolean;
+ isFullscreen: boolean;
- onNoteCreated: (id: string) => void;
++ onNoteCreated?: ((id: string) => void) | null;
+ isFocused: boolean;
+ focusType: 'title' | 'editor' | null;
+ movedAway: boolean;
+ tooltip: boolean;
+ isRestoringState: boolean;
+ keyboardState: boolean;
+ ready: boolean;
+ saveCount: 0;
+};
+
+export type Note = {
+ [name: string]: any;
+ id: string | null;
+ type: string;
+ contentId: string;
+ title: string;
+ locked: boolean;
+ conflicted: boolean;
+ dateEdited: number;
+ headline: string;
+};
+
+export type Content = {
+ data?: string;
+ type: string;
+};
+
+export type SavePayload = {
+ title?: string;
+ id?: string | null;
+ data?: Content['data'];
+ type?: Content['type'];
+ sessionId?: string | null;
+ sessionHistoryId?: number;
+};
+
+export type AppState = {
+ note?: Note;
+ editing: boolean;
+ movedAway: boolean;
+ timestamp: number;
+};
diff --cc apps/mobile/src/screens/editor/tiptap/utils.ts
index d41a6a24a,000000000..90b503870
mode 100644,000000..100644
--- a/apps/mobile/src/screens/editor/tiptap/utils.ts
+++ b/apps/mobile/src/screens/editor/tiptap/utils.ts
@@@ -1,78 -1,0 +1,78 @@@
+import { createRef, MutableRefObject } from 'react';
+import { TextInput } from 'react-native';
+import WebView from 'react-native-webview';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../../../services/event-manager';
- import { useEditorType } from './types';
++import { EditorState, useEditorType } from './types';
+export const textInput = createRef<TextInput>();
+export const editorController = createRef<useEditorType>();
+
- export const defaultState = {
++export const defaultState: Partial<EditorState> = {
+ movedAway: true
+};
+
+export function editorState() {
+ if (!editorController.current?.state.current) {
+ console.warn('Editor state not ready');
+ }
+ return editorController.current?.state.current || defaultState;
+}
+
+export const EditorEvents: { [name: string]: string } = {
+ html: 'native:html',
+ title: 'native:title',
+ theme: 'native:theme',
+ titleplaceholder: 'native:titleplaceholder',
+ logger: 'native:logger',
+ status: 'native:status'
+};
+
+export function randId(prefix: string) {
+ return Math.random()
+ .toString(36)
+ .replace('0.', prefix || '');
+}
+
+export function makeSessionId(item?: any) {
+ return item?.id ? item.id + randId('_session_') : randId('session_');
+}
+
+export async function isEditorLoaded(ref: MutableRefObject<WebView | undefined>) {
+ return await post(ref, EditorEvents.status);
+}
+
+export async function post(ref: MutableRefObject<WebView | undefined>, type: string, value = null) {
+ let sessionId = editorController.current?.sessionId;
+ if (!sessionId) {
+ console.warn('post called without sessionId of type:', type);
+ return;
+ }
+ let message = {
+ type,
+ value,
+ sessionId: sessionId
+ };
+ setImmediate(() => ref.current?.postMessage(JSON.stringify(message)));
+ let response = await getResponse(type);
+ console.log('post: ', type, sessionId, 'result:', !!response);
+ return response;
+}
+
+type WebviewResponseData = {
+ [name: string]: any;
+ sessionId: string | null;
+ type: string;
+ value: any;
+};
+
+export const getResponse = async (type: string): Promise<WebviewResponseData | false> => {
+ return new Promise(resolve => {
+ let callback = (data: WebviewResponseData) => {
+ eUnSubscribeEvent(type, callback);
+ resolve(data);
+ };
+ eSubscribeEvent(type, callback);
+ setTimeout(() => {
+ resolve(false);
+ }, 5000);
+ });
+};
diff --cc apps/mobile/src/screens/notes/common.ts
index 000000000,a106146f6..46dd1c9f0
mode 000000,100644..100644
--- a/apps/mobile/src/screens/notes/common.ts
+++ b/apps/mobile/src/screens/notes/common.ts
@@@ -1,0 -1,66 +1,128 @@@
+ import { DDS } from '../../services/device-detection';
+ import { eSendEvent } from '../../services/event-manager';
-import { NotesScreenParams } from '../../services/navigation';
-import { editing } from '../../utils';
++import Navigation, { NotesScreenParams } from '../../services/navigation';
++import { useMenuStore } from '../../stores/use-menu-store';
+ import { db } from '../../utils/database';
+ import { eOnLoadNote } from '../../utils/events';
+ import { openLinkInBrowser } from '../../utils/functions';
+ import { tabBarRef } from '../../utils/global-refs';
-import { getNote } from '../editor/Functions';
++import { editorController, editorState } from '../editor/tiptap/utils';
+
+ export function toCamelCase(title: string) {
+ return title.slice(0, 1).toUpperCase() + title.slice(1);
+ }
+
+ export function getAlias(params: NotesScreenParams) {
+ if (!params) return '';
+ const { item } = params;
+ let alias =
+ item.type === 'tag'
+ ? db.tags?.alias(item.id)
+ : item.type === 'color'
+ ? db.colors?.alias(item.id)
+ : params?.title;
+ return alias || '';
+ }
+
+ export function openMonographsWebpage() {
+ try {
+ openLinkInBrowser('https://docs.notesnook.com/monographs/');
+ } catch (e) {}
+ }
+
+ export function openEditor() {
+ if (!DDS.isTab) {
- if (getNote()) {
++ if (editorController.current?.note) {
+ eSendEvent(eOnLoadNote, { type: 'new' });
- editing.currentlyEditing = true;
- editing.movedAway = false;
++ editorState().currentlyEditing = true;
++ editorState().movedAway = false;
+ }
+ tabBarRef.current?.goToPage(1);
+ } else {
+ eSendEvent(eOnLoadNote, { type: 'new' });
+ }
+ }
+
++type FirstSaveData = {
++ type: string;
++ id: string;
++ notebook?: string;
++ color?: string;
++};
++
+ export const setOnFirstSave = (
+ data: {
+ type: string;
+ id: string;
+ notebook?: string;
+ color?: string;
+ } | null
+ ) => {
+ //@ts-ignore
- editing.actionAfterFirstSave = data;
++ editorState().onNoteCreated = onNoteCreated(id, data);
+ };
+
+ export function isSynced(params: NotesScreenParams) {
+ if (params.item.type === 'topic') {
+ console.log(params.item.type);
+ let topic = db.notebooks?.notebook(params.item.notebookId)?.topics.topic(params.item.id);
+ console.log(topic?.synced(), 'sycned');
+ return !topic ? true : topic?.synced();
+ }
+ return true;
+ }
++
++async function onNoteCreated(id: string, params: FirstSaveData) {
++ if (!params) return;
++
++ switch (params.type) {
++ case 'topic': {
++ await db.notes?.move(
++ {
++ topic: params.id,
++ id: params.notebook
++ },
++ id
++ );
++ editorState().onNoteCreated = null;
++ Navigation.queueRoutesForUpdate(
++ 'TaggedNotes',
++ 'ColoredNotes',
++ 'TopicNotes',
++ 'Favorites',
++ 'Notes',
++ 'Notebook'
++ );
++ break;
++ }
++ case 'tag': {
++ await db.notes?.note(id).tag(params.id);
++ editorState().onNoteCreated = null;
++ Navigation.queueRoutesForUpdate(
++ 'TaggedNotes',
++ 'ColoredNotes',
++ 'TopicNotes',
++ 'Favorites',
++ 'Notes'
++ );
++ eSendEvent('updateTags');
++ break;
++ }
++ case 'color': {
++ await db.notes?.note(id).color(params.color);
++ editorState().onNoteCreated = null;
++ Navigation.queueRoutesForUpdate(
++ 'TaggedNotes',
++ 'ColoredNotes',
++ 'TopicNotes',
++ 'Favorites',
++ 'Notes'
++ );
++ useMenuStore.getState().setColorNotes();
++ break;
++ }
++ default: {
++ break;
++ }
++ }
++}
diff --cc apps/mobile/src/utils/hooks/useAppEvents.js
index 30f32b1cd,2e35dd37c..1c0b7c3c2
--- a/apps/mobile/src/utils/hooks/useAppEvents.js
+++ b/apps/mobile/src/utils/hooks/useAppEvents.js
@@@ -11,18 -11,23 +11,9 @@@ import
} from 'react-native';
import * as RNIap from 'react-native-iap';
import { enabled } from 'react-native-privacy-snapshot';
- import { doInBackground, editing } from '..';
-import { editing } from '..';
import { Walkthrough } from '../../components/walkthroughs';
-import {
- EditorWebView,
- getNote,
- getWebviewInit,
- updateNoteInEditor
-} from '../../screens/editor/Functions';
-import tiny from '../../screens/editor/tiny/tiny';
+import { editorState } from '../../screens/editor/tiptap/utils';
- import Backup from '../../services/backup';
import BiometricService from '../../services/biometrics';
--import {
-- eSendEvent,
-- eSubscribeEvent,
-- eUnSubscribeEvent,
-- presentSheet,
-- ToastEvent
--} from '../../services/event-manager';
import {
clearMessage,
setEmailVerifyMessage,
@@@ -31,25 -36,20 +22,26 @@@
} from '../../services/message';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
- import Sync, { ignoredMessages } from '../../services/sync';
- import {
- clearAllStores,
- initialize,
- useAttachmentStore,
- useEditorStore,
- useMessageStore,
- useNoteStore,
- useSettingStore,
- useUserStore
- } from '../../stores/stores';
+import { updateStatusBarColor } from '../color-scheme';
+import { db } from '../database';
+import { MMKV } from '../database/mmkv';
- import { eClearEditor, eCloseProgressDialog, eOpenLoginDialog, refreshNotesPage } from '../events';
- import { sleep } from '../time';
++import { eClearEditor, eCloseProgressDialog, refreshNotesPage } from '../events';
+ import Sync from '../../services/sync';
+ import { clearAllStores, initialize } from '../../stores';
+ import { useUserStore } from '../../stores/use-user-store';
+ import { useMessageStore } from '../../stores/use-message-store';
+ import { useSettingStore } from '../../stores/use-setting-store';
+ import { useAttachmentStore } from '../../stores/use-attachment-store';
+ import { useNoteStore } from '../../stores/use-notes-store';
-import { updateStatusBarColor } from '../color-scheme';
-import { db } from '../database';
-import { MMKV } from '../database/mmkv';
-import { eClearEditor, eCloseProgressDialog, eOpenLoginDialog, refreshNotesPage } from '../events';
-import { sleep } from '../time';
++import {
++ eSendEvent,
++ eSubscribeEvent,
++ eUnSubscribeEvent,
++ ToastEvent
++} from '../../services/event-manager';
++import { useEditorStore } from '../../stores/use-editor-store';
const SodiumEventEmitter = new NativeEventEmitter(NativeModules.Sodium);
-
export const useAppEvents = () => {
const loading = useNoteStore(state => state.loading);
const setLastSynced = useUserStore(state => state.setLastSynced);
@@@ -455,17 -421,15 +415,17 @@@
}
async function storeAppState() {
- if (editing.currentlyEditing) {
- if (getNote()?.locked) return;
+ if (editorState().currentlyEditing) {
+ let id = useEditorStore.getState().currentEditingNote;
+ let note = id && db.notes.note(id).data;
+ if (note?.locked) return;
let state = JSON.stringify({
- editing: editing.currentlyEditing,
- note: getNote(),
- movedAway: editing.movedAway,
+ editing: editorState().currentlyEditing,
+ note: note,
+ movedAway: editorState().movedAway,
timestamp: Date.now()
});
- await MMKV.setItem('appState', state);
+ MMKV.setString('appState', state);
}
}