Skip to content

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

update state library

Ammar Ahmed70e37dfd5b46
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 589a66b09..d067d09ee 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -9,6 +9,7 @@ import {RootView} from './initializer.root';
import AppLoader from './src/components/AppLoader';
import {useTracked} from './src/provider';
import {Actions} from './src/provider/Actions';
+import {initialize, useNoteStore, useSettingStore} from './src/provider/stores';
import BiometricService from './src/services/BiometricService';
import {DDS} from './src/services/DeviceDetection';
import {
@@ -25,20 +26,19 @@ import EditorRoot from './src/views/Editor/EditorRoot';
let initStatus = false;
const App = () => {
const [, dispatch] = useTracked();
-
+ const setDeviceMode = useSettingStore(state => state.setDeviceMode);
useEffect(() => {
(async () => {
try {
Orientation.getOrientation((e, r) => {
DDS.checkSmallTab(r);
- dispatch({
- type: Actions.DEVICE_MODE,
- state: DDS.isLargeTablet()
+ setDeviceMode(
+ DDS.isLargeTablet()
? 'tablet'
: DDS.isSmallTab
? 'smallTablet'
: 'mobile',
- });
+ );
});
let func = async () => {
@@ -101,7 +101,7 @@ const App = () => {
if (initStatus) {
SettingsService.setAppLoaded();
eSendEvent('load_overlay');
- dispatch({type: Actions.ALL});
+ initialize();
}
};
@@ -126,7 +126,7 @@ const App = () => {
}
console.log('default note created');
await MMKV.setItem('defaultNoteCreated', 'yes');
- dispatch({type: Actions.ALL});
+ useNoteStore.getState().setNotes();
} catch (e) {
console.log(e, 'loading note on welcome');
}
diff --git a/apps/mobile/AppRootEvents.js b/apps/mobile/AppRootEvents.js
index dfdf4f10e..8391f5200 100644
--- a/apps/mobile/AppRootEvents.js
+++ b/apps/mobile/AppRootEvents.js
@@ -1,45 +1,46 @@
import NetInfo from '@react-native-community/netinfo';
-import {EV, EVENTS} from 'notes-core/common';
-import React, {useEffect} from 'react';
-import {Appearance, AppState, Keyboard, Linking, Platform} from 'react-native';
+import { EV, EVENTS } from 'notes-core/common';
+import React, { useEffect } from 'react';
+import { Appearance, AppState, Linking, Platform } from 'react-native';
import RNExitApp from 'react-native-exit-app';
import * as RNIap from 'react-native-iap';
-import {enabled} from 'react-native-privacy-snapshot';
+import { enabled } from 'react-native-privacy-snapshot';
import SplashScreen from 'react-native-splash-screen';
-import {updateEvent} from './src/components/DialogManager/recievers';
-import {useTracked} from './src/provider';
-import {Actions} from './src/provider/Actions';
+import { updateEvent } from './src/components/DialogManager/recievers';
+import { useTracked } from './src/provider';
+import { Actions } from './src/provider/Actions';
+import { clearAllStores, initialize, useNoteStore, useUserStore } from './src/provider/stores';
import Backup from './src/services/Backup';
import BiometricService from './src/services/BiometricService';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
- ToastEvent,
+ ToastEvent
} from './src/services/EventManager';
import {
clearMessage,
setEmailVerifyMessage,
- setLoginMessage,
+ setLoginMessage
} from './src/services/Message';
import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService';
import SettingsService from './src/services/SettingsService';
import Sync from './src/services/Sync';
-import {APP_VERSION, doInBackground, editing} from './src/utils';
-import {updateStatusBarColor} from './src/utils/Colors';
-import {db} from './src/utils/DB';
+import { APP_VERSION, doInBackground, editing } from './src/utils';
+import { updateStatusBarColor } from './src/utils/Colors';
+import { db } from './src/utils/DB';
import {
eClearEditor,
eCloseProgressDialog,
eOpenLoginDialog,
eOpenProgressDialog,
- refreshNotesPage,
+ refreshNotesPage
} from './src/utils/Events';
-import {MMKV} from './src/utils/mmkv';
+import { MMKV } from './src/utils/mmkv';
import Storage from './src/utils/storage';
-import {sleep} from './src/utils/TimeUtils';
-import {getNote, getWebviewInit} from './src/views/Editor/Functions';
+import { sleep } from './src/utils/TimeUtils';
+import { getNote, getWebviewInit } from './src/views/Editor/Functions';
let prevTransactionId = null;
let subsriptionSuccessListener;
@@ -66,10 +67,10 @@ async function checkIntentState() {
await db.notes.init();
}
eSendEvent('webviewreset');
- updateEvent({type: Actions.NOTES});
+ useNoteStore.getState().setNotes();
eSendEvent(refreshNotesPage);
MMKV.removeItem('notesAddedFromIntent');
- updateEvent({type: Actions.ALL});
+ initialize();
eSendEvent(refreshNotesPage);
}
} catch (e) {}
@@ -107,7 +108,11 @@ let removeInternetStateListener;
export const AppRootEvents = React.memo(
() => {
const [state, dispatch] = useTracked();
- const {loading} = state;
+ const loading = useNoteStore(state => state.loading);
+ const setLastSynced = useUserStore(state => state.setLastSynced);
+ const setUser = useUserStore(state => state.setUser);
+ const setSyncing = useUserStore(state => state.setSyncing);
+
useEffect(() => {
Appearance.addChangeListener(SettingsService.setTheme);
@@ -197,8 +202,8 @@ export const AppRootEvents = React.memo(
};
const onSyncComplete = async () => {
- dispatch({type: Actions.ALL});
- dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
+ initialize();
+ setLastSynced(await db.lastSynced())
};
const onUrlRecieved = async res => {
@@ -214,7 +219,7 @@ export const AppRootEvents = React.memo(
const onEmailVerified = async () => {
let user = await db.user.getUser();
- dispatch({type: Actions.USER, user: user});
+ setUser(user);
if (!user) return;
await PremiumService.setPremiumStatus();
let message =
@@ -266,7 +271,7 @@ export const AppRootEvents = React.memo(
const partialSync = async () => {
try {
- dispatch({type: Actions.SYNCING, syncing: true});
+ setSyncing(true);
let res = await doInBackground(async () => {
try {
await db.sync(false);
@@ -276,29 +281,27 @@ export const AppRootEvents = React.memo(
}
});
if (res !== true) throw new Error(res);
-
- dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
+ setLastSynced(await db.lastSynced())
} catch (e) {
- dispatch({type: Actions.SYNCING, syncing: false});
+ setSyncing(false);
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
context: "global",
});
} finally {
- dispatch({type: Actions.SYNCING, syncing: false});
+ setSyncing(false);
}
};
const onLogout = async reason => {
- dispatch({type: Actions.USER, user: null});
- dispatch({type: Actions.CLEAR_ALL});
- dispatch({type: Actions.SYNCING, syncing: false});
- setLoginMessage(dispatch);
- await sleep(500);
+ setUser(null);
+ clearAllStores();
+ setSyncing(false);
+ setLoginMessage();
+ await sleep(50);
await PremiumService.setPremiumStatus();
await Storage.write('introCompleted', 'true');
-
eSendEvent(eOpenProgressDialog, {
title: reason ? reason : 'User logged out',
paragraph: `You have been logged out of your account.`,
@@ -330,8 +333,8 @@ export const AppRootEvents = React.memo(
return;
let user = await db.user.getUser();
if (user) {
- dispatch({type: Actions.USER, user: user});
- clearMessage(dispatch);
+ setUser(user);
+ clearMessage();
await PremiumService.setPremiumStatus();
attachIAPListeners();
@@ -347,20 +350,20 @@ export const AppRootEvents = React.memo(
if (res !== true) throw new Error(res);
if (!user.isEmailConfirmed) {
- setEmailVerifyMessage(dispatch);
+ setEmailVerifyMessage();
return;
}
- dispatch({type: Actions.USER, user: user});
+ setUser(user);
} else {
await PremiumService.setPremiumStatus();
- setLoginMessage(dispatch);
+ setLoginMessage();
}
} catch (e) {
let user = await db.user.getUser();
if (user && !user.isEmailConfirmed) {
- setEmailVerifyMessage(dispatch);
+ setEmailVerifyMessage();
} else if (!user) {
- setLoginMessage(dispatch);
+ setLoginMessage();
} else {
console.log('unknown error', e);
}
diff --git a/apps/mobile/initializer.root.js b/apps/mobile/initializer.root.js
index 67977e985..45afa7c50 100644
--- a/apps/mobile/initializer.root.js
+++ b/apps/mobile/initializer.root.js
@@ -1,39 +1,39 @@
import {
activateKeepAwake,
- deactivateKeepAwake,
+ deactivateKeepAwake
} from '@sayem314/react-native-keep-awake';
-import React, {Component, createRef, useEffect, useRef, useState} from 'react';
-import {Dimensions, FlatList, Keyboard, TextInput, View} from 'react-native';
-import Animated, {useValue} from 'react-native-reanimated';
-import {notesnook} from './e2e/test.ids';
+import React, { Component, createRef, useEffect, useRef, useState } from 'react';
+import { Dimensions, FlatList, TextInput, View } from 'react-native';
+import Animated, { useValue } from 'react-native-reanimated';
+import { notesnook } from './e2e/test.ids';
import ContextMenu from './src/components/ContextMenu';
-import {DialogManager} from './src/components/DialogManager';
-import {DummyText} from './src/components/DummyText';
-import {Menu} from './src/components/Menu';
-import {Toast} from './src/components/Toast';
-import {NavigatorStack} from './src/navigation/NavigatorStack';
-import {useTracked} from './src/provider';
-import {Actions} from './src/provider/Actions';
-import {DDS} from './src/services/DeviceDetection';
+import { DialogManager } from './src/components/DialogManager';
+import { DummyText } from './src/components/DummyText';
+import { Menu } from './src/components/Menu';
+import { Toast } from './src/components/Toast';
+import { NavigatorStack } from './src/navigation/NavigatorStack';
+import { useTracked } from './src/provider';
+import { useSettingStore } from './src/provider/stores';
+import { DDS } from './src/services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
- eUnSubscribeEvent,
+ eUnSubscribeEvent
} from './src/services/EventManager';
-import {dHeight, editing, setWidthHeight} from './src/utils';
-import {updateStatusBarColor} from './src/utils/Colors';
+import { editing, setWidthHeight } from './src/utils';
+import { updateStatusBarColor } from './src/utils/Colors';
import {
eClearEditor,
eCloseFullscreenEditor,
eCloseSideMenu,
eOnLoadNote,
eOpenFullscreenEditor,
- eOpenSideMenu,
+ eOpenSideMenu
} from './src/utils/Events';
-import {editorRef, tabBarRef} from './src/utils/Refs';
-import {sleep} from './src/utils/TimeUtils';
-import {EditorWrapper} from './src/views/Editor/EditorWrapper';
-import {EditorWebView, getNote} from './src/views/Editor/Functions';
+import { editorRef, tabBarRef } from './src/utils/Refs';
+import { sleep } from './src/utils/TimeUtils';
+import { EditorWrapper } from './src/views/Editor/EditorWrapper';
+import { EditorWebView, getNote } from './src/views/Editor/Functions';
import tiny from './src/views/Editor/tiny/tiny';
let {width, height} = Dimensions.get('window');
let layoutTimer = null;
@@ -49,7 +49,6 @@ const onChangeTab = async obj => {
activateKeepAwake();
eSendEvent('navigate');
eSendEvent(eClearEditor, 'addHandler');
- console.log(editing.currentlyEditing, getNote(), editing.isRestoringState);
if (
!editing.isRestoringState &&
(!editing.currentlyEditing || !getNote())
@@ -146,13 +145,18 @@ const _onTouchEnd = e => {
const AppStack = React.memo(
() => {
const [state, dispatch] = useTracked();
- const {colors, deviceMode} = state;
+ const {colors} = state;
+
+ const deviceMode = useSettingStore(state => state.deviceMode);
+ const setFullscreen = useSettingStore(state => state.setFullscreen);
+ const setDeviceModeState = useSettingStore(state => state.setDeviceMode);
+
const [dimensions, setDimensions] = useState({width, height});
const animatedOpacity = useValue(0);
- const animatedHeight = useValue(0);
const overlayRef = useRef();
+
const showFullScreenEditor = () => {
- dispatch({type: Actions.FULLSCREEN, state: true});
+ setFullscreen(true);
editorRef.current?.setNativeProps({
style: {
position: 'absolute',
@@ -165,7 +169,7 @@ const AppStack = React.memo(
};
const closeFullScreenEditor = () => {
- dispatch({type: Actions.FULLSCREEN, state: false});
+ setFullscreen(false);
editorRef.current?.setNativeProps({
style: {
position: 'relative',
@@ -198,7 +202,7 @@ const AppStack = React.memo(
if (!size || (size.width === dimensions.width && deviceMode !== null)) {
DDS.setSize(size);
//console.log(deviceMode, 'MODE__');
- dispatch({type: Actions.DEVICE_MODE, state: deviceMode});
+ setDeviceModeState(deviceMode)
return;
}
@@ -235,8 +239,8 @@ const AppStack = React.memo(
function setDeviceMode(current, size) {
eSendEvent(current !== 'mobile' ? eCloseSideMenu : eOpenSideMenu);
- dispatch({type: Actions.DEVICE_MODE, state: current});
- dispatch({type: Actions.FULLSCREEN, state: false});
+ setDeviceModeState(current);
+ setFullscreen(false);
editorRef.current?.setNativeProps({
style: {
diff --git a/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js b/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js
index 147983b3b..2d34713bd 100644
--- a/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js
+++ b/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js
@@ -4,6 +4,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useMenuStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent, sendNoteEditedEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
@@ -20,7 +21,7 @@ import {PressableButton} from '../PressableButton';
export const ActionSheetColorsSection = ({item, close}) => {
const [, dispatch] = useTracked();
const [note, setNote] = useState(item);
-
+ const setColorNotes = useMenuStore(state => state.setColorNotes)
const localRefresh = () => {
toAdd = db.notes.note(note.id);
if (toAdd) {
@@ -56,7 +57,7 @@ export const ActionSheetColorsSection = ({item, close}) => {
await db.notes.note(note.id).color(color.name);
}
localRefresh();
- dispatch({type: Actions.COLORS});
+ setColorNotes();
Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js
index 962ccf0fe..1e2047412 100644
--- a/apps/mobile/src/components/ActionSheetComponent/index.js
+++ b/apps/mobile/src/components/ActionSheetComponent/index.js
@@ -11,8 +11,9 @@ import {
import Share from 'react-native-share';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids';
-import { useNoteStore, useTracked, useTrackedNotes } from '../../provider';
+import { useTracked, useTrackedNotes } from '../../provider';
import { Actions } from '../../provider/Actions';
+import { useMenuStore, useNotebookStore, useNoteStore, useSelectionStore, useUserStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import {
eSendEvent,
@@ -55,7 +56,17 @@ export const ActionSheetComponent = ({
getRef,
}) => {
const [state, dispatch] = useTracked();
- const {colors, user, lastSynced} = state;
+ const {colors,} = state;
+
+ const setNotes = useNoteStore(state => state.setNotes);
+ const setNotebooks = useNotebookStore(state => state.setNotebooks);
+ const clearSelection = useSelectionStore(state => state.clearSelection);
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
+ const setMenuPins = useMenuStore(state => state.setMenuPins);
+
+ const user = useUserStore(state => state.user);
+ const lastSynced = useUserStore(state => state.lastSynced);
+
const [refreshing, setRefreshing] = useState(false);
const [isPinnedToMenu, setIsPinnedToMenu] = useState(false);
const [note, setNote] = useState(item);
@@ -125,15 +136,17 @@ export const ActionSheetComponent = ({
if (!toAdd || !toAdd.id) return;
if (!nodispatch) {
- dispatch({type: type});
- if (type === 'note') {
- Navigation.setRoutesToUpdate([
+ Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
+ Navigation.routeNames.Notebooks,
+ Navigation.routeNames.Notebook,
+ Navigation.routeNames.Tags,
+ Navigation.routeNames.Trash,
]);
- }
}
+
setNote({...toAdd});
};
@@ -143,8 +156,9 @@ export const ActionSheetComponent = ({
icon: 'book-outline',
func: () => {
close();
- dispatch({type: Actions.CLEAR_SELECTION});
- dispatch({type: Actions.SELECTED_ITEMS, item: note});
+
+ clearSelection();
+ setSelectedItem(item);
setTimeout(() => {
eSendEvent(eOpenMoveNoteDialog, note);
}, 300);
@@ -346,11 +360,6 @@ export const ActionSheetComponent = ({
} else {
await db.notebooks.notebook(note.id).favorite();
}
- //dispatch({type: Actions.NOTES});
- dispatchh({type:Actions.NOTES});
- //setNotes()
- //eSendEvent("onListUpdate",db.notes.note(note.id).data);
- return;
Navigation.setRoutesToUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
@@ -386,7 +395,7 @@ export const ActionSheetComponent = ({
}
}
setIsPinnedToMenu(db.settings.isPinned(note.id));
- dispatch({type: Actions.MENU_PINS});
+ setMenuPins();
} catch (e) {}
},
close: false,
diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js
index 632cc9072..449246be9 100644
--- a/apps/mobile/src/components/AddNotebookDialog/index.js
+++ b/apps/mobile/src/components/AddNotebookDialog/index.js
@@ -12,6 +12,7 @@ import {
import {FlatList, TextInput} from 'react-native-gesture-handler';
import {notesnook} from '../../../e2e/test.ids';
import {Actions} from '../../provider/Actions';
+import { useMenuStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {ToastEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
@@ -203,7 +204,7 @@ export class AddNotebookDialog extends React.Component {
id: id,
});
}
- updateEvent({type: Actions.MENU_PINS});
+ useMenuStore.getState().setMenuPins();
Navigation.setRoutesToUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notebook,
diff --git a/apps/mobile/src/components/AddTopicDialog/index.js b/apps/mobile/src/components/AddTopicDialog/index.js
index 8af16c86f..87ed144ce 100644
--- a/apps/mobile/src/components/AddTopicDialog/index.js
+++ b/apps/mobile/src/components/AddTopicDialog/index.js
@@ -1,5 +1,6 @@
import React, {createRef} from 'react';
import {Actions} from '../../provider/Actions';
+import { useMenuStore } from '../../provider/stores';
import {
eSubscribeEvent,
eUnSubscribeEvent,
@@ -60,7 +61,7 @@ export class AddTopicDialog extends React.Component {
Navigation.routeNames.Notebook,
Navigation.routeNames.NotesPage,
]);
- updateEvent({type: Actions.MENU_PINS});
+ useMenuStore.getState().setMenuPins();
} catch (e) {}
};
diff --git a/apps/mobile/src/components/AppLoader/index.js b/apps/mobile/src/components/AppLoader/index.js
index d42cf7cbe..be678693f 100644
--- a/apps/mobile/src/components/AppLoader/index.js
+++ b/apps/mobile/src/components/AppLoader/index.js
@@ -4,6 +4,7 @@ import Animated, { Easing } from 'react-native-reanimated';
import AnimatedProgress from 'react-native-reanimated-progress-bar';
import { useTracked } from '../../provider';
import { Actions } from '../../provider/Actions';
+import { useFavoriteStore, useNoteStore } from '../../provider/stores';
import {
eSendEvent,
eSubscribeEvent,
@@ -25,7 +26,9 @@ const AppLoader = ({onLoad}) => {
const colors = state.colors;
const [loading, setLoading] = useState(true);
const [opacity, setOpacity] = useState(true);
-
+ const setNotes = useNoteStore(state => state.setNotes);
+ const setFavorites = useFavoriteStore(state => state.setFavorites);
+ const _setLoading = useNoteStore(state => state.setLoading)
const load = async value => {
console.log('loading called here');
if (value === 'hide') {
@@ -64,9 +67,9 @@ const AppLoader = ({onLoad}) => {
setTimeout(async ()=>{
setLoading(false);
await db.notes.init();
- dispatch({type: Actions.NOTES});
- dispatch({type: Actions.FAVORITES});
- dispatch({type: Actions.LOADING, loading: false});
+ setNotes();
+ setFavorites();
+ _setLoading(false);
eSendEvent(eOpenSideMenu);
let askForRating = await MMKV.getItem('askForRating');
if (askForRating !== 'never' || askForRating !== 'completed') {
diff --git a/apps/mobile/src/components/Container/ContainerTopSection.js b/apps/mobile/src/components/Container/ContainerTopSection.js
index fad199b51..cb746c093 100644
--- a/apps/mobile/src/components/Container/ContainerTopSection.js
+++ b/apps/mobile/src/components/Container/ContainerTopSection.js
@@ -1,10 +1,12 @@
import React from 'react';
import { View } from 'react-native';
import { useTracked } from '../../provider';
+import { useSelectionStore } from '../../provider/stores';
export const ContainerTopSection = ({children}) => {
const [state] = useTracked();
- const {colors, selectionMode} = state;
+ const {colors} = state;
+ const selectionMode = useSelectionStore(state => state.selectionMode);
return !selectionMode && (
<View
diff --git a/apps/mobile/src/components/Dialog/BaseDialog.js b/apps/mobile/src/components/Dialog/BaseDialog.js
index 019febbe8..6821d534d 100644
--- a/apps/mobile/src/components/Dialog/BaseDialog.js
+++ b/apps/mobile/src/components/Dialog/BaseDialog.js
@@ -24,7 +24,7 @@ const BaseDialog = ({
centered = true,
}) => {
const [state, dispatch] = useTracked();
- const scaleValue = new Animated.Value(1);
+
const floating = useIsFloatingKeyboard();
return (
<Modal
diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.js
index f4619752c..104cc7d43 100644
--- a/apps/mobile/src/components/Dialog/index.js
+++ b/apps/mobile/src/components/Dialog/index.js
@@ -1,6 +1,7 @@
import React, {Component} from 'react';
import {View} from 'react-native';
import {Actions} from '../../provider/Actions';
+import { useSelectionStore, useTrashStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {ToastEvent} from '../../services/EventManager';
import {getElevation, history} from '../../utils';
@@ -38,9 +39,8 @@ export class Dialog extends Component {
let ids = [];
history.selectedItemsList.forEach((item) => ids.push(item.id));
await db.trash.delete(...ids);
- updateEvent({type: Actions.TRASH});
- updateEvent({type: Actions.CLEAR_SELECTION});
- updateEvent({type: Actions.SELECTION_MODE, enabled: false});
+ useTrashStore.getState().setTrash();
+ useSelectionStore.getState().clearSelection();
ToastEvent.show({
heading: 'Permanantly deleted items',
type: 'success',
@@ -51,9 +51,8 @@ export class Dialog extends Component {
}
case dialogActions.ACTION_EMPTY_TRASH: {
await db.trash.clear();
- updateEvent({type: Actions.TRASH});
- updateEvent({type: Actions.CLEAR_SELECTION});
- updateEvent({type: Actions.SELECTION_MODE, enabled: false});
+ useTrashStore.getState().setTrash();
+ useSelectionStore.getState().clearSelection();
ToastEvent.show({
heading: 'Trash cleared',
message:"All notes and notebooks in the trash have been removed permanantly.",
diff --git a/apps/mobile/src/components/ExportDialog/index.js b/apps/mobile/src/components/ExportDialog/index.js
index 0d9e3e90d..879176e7f 100644
--- a/apps/mobile/src/components/ExportDialog/index.js
+++ b/apps/mobile/src/components/ExportDialog/index.js
@@ -30,7 +30,8 @@ const {
const ExportDialog = () => {
const [state] = useTracked();
- const {colors, tags, premiumUser} = state;
+ const {colors} = state;
+
const [visible, setVisible] = useState(false);
const [notes, setNotes] = useState([]);
const [exporting, setExporting] = useState(false);
diff --git a/apps/mobile/src/components/Header/HeaderLeftMenu.js b/apps/mobile/src/components/Header/HeaderLeftMenu.js
index 0d8430692..d337a97e8 100644
--- a/apps/mobile/src/components/Header/HeaderLeftMenu.js
+++ b/apps/mobile/src/components/Header/HeaderLeftMenu.js
@@ -1,6 +1,7 @@
import React from 'react';
import { notesnook } from '../../../e2e/test.ids';
import { useTracked } from '../../provider';
+import { useSettingStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import Navigation from '../../services/Navigation';
import { SIZE } from '../../utils/SizeUtils';
@@ -8,7 +9,8 @@ import { ActionIcon } from '../ActionIcon';
export const HeaderLeftMenu = ({currentScreen,headerMenuState}) => {
const [state] = useTracked();
- const {colors, deviceMode} = state;
+ const {colors} = state;
+ const deviceMode = useSettingStore(state => state.deviceMode);
const onLeftButtonPress = () => {
if (headerMenuState) {
diff --git a/apps/mobile/src/components/Header/HeaderMenu.js b/apps/mobile/src/components/Header/HeaderMenu.js
index 6b15a3c09..91eef097e 100644
--- a/apps/mobile/src/components/Header/HeaderMenu.js
+++ b/apps/mobile/src/components/Header/HeaderMenu.js
@@ -2,6 +2,7 @@ import React from 'react';
import { TouchableOpacity } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { useTracked } from '../../provider';
+import { useSettingStore } from '../../provider/stores';
import { eSendEvent } from '../../services/EventManager';
import { getElevation } from '../../utils';
import { eOpenSortDialog } from '../../utils/Events';
@@ -10,7 +11,8 @@ import Heading from '../Typography/Heading';
export const HeaderMenu = () => {
const [state] = useTracked();
- const {colors, settings} = state;
+ const {colors} = state;
+ const settings = useSettingStore(state => state.settings);
return (
<TouchableOpacity
diff --git a/apps/mobile/src/components/Header/HeaderRightMenu.js b/apps/mobile/src/components/Header/HeaderRightMenu.js
index 9d7e0cbf1..0945e57f0 100644
--- a/apps/mobile/src/components/Header/HeaderRightMenu.js
+++ b/apps/mobile/src/components/Header/HeaderRightMenu.js
@@ -2,6 +2,7 @@ import React from 'react';
import { ActivityIndicator, StyleSheet, View } from 'react-native';
import { notesnook } from '../../../e2e/test.ids';
import { useTracked } from '../../provider';
+import { useUserStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import Navigation from '../../services/Navigation';
import { SIZE } from '../../utils/SizeUtils';
@@ -10,7 +11,8 @@ import { Button } from '../Button';
export const HeaderRightMenu = ({currentScreen,action}) => {
const [state] = useTracked();
- const {colors, syncing} = state;
+ const {colors} = state;
+ const syncing = useUserStore(state => state.syncing);
return (
<View style={styles.rightBtnContainer}>
diff --git a/apps/mobile/src/components/JumpToDialog/index.js b/apps/mobile/src/components/JumpToDialog/index.js
index a8103a34f..748620976 100644
--- a/apps/mobile/src/components/JumpToDialog/index.js
+++ b/apps/mobile/src/components/JumpToDialog/index.js
@@ -4,6 +4,7 @@ import BaseDialog from '../../components/Dialog/base-dialog';
import {PressableButton} from '../../components/PressableButton';
import Seperator from '../../components/Seperator';
import {useTracked} from '../../provider';
+import { useNoteStore, useSettingStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import {getElevation} from '../../utils';
@@ -19,7 +20,11 @@ const offsets = [];
let timeout = null;
const JumpToDialog = ({scrollRef}) => {
const [state] = useTracked();
- const {notes, colors, settings} = state;
+ const {colors} = state;
+
+ const notes = useNoteStore(state => state.notes);
+ const settings = useSettingStore(state => state.settings);
+
const [visible, setVisible] = useState(false);
const [currentIndex, setCurrentIndex] = useState(null);
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 7b04d84b1..3437a54e1 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -9,6 +9,7 @@ import Seperator from '../../components/Seperator';
import {Toast} from '../../components/Toast';
import {Actions} from '../../provider/Actions';
import {useTracked} from '../../provider/index';
+import { useUserStore } from '../../provider/stores';
import BiometricService from '../../services/BiometricService';
import {DDS} from '../../services/DeviceDetection';
import {
@@ -71,6 +72,10 @@ function getEmail() {
const LoginDialog = () => {
const [state, dispatch] = useTracked();
const colors = state.colors;
+
+ const setUser = useUserStore(state => state.setUser);
+ const setLastSynced = useUserStore(state => state.setLastSynced)
+
const [visible, setVisible] = useState(false);
const [status, setStatus] = useState(null);
const [loading, setLoading] = useState(false);
@@ -81,6 +86,7 @@ const LoginDialog = () => {
const [confirm, setConfirm] = useState(false);
const insets = useSafeAreaInsets();
+
const _email = useRef();
const _pass = useRef();
const _username = useRef();
@@ -236,8 +242,8 @@ const LoginDialog = () => {
if (!user) throw new Error('Email or password incorrect!');
setStatus('Syncing Your Data');
PremiumService.setPremiumStatus();
- dispatch({type: Actions.USER, user: user});
- clearMessage(dispatch);
+ setUser(user);
+ clearMessage();
ToastEvent.show({
heading: 'Login successful',
message: `Logged in as ${user.email}`,
@@ -318,10 +324,10 @@ const LoginDialog = () => {
await db.user.signup(email, password);
let user = await db.user.getUser();
setStatus('Setting Crenditials');
- dispatch({type: Actions.USER, user: user});
- dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
- clearMessage(dispatch);
- setEmailVerifyMessage(dispatch);
+ setUser(user);
+ setLastSynced(await db.lastSynced())
+ clearMessage();
+ setEmailVerifyMessage();
close();
await sleep(300);
eSendEvent(eOpenRecoveryKeyDialog, true);
diff --git a/apps/mobile/src/components/Menu/ColorSection.js b/apps/mobile/src/components/Menu/ColorSection.js
index 4fe49bf87..33dfabc41 100644
--- a/apps/mobile/src/components/Menu/ColorSection.js
+++ b/apps/mobile/src/components/Menu/ColorSection.js
@@ -2,6 +2,7 @@ import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useMenuStore, useNoteStore } from '../../provider/stores';
import {
eSendEvent,
eSubscribeEvent,
@@ -17,12 +18,13 @@ import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
export const ColorSection = () => {
- const [state, dispatch] = useTracked();
- const {colorNotes, loading} = state;
+ const colorNotes = useMenuStore(state => state.colorNotes);
+ const loading = useNoteStore(state => state.loading);
+ const setColorNotes = useMenuStore(state => state.setColorNotes);
useEffect(() => {
if (!loading) {
- dispatch({type: Actions.COLORS});
+ setColorNotes();
}
}, [loading]);
@@ -33,7 +35,7 @@ export const ColorSection = () => {
};
const ColorItem = ({item, index}) => {
- const [state, dispatch] = useTracked();
+ const [state] = useTracked();
const {colors} = state;
const [headerTextState, setHeaderTextState] = useState(null);
diff --git a/apps/mobile/src/components/Menu/TagsSection.js b/apps/mobile/src/components/Menu/TagsSection.js
index 31074e1db..2284df981 100644
--- a/apps/mobile/src/components/Menu/TagsSection.js
+++ b/apps/mobile/src/components/Menu/TagsSection.js
@@ -3,6 +3,7 @@ import {FlatList, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useMenuStore, useNoteStore } from '../../provider/stores';
import {
eSendEvent,
eSubscribeEvent,
@@ -20,12 +21,13 @@ import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
export const TagsSection = () => {
- const [state, dispatch] = useTracked();
- const {colors, menuPins, loading} = state;
+ const menuPins = useMenuStore(state => state.menuPins);
+ const loading = useNoteStore(state => state.loading);
+ const setMenuPins =useMenuStore(state => state.setMenuPins);
useEffect(() => {
if (!loading) {
- dispatch({type: Actions.MENU_PINS});
+ setMenuPins();
}
}, [loading]);
@@ -94,6 +96,9 @@ export const TagsSection = () => {
const PinItem = ({item, index, onPress}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
+
+ const setMenuPins =useMenuStore(state => state.setMenuPins);
+
const [visible, setVisible] = useState(false);
const [headerTextState, setHeaderTextState] = useState(null);
const color = headerTextState?.id === item.id ? colors.accent : colors.pri;
@@ -134,7 +139,7 @@ const PinItem = ({item, index, onPress}) => {
type="error"
onPress={async () => {
await db.settings.unpin(item.id);
- dispatch({type: Actions.MENU_PINS});
+ setMenuPins();
}}
fontSize={SIZE.md}
width="95%"
diff --git a/apps/mobile/src/components/Menu/UserSection.js b/apps/mobile/src/components/Menu/UserSection.js
index c07e99e80..b939fadea 100644
--- a/apps/mobile/src/components/Menu/UserSection.js
+++ b/apps/mobile/src/components/Menu/UserSection.js
@@ -3,6 +3,7 @@ import { ActivityIndicator, Platform, TouchableOpacity, View } from 'react-nativ
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { useTracked } from '../../provider';
+import { useUserStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent, ToastEvent } from '../../services/EventManager';
import Sync from '../../services/Sync';
@@ -14,7 +15,12 @@ import { TimeSince } from './TimeSince';
export const UserSection = () => {
const [state] = useTracked();
- const {colors, syncing, user, lastSynced} = state;
+ const {colors} = state;
+
+ const user = useUserStore(state => state.user);
+ const syncing = useUserStore(state => state.syncing);
+ const lastSynced = useUserStore(state => state.lastSynced);
+
const insets = useSafeAreaInsets();
return (
<View
diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js
index 064d64022..b25bc4bfd 100644
--- a/apps/mobile/src/components/Menu/index.js
+++ b/apps/mobile/src/components/Menu/index.js
@@ -5,6 +5,7 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useSettingStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {DrawerScale} from '../../utils/Animations';
import {
@@ -24,7 +25,10 @@ import {UserSection} from './UserSection';
export const Menu = React.memo(
() => {
const [state, dispatch] = useTracked();
- const {colors, deviceMode} = state;
+ const {colors} = state;
+
+ const deviceMode = useSettingStore(state => state.deviceMode);
+
const insets = useSafeAreaInsets();
const noTextMode = false;
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
diff --git a/apps/mobile/src/components/MoveNoteDialog/index.js b/apps/mobile/src/components/MoveNoteDialog/index.js
index 8e637097b..788f12e8b 100644
--- a/apps/mobile/src/components/MoveNoteDialog/index.js
+++ b/apps/mobile/src/components/MoveNoteDialog/index.js
@@ -5,6 +5,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useNotebookStore, useSelectionStore } from '../../provider/stores';
import {
eSubscribeEvent,
eUnSubscribeEvent,
@@ -60,7 +61,6 @@ const MoveNoteDialog = () => {
Navigation.routeNames.Notebook,
Navigation.routeNames.Notebooks,
]);
- //dispatch({type: Actions.CLEAR_SELECTION});
};
const update = (note) => {
@@ -78,7 +78,13 @@ export default MoveNoteDialog;
const MoveNoteComponent = ({close, note, setNote}) => {
const [state, dispatch] = useTracked();
- const {colors, selectedItemsList, notebooks} = state;
+ const {colors} = state;
+
+ const notebooks = useNotebookStore(state => state.notebooks);
+ const selectedItemsList = useSelectionStore(state => state.selectedItemsList);
+ const setNotebooks = useNotebookStore(state => state.setNotebooks);
+
+
const [expanded, setExpanded] = useState('');
const [notebookInputFocused, setNotebookInputFocused] = useState(false);
const [topicInputFocused, setTopicInputFocused] = useState(false);
@@ -99,7 +105,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
});
notebookInput.current?.clear();
notebookInput.current?.blur();
- dispatch({type: Actions.NOTEBOOKS});
+ setNotebooks();
};
const addNewTopic = async () => {
@@ -111,7 +117,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
});
}
await db.notebooks.notebook(expanded).topics.add(newTopicTitle);
- dispatch({type: Actions.NOTEBOOKS});
+ setNotebooks();
topicInput.current?.clear();
topicInput.current?.blur();
newTopicTitle = null;
@@ -132,7 +138,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
Navigation.routeNames.Notes,
]);
}
- dispatch({type: Actions.NOTEBOOKS});
+ setNotebooks();
return;
}
@@ -156,7 +162,7 @@ const MoveNoteComponent = ({close, note, setNote}) => {
Navigation.routeNames.Notes,
]);
}
- dispatch({type: Actions.NOTEBOOKS});
+ setNotebooks();
};
useEffect(() => {
diff --git a/apps/mobile/src/components/NoteItem/wrapper.js b/apps/mobile/src/components/NoteItem/wrapper.js
index e4ffeced3..f0f001d0b 100644
--- a/apps/mobile/src/components/NoteItem/wrapper.js
+++ b/apps/mobile/src/components/NoteItem/wrapper.js
@@ -3,6 +3,7 @@ import NoteItem from '.';
import { notesnook } from '../../../e2e/test.ids';
import { useTracked } from '../../provider';
import { Actions } from '../../provider/Actions';
+import { useSelectionStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent, openVault } from '../../services/EventManager';
import { history } from '../../utils';
@@ -14,13 +15,13 @@ import { TEMPLATE_TRASH } from '../DialogManager/Templates';
import SelectionWrapper from '../SelectionWrapper';
export const NoteWrapper = React.memo(({item, index}) => {
- const [state, dispatch] = useTracked();
const isTrash = item.type === 'trash';
-
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
+
const onPress = async () => {
let _note = db.notes.note(item.id).data;
if (history.selectedItemsList.length > 0 ) {
- dispatch({type: Actions.SELECTED_ITEMS, item: _note});
+ setSelectedItem(_note);
return;
}
diff --git a/apps/mobile/src/components/NotebookItem/wrapper.js b/apps/mobile/src/components/NotebookItem/wrapper.js
index c41b76175..672e3f605 100644
--- a/apps/mobile/src/components/NotebookItem/wrapper.js
+++ b/apps/mobile/src/components/NotebookItem/wrapper.js
@@ -1,22 +1,17 @@
import React from 'react';
-import {NotebookItem} from '.';
-import {useTracked} from '../../provider';
-import {Actions} from '../../provider/Actions';
+import { NotebookItem } from '.';
+import { useSelectionStore } from '../../provider/stores';
import Navigation from '../../services/Navigation';
-import {history} from '../../utils';
+import { history } from '../../utils';
import SelectionWrapper from '../SelectionWrapper';
export const NotebookWrapper = React.memo(({item, index}) => {
- const [state, dispatch] = useTracked();
const isTrash = item.type === 'trash';
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem)
const onPress = () => {
if (history.selectedItemsList.length > 0) {
- dispatch({
- type: Actions.SELECTED_ITEMS,
- item: item,
- });
-
+ setSelectedItem(item);
return;
}
let routeName = item.type === "topic" ? 'NotesPage' : 'Notebook';
diff --git a/apps/mobile/src/components/PressableButton/index.js b/apps/mobile/src/components/PressableButton/index.js
index 7f306bc27..f4aae7e84 100644
--- a/apps/mobile/src/components/PressableButton/index.js
+++ b/apps/mobile/src/components/PressableButton/index.js
@@ -33,6 +33,7 @@ export const PressableButton = ({
}) => {
const [state] = useTracked();
const {colors} = state;
+
const selectedColor = customSelectedColor ||
colors[
type === 'accent'
diff --git a/apps/mobile/src/components/RestoreDialog/index.js b/apps/mobile/src/components/RestoreDialog/index.js
index 26f1d8bbe..7d2d397b2 100644
--- a/apps/mobile/src/components/RestoreDialog/index.js
+++ b/apps/mobile/src/components/RestoreDialog/index.js
@@ -4,6 +4,7 @@ import DocumentPicker from 'react-native-document-picker';
import {FlatList} from 'react-native-gesture-handler';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { initialize } from '../../provider/stores';
import {
eSubscribeEvent,
eUnSubscribeEvent,
@@ -105,7 +106,7 @@ const RestoreDataComponent = ({close, setRestoring, restoring}) => {
let backup = await RNFetchBlob.fs.readFile(prefix + item.path, 'utf8');
await db.backup.import(backup);
setRestoring(false);
- dispatch({type: Actions.ALL});
+ initialize();
ToastEvent.show({
heading: 'Restore successful',
message: 'Your backup data has been restored successfully.',
@@ -182,7 +183,7 @@ const RestoreDataComponent = ({close, setRestoring, restoring}) => {
await db.backup.import(JSON.stringify(backup));
setRestoring(false);
- dispatch({type: Actions.ALL});
+ initialize();
ToastEvent.show({
heading: 'Restore successful',
diff --git a/apps/mobile/src/components/SelectionHeader/index.js b/apps/mobile/src/components/SelectionHeader/index.js
index 4a6894832..83e8daf68 100644
--- a/apps/mobile/src/components/SelectionHeader/index.js
+++ b/apps/mobile/src/components/SelectionHeader/index.js
@@ -4,6 +4,7 @@ import {View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useSelectionStore } from '../../provider/stores';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {db} from '../../utils/DB';
@@ -20,7 +21,13 @@ import Heading from '../Typography/Heading';
export const SelectionHeader = React.memo(({screen, type, extras}) => {
const [state, dispatch] = useTracked();
- const {colors, selectionMode, selectedItemsList} = state;
+ const {colors} = state;
+
+ const selectionMode = useSelectionStore(state => state.selectionMode);
+ const selectedItemsList = useSelectionStore(state => state.selectedItemsList);
+ const setSelectionMode = useSelectionStore(state => state.setSelectionMode);
+ const clearSelection = useSelectionStore(state => state.clearSelection)
+
const insets = useSafeAreaInsets();
const addToFavorite = async () => {
@@ -33,8 +40,8 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
]);
- dispatch({type: Actions.SELECTION_MODE, enabled: false});
- dispatch({type: Actions.CLEAR_SELECTION});
+ setSelectionMode(false);
+ clearSelection();
}
};
@@ -53,8 +60,8 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
Navigation.routeNames.Favorites,
Navigation.routeNames.Trash,
]);
- dispatch({type: Actions.SELECTION_MODE, enabled: false});
- dispatch({type: Actions.CLEAR_SELECTION});
+ setSelectionMode(false);
+ clearSelection();
ToastEvent.show({
heading: 'Restore successful',
type: 'success',
@@ -63,8 +70,8 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
};
const onBackPress = () => {
- dispatch({type: Actions.SELECTION_MODE, enabled: false});
- dispatch({type: Actions.CLEAR_SELECTION});
+ setSelectionMode(false);
+ clearSelection();
return true;
};
@@ -109,8 +116,8 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
marginRight: 25,
}}
onPress={() => {
- dispatch({type: Actions.SELECTION_MODE, enabled: !selectionMode});
- dispatch({type: Actions.CLEAR_SELECTION});
+ setSelectionMode(!selectionMode)
+ clearSelection();
}}
color={colors.light}
name="close"
@@ -145,7 +152,7 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
type === 'topic' ? null : (
<ActionIcon
onPress={async () => {
- //dispatch({type: Actions.SELECTION_MODE, enabled: false});
+ //setSelectionMode(false);
await sleep(100);
eSendEvent(eOpenMoveNoteDialog);
}}
@@ -175,8 +182,8 @@ export const SelectionHeader = React.memo(({screen, type, extras}) => {
Navigation.routeNames.Notebook,
Navigation.routeNames.Notebooks,
]);
- dispatch({type: Actions.SELECTION_MODE, enabled: false});
- dispatch({type: Actions.CLEAR_SELECTION});
+ setSelectionMode(false);
+ clearSelection();
}
}}
customStyle={{
diff --git a/apps/mobile/src/components/SelectionWrapper/actionstrip.js b/apps/mobile/src/components/SelectionWrapper/actionstrip.js
index 5974a76c0..74ad33bf4 100644
--- a/apps/mobile/src/components/SelectionWrapper/actionstrip.js
+++ b/apps/mobile/src/components/SelectionWrapper/actionstrip.js
@@ -3,6 +3,7 @@ import {Clipboard, View} from 'react-native';
import Animated, {useValue} from 'react-native-reanimated';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useMenuStore, useNotebookStore, useSelectionStore } from '../../provider/stores';
import {openVault, ToastEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {dWidth, getElevation, toTXT} from '../../utils';
@@ -15,7 +16,13 @@ import {TEMPLATE_PERMANANT_DELETE} from '../DialogManager/Templates';
export const ActionStrip = ({note, setActionStrip}) => {
const [state, dispatch] = useTracked();
- const {colors, selectionMode} = state;
+ const {colors} = state;
+ const selectionMode = useSelectionStore(state => state.selectionMode);
+ const setNotebooks = useNotebookStore(state => state.setNotebooks);
+ const setMenuPins = useMenuStore(state => state.setMenuPins);
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
+ const setSelectionMode = useSelectionStore(state => state.setSelectionMode);
+
const [isPinnedToMenu, setIsPinnedToMenu] = useState(false);
const [width, setWidth] = useState(dWidth - 16);
const opacity = useValue(0);
@@ -67,7 +74,7 @@ export const ActionStrip = ({note, setActionStrip}) => {
return;
}
await db.notebooks.notebook(note.id).pin();
- dispatch({type: Actions.NOTEBOOKS});
+ setNotebooks();
}
updateNotes();
setActionStrip(false);
@@ -118,7 +125,7 @@ export const ActionStrip = ({note, setActionStrip}) => {
});
}
setIsPinnedToMenu(db.settings.isPinned(note.id));
- dispatch({type: Actions.MENU_PINS});
+ setMenuPins()
setActionStrip(false);
} catch (e) {}
@@ -229,9 +236,9 @@ export const ActionStrip = ({note, setActionStrip}) => {
tooltipText="Select Item"
onPress={event => {
if (!selectionMode) {
- dispatch({type: Actions.SELECTION_MODE, enabled: true});
+ setSelectionMode(true);
}
- dispatch({type: Actions.SELECTED_ITEMS, item: note});
+ setSelectedItem(item);
setActionStrip(false);
}}
style={{
diff --git a/apps/mobile/src/components/SelectionWrapper/backfill.js b/apps/mobile/src/components/SelectionWrapper/backfill.js
index cc4709ba1..017b4a028 100644
--- a/apps/mobile/src/components/SelectionWrapper/backfill.js
+++ b/apps/mobile/src/components/SelectionWrapper/backfill.js
@@ -2,13 +2,17 @@ import React from 'react';
import {View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
+import { useEditorStore } from '../../provider/stores';
import {hexToRGBA} from '../../utils/ColorUtils';
import {SIZE} from '../../utils/SizeUtils';
import Heading from '../Typography/Heading';
export const Filler = ({item, background}) => {
const [state] = useTracked();
- const {colors, currentEditingNote} = state;
+ const {colors} = state;
+
+ const currentEditingNote = useEditorStore(state => state.currentEditingNote);
+
const color = item.color || 'accent';
return (
diff --git a/apps/mobile/src/components/SelectionWrapper/selection.js b/apps/mobile/src/components/SelectionWrapper/selection.js
index 46d3a4db2..30b241129 100644
--- a/apps/mobile/src/components/SelectionWrapper/selection.js
+++ b/apps/mobile/src/components/SelectionWrapper/selection.js
@@ -3,11 +3,16 @@ import {TouchableOpacity, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useSelectionStore } from '../../provider/stores';
import {SIZE} from '../../utils/SizeUtils';
export const SelectionIcon = ({setActionStrip, item}) => {
const [state, dispatch] = useTracked();
- const {colors, selectionMode, selectedItemsList} = state;
+ const {colors} = state;
+
+ const selectionMode = useSelectionStore(state => state.selectionMode);
+ const selectedItemsList = useSelectionStore(state => state.selectedItemsList);
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
const [selected, setSelected] = useState(false);
@@ -31,10 +36,7 @@ export const SelectionIcon = ({setActionStrip, item}) => {
}, [selectedItemsList, item.id]);
onPress = () => {
- dispatch({
- type: Actions.SELECTED_ITEMS,
- item: item,
- });
+ setSelectedItem(item);
};
return (
diff --git a/apps/mobile/src/components/SimpleList/announcement.js b/apps/mobile/src/components/SimpleList/announcement.js
index 820cd798a..a6a2f6d7a 100644
--- a/apps/mobile/src/components/SimpleList/announcement.js
+++ b/apps/mobile/src/components/SimpleList/announcement.js
@@ -1,6 +1,7 @@
import React from 'react';
import { View } from 'react-native';
import { useTracked } from '../../provider';
+import { useSelectionStore } from '../../provider/stores';
import { eSendEvent } from '../../services/EventManager';
import { eOpenPremiumDialog } from '../../utils/Events';
import { openLinkInBrowser } from '../../utils/functions';
@@ -13,7 +14,8 @@ import Paragraph from '../Typography/Paragraph';
export const Announcement = ({announcement,remove}) => {
const [state] = useTracked();
const colors = state.colors;
- const {selectionMode} = state;
+
+ const selectionMode = useSelectionStore(state => state.selectionMode);
return !announcement || selectionMode ? null : (
<View
diff --git a/apps/mobile/src/components/SimpleList/card.js b/apps/mobile/src/components/SimpleList/card.js
index e18cfe8b8..617953c53 100644
--- a/apps/mobile/src/components/SimpleList/card.js
+++ b/apps/mobile/src/components/SimpleList/card.js
@@ -1,16 +1,16 @@
import React from 'react';
-import {TouchableOpacity, View} from 'react-native';
+import { TouchableOpacity, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {notesnook} from '../../../e2e/test.ids';
-import {useTracked} from '../../provider';
-import {DDS} from '../../services/DeviceDetection';
-import {getElevation} from '../../utils';
-import {SIZE} from '../../utils/SizeUtils';
+import { notesnook } from '../../../e2e/test.ids';
+import { useMessageStore, useSelectionStore } from '../../provider/stores';
+import { DDS } from '../../services/DeviceDetection';
+import { getElevation } from '../../utils';
+import { SIZE } from '../../utils/SizeUtils';
import Paragraph from '../Typography/Paragraph';
-export const Card = ({color, announcement}) => {
- const [state] = useTracked();
- const {selectionMode, messageBoardState} = state;
+export const Card = ({color, announcement}) => {;
+ const selectionMode = useSelectionStore(state => state.selectionMode);
+ const messageBoardState = useMessageStore(state => state.message);
return !messageBoardState.visible || selectionMode || announcement ? null : (
<TouchableOpacity
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index db2923f67..190f36573 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -3,8 +3,13 @@ import {FlatList} from 'react-native';
import {RefreshControl, useWindowDimensions} from 'react-native';
import {DataProvider, LayoutProvider, RecyclerListView} from 'recyclerlistview';
import {useTracked} from '../../provider';
+import {useMessageStore, useSettingStore} from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
-import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
+import {
+ eSendEvent,
+ eSubscribeEvent,
+ eUnSubscribeEvent,
+} from '../../services/EventManager';
import SettingsService from '../../services/SettingsService';
import Sync from '../../services/Sync';
import {dHeight, dWidth} from '../../utils';
@@ -23,277 +28,6 @@ import {Footer} from './footer';
import {Header} from './header';
import {SectionHeader} from './section-header';
-const header = {
- type: 'MAIN_HEADER',
-};
-
-const empty = {
- type: 'empty_loading',
-};
-const empty_not = {
- type: 'empty_not_loading',
-};
-
-const SimpleList1 = ({
- listData,
- type,
- customRefresh,
- customRefreshing,
- refreshCallback,
- sortMenuButton,
- jumpToDialog,
- placeholderData,
- loading,
- headerProps = {
- heading: 'Home',
- },
- screen,
-}) => {
- const [state] = useTracked();
- const {colors, deviceMode, messageBoardState} = state;
- const [_loading, _setLoading] = useState(false);
- const [dataProvider, setDataProvider] = useState(
- new DataProvider((r1, r2) => {
- return r1 !== r2;
- }),
- );
- const [width, setWidth] = useState(dWidth);
- const scrollRef = useRef();
- const {fontScale} = useWindowDimensions();
- const refreshing = false;
- const dataType = type;
- const [announcement, remove] = useAnnouncement();
-
- useEffect(() => {
- if (!loading) {
- if (
- !dataProvider.getDataForIndex(1) ||
- dataProvider.getDataForIndex(1).type.includes('empty')
- ) {
- setDataProvider(
- dataProvider.cloneWithRows(
- !listData || listData.length === 0
- ? [header, empty_not]
- : [header].concat(
- listData.length > 1 &&
- SettingsService.get().homepage !== screen
- ? listData.slice(0, 1)
- : listData,
- ),
- ),
- );
- }
-
- if (
- !listData ||
- listData.length === 0 ||
- SettingsService.get().homepage === screen
- )
- return;
- setTimeout(() => {
- setDataProvider(dataProvider.cloneWithRows([header].concat(listData)));
- }, 150);
- } else {
- setDataProvider(dataProvider.cloneWithRows([header, empty]));
- }
- }, [listData, loading, announcement]);
-
- useEffect(() => {
- setWidth(dWidth);
- }, [deviceMode]);
-
- const _onRefresh = async () => {
- await Sync.run();
- if (refreshCallback) {
- refreshCallback();
- }
- };
-
- const _onScroll = React.useCallback(
- event => {
- if (!event) return;
- let y = event.nativeEvent.contentOffset.y;
- eSendEvent(eScrollEvent, {
- y,
- screen,
- });
- },
- [screen],
- );
-
- const _layoutProvider = new LayoutProvider(
- index => {
- return dataProvider.getDataForIndex(index)?.type || 'note';
- },
- (type, dim) => {
- switch (type) {
- case 'note':
- dim.width = width;
- dim.height = 100 * fontScale;
- break;
- case 'notebook':
- dim.width = width;
- dim.height = 110 * fontScale;
- break;
- case 'trash':
- dim.width = width;
- dim.height = 110 * fontScale;
- break;
- case 'empty':
- dim.width = width;
- dim.height = dHeight - 250 - 35;
- break;
- case 'topic':
- dim.width = width;
- dim.height = 80 * fontScale;
- break;
- case 'tag':
- dim.width = width;
- dim.height = 80 * fontScale;
- break;
- case 'header':
- dim.width = width;
- dim.height = 40 * fontScale;
- break;
- case 'MAIN_HEADER':
- dim.width = width;
- dim.height =
- dataType === 'search'
- ? 0
- : DDS.isLargeTablet() || announcement
- ? messageBoardState.visible && !announcement
- ? 50
- : 0
- : 195;
- break;
- default:
- dim.width = width;
- dim.height = 0;
- }
- },
- );
- _layoutProvider.shouldRefreshWithAnchoring = false;
-
- const _renderRow = (type, data, index) => {
- switch (type) {
- case 'note':
- return <NoteWrapper item={data} index={index} />;
- case 'notebook':
- case 'topic':
- return <NotebookWrapper item={data} index={index} />;
- case 'tag':
- return <TagItem item={data} index={index} />;
- case 'trash':
- return data.itemType === 'note' ? (
- <NoteWrapper item={data} index={index} />
- ) : (
- <NotebookWrapper item={data} index={index} />
- );
- case 'MAIN_HEADER':
- return (
- <Header
- title={headerProps.heading}
- paragraph={headerProps.paragraph}
- onPress={headerProps.onPress}
- icon={headerProps.icon}
- type={dataType}
- announcement={announcement}
- index={index}
- screen={screen}
- />
- );
- case 'header':
- return (
- <SectionHeader
- item={data}
- index={index}
- headerProps={headerProps}
- jumpToDialog={jumpToDialog}
- sortMenuButton={sortMenuButton}
- />
- );
- case 'empty_not_loading':
- return (
- <Empty
- loading={false}
- placeholderData={placeholderData}
- headerProps={headerProps}
- />
- );
- case 'empty_loading':
- return (
- <Empty
- loading={true}
- placeholderData={placeholderData}
- headerProps={headerProps}
- />
- );
- }
- };
-
- let scrollProps = React.useMemo(() => {
- return {
- refreshControl: (
- <RefreshControl
- style={{
- opacity: 0,
- elevation: 0,
- }}
- tintColor={colors.accent}
- colors={[colors.accent]}
- progressViewOffset={150}
- onRefresh={customRefresh ? customRefresh : _onRefresh}
- refreshing={customRefresh ? customRefreshing : refreshing}
- />
- ),
-
- overScrollMode: 'always',
- contentContainerStyle: {
- width: '100%',
- alignSelf: 'center',
- minHeight: '100%',
- },
- testID: 'list-' + type,
- };
- }, [colors.accent, type, customRefresh]);
-
- let styles = {
- height: '100%',
- backgroundColor: colors.bg,
- width: '100%',
- minHeight: 1,
- minWidth: 1,
- };
-
- const renderFooter = () => (listData.length === 0 ? null : <Footer />);
-
- return (
- <>
- {!loading && (
- <Announcement
- announcement={announcement}
- remove={remove}
- color={
- COLORS_NOTE[headerProps.heading?.toLowerCase()] || colors.accent
- }
- />
- )}
- <RecyclerListView
- ref={scrollRef}
- layoutProvider={_layoutProvider}
- dataProvider={dataProvider}
- rowRenderer={_renderRow}
- renderAheadOffset={0}
- onScroll={_onScroll}
- renderFooter={renderFooter}
- scrollViewProps={scrollProps}
- style={styles}
- />
- <JumpToDialog scrollRef={scrollRef} />
- </>
- );
-};
-
const heights = {
note: 100,
notebook: 110,
@@ -335,36 +69,19 @@ const SimpleList = ({
}) => {
const [state] = useTracked();
const {colors} = state;
+
const [dataProvider, setDataProvider] = useState([]);
const scrollRef = useRef();
const [announcement, remove] = useAnnouncement();
- const [_loading,_setLoading] = useState(true);
+ const [_loading, _setLoading] = useState(true);
const RenderItem = renderItems[type];
const refreshing = false;
-
-
- const updateList = (item) => {
- let index = dataProvider.findIndex(i => i.id === item.id);
- if (index !== -1) {
- setDataProvider(prev => {
- prev[index] = item;
- return prev.slice()
- });
- }
- }
-
- useEffect(() => {
- eSubscribeEvent("onListUpdate",updateList)
- return () => {
- eUnSubscribeEvent("onListUpdate",updateList)
- }
- },[]);
useEffect(() => {
if (!_loading) {
setDataProvider(listData);
}
- },[listData])
+ }, [listData]);
useEffect(() => {
if (!loading) {
@@ -373,7 +90,7 @@ const SimpleList = ({
? listData.slice(0, 1)
: listData,
);
-
+
if (
!listData ||
listData.length === 0 ||
@@ -381,7 +98,7 @@ const SimpleList = ({
) {
setTimeout(() => {
_setLoading(false);
- },1);
+ }, 1);
return;
}
setTimeout(() => {
diff --git a/apps/mobile/src/components/SortDialog/index.js b/apps/mobile/src/components/SortDialog/index.js
index c169441c8..9d9e0571f 100644
--- a/apps/mobile/src/components/SortDialog/index.js
+++ b/apps/mobile/src/components/SortDialog/index.js
@@ -4,6 +4,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {notesnook} from '../../../e2e/test.ids';
import {Actions} from '../../provider/Actions';
import {defaultState} from '../../provider/DefaultState';
+import { useNoteStore } from '../../provider/stores';
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import SettingsService from '../../services/SettingsService';
import {getElevation, SORT, sortSettings} from '../../utils';
@@ -23,7 +24,21 @@ class SortDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
- settings: defaultState.settings,
+ settings: {
+ showToolbarOnTop: false,
+ showKeyboardOnOpen: false,
+ fontScale: 1,
+ forcePortraitOnTablet: false,
+ useSystemTheme: false,
+ reminder: 'off',
+ encryptedBackup: false,
+ homepage: 'Notes',
+ sort: 'default',
+ sortOrder: 'desc',
+ screenshotMode: true,
+ privacyScreen: false,
+ appLockMode: 'none', //none or // background // launch
+ },
visible: false,
};
}
@@ -104,7 +119,7 @@ class SortDialog extends React.Component {
await SettingsService.set('sortOrder', value);
sortSettings.sortOrder = value;
await this.getSettings();
- updateEvent({type: Actions.NOTES});
+ useNoteStore.getState().setNotes();
}}
activeOpacity={1}
style={{
@@ -148,7 +163,7 @@ class SortDialog extends React.Component {
await SettingsService.set('sort', item);
await this.getSettings();
sortSettings.sort = item;
- updateEvent({type: Actions.NOTES});
+ useNoteStore.getState().setNotes();
}}
type="transparent"
customStyle={{
diff --git a/apps/mobile/src/navigation/Drawer.js b/apps/mobile/src/navigation/Drawer.js
index 66767987a..93c282c52 100644
--- a/apps/mobile/src/navigation/Drawer.js
+++ b/apps/mobile/src/navigation/Drawer.js
@@ -4,6 +4,7 @@ import * as React from 'react';
import { State } from 'react-native-gesture-handler';
import { Menu } from '../components/Menu';
import { useTracked } from '../provider';
+import { useSettingStore } from '../provider/stores';
import { eSubscribeEvent, eUnSubscribeEvent } from '../services/EventManager';
import { eCloseSideMenu, eOpenSideMenu } from '../utils/Events';
import { sideMenuRef, tabBarRef } from '../utils/Refs';
@@ -32,8 +33,7 @@ const onNavigatorStateChange = e => {
};
export const NavigationStack = ({component = NavigatorStack}) => {
- const [state] = useTracked();
- const {deviceMode} = state;
+ const deviceMode = useSettingStore(state => state.deviceMode);
const [locked, setLocked] = React.useState(false);
const setGestureDisabled = () => {
diff --git a/apps/mobile/src/navigation/NavigatorStack.js b/apps/mobile/src/navigation/NavigatorStack.js
index 018a0cca9..c1416b974 100644
--- a/apps/mobile/src/navigation/NavigatorStack.js
+++ b/apps/mobile/src/navigation/NavigatorStack.js
@@ -5,6 +5,7 @@ import {createNativeStackNavigator} from 'react-native-screens/native-stack';
import Container from '../components/Container';
import {useTracked} from '../provider';
import {Actions} from '../provider/Actions';
+import { useSelectionStore } from '../provider/stores';
import {
eSendEvent,
eSubscribeEvent,
@@ -81,10 +82,10 @@ export const NavigatorStack = React.memo(
() => {
const [, dispatch] = useTracked();
const [render, setRender] = React.useState(true);
+ const clearSelection = useSelectionStore(state => state.clearSelection);
const onStateChange = React.useCallback(() => {
if (history.selectionMode) {
- dispatch({type: Actions.SELECTION_MODE, enabled: false});
- dispatch({type: Actions.CLEAR_SELECTION});
+ clearSelection();
}
eSendEvent('navigate');
});
diff --git a/apps/mobile/src/provider/DefaultState.js b/apps/mobile/src/provider/DefaultState.js
index 5aa54933c..1539245c1 100644
--- a/apps/mobile/src/provider/DefaultState.js
+++ b/apps/mobile/src/provider/DefaultState.js
@@ -1,4 +1,23 @@
export const defaultState = {
+ colors: {
+ night: false,
+ bg: 'white',
+ fg: '#00c853',
+ navbg: '#f6fbfc',
+ nav: '#f0f0f0',
+ pri: 'black',
+ sec: 'white',
+ accent: '#00c853',
+ shade: '#00c85312',
+ normal: 'black',
+ icon: 'gray',
+ errorBg: '#FFD2D2',
+ errorText: '#D8000C',
+ successBg: '#DFF2BF',
+ successText: '#4F8A10',
+ warningBg: '#FEEFB3',
+ warningText: '#9F6000',
+ }
// selectionMode: false,
// selectedItemsList: [],
// notes: [],
@@ -29,25 +48,7 @@ export const defaultState = {
}, */
//deviceMode: null,
- colors: {
- night: false,
- bg: 'white',
- fg: '#00c853',
- navbg: '#f6fbfc',
- nav: '#f0f0f0',
- pri: 'black',
- sec: 'white',
- accent: '#00c853',
- shade: '#00c85312',
- normal: 'black',
- icon: 'gray',
- errorBg: '#FFD2D2',
- errorText: '#D8000C',
- successBg: '#DFF2BF',
- successText: '#4F8A10',
- warningBg: '#FEEFB3',
- warningText: '#9F6000',
- },
+
// currentEditingNote: null,
//loading: true,
// searchResults: [],
diff --git a/apps/mobile/src/provider/Reducer.js b/apps/mobile/src/provider/Reducer.js
index 90b295a0a..09a92c1af 100644
--- a/apps/mobile/src/provider/Reducer.js
+++ b/apps/mobile/src/provider/Reducer.js
@@ -9,6 +9,7 @@ export const reducer = (state, action) => {
};
}
default:
- throw new Error('unknown action type');
+ return state
+ //throw new Error('unknown action type');
}
};
diff --git a/apps/mobile/src/provider/index.js b/apps/mobile/src/provider/index.js
index 5b814707c..67f478be9 100644
--- a/apps/mobile/src/provider/index.js
+++ b/apps/mobile/src/provider/index.js
@@ -1,234 +1,9 @@
-import {useReducer} from 'react';
-import {createContainer} from 'react-tracked';
-import {reducer} from './Reducer';
-import {defaultState} from './DefaultState';
-import {db} from '../utils/DB';
-import {history, SORT, sortSettings} from '../utils';
-import create from 'zustand';
-import {eOpenSideMenu} from '../utils/Events';
-import {eSendEvent} from '../services/EventManager';
+import { useReducer } from 'react';
+import { createContainer } from 'react-tracked';
+import { defaultState } from './DefaultState';
+import { reducer } from './Reducer';
const useValue = () => useReducer(reducer, defaultState);
-
export const {Provider, useTracked, useTrackedState} = createContainer(
useValue,
-);
-
-/**
- * create(set => ({
- bears: 0,
- increasePopulation: () => set(state => ({ bears: state.bears + 1 })),
- removeAllBears: () => set({ bears: 0 })
-}))
- */
-
-export const useNoteStore = create((set, get) => ({
- notes: [],
- loading: true,
- setLoading: loading => set({loading: loading}),
- setNotes: items => {
- if (!items) {
- set({
- notes: db.notes.group(SORT[sortSettings.sort], sortSettings.sortOrder),
- });
- return;
- }
- let prev = get().notes;
- for (var i = 0; i < items.length; i++) {
- let item = items[i];
- let index = prev.findIndex(v => v.id === item.id);
- if (index !== -1) {
- prev[index] = item;
- }
- }
- set({notes: prev});
- },
- clearNotes: () => set({notes: []}),
-}));
-
-export const useNotebookStore = create((set, get) => ({
- notebooks: [],
- setNotebooks: items => {
- if (!items) {
- set({
- notebooks: db.notebooks.all,
- });
- return;
- }
- let prev = get().notebooks;
- for (var i = 0; i < items.length; i++) {
- let item = items[i];
- let index = prev.findIndex(v => v.id === item.id);
- if (index !== -1) {
- prev[index] = item;
- }
- }
- set({notebooks: prev});
- },
- clearNotebooks: () => set({notebooks: []}),
-}));
-
-export const useFavoriteStore = create((set, get) => ({
- favorites: [],
- setFavorites: items => {
- if (!items) {
- set({
- favorites: db.notes.favorites,
- });
- return;
- }
- let prev = get().favorites;
- for (var i = 0; i < items.length; i++) {
- let item = items[i];
- let index = prev.findIndex(v => v.id === item.id);
- if (index !== -1) {
- prev[index] = item;
- }
- }
- set({favorites: prev});
- },
- clearFavorites: () => set({favorites: []}),
-}));
-
-export const useTagStore = create((set, get) => ({
- tags: [],
- setTags: items => {
- if (!items) {
- set({
- tags: db.tags.all,
- });
- return;
- }
- let prev = get().tags;
- for (var i = 0; i < items.length; i++) {
- let item = items[i];
- let index = prev.findIndex(v => v.id === item.id);
- if (index !== -1) {
- prev[index] = item;
- }
- }
- set({tags: prev});
- },
- clearTags: () => set({tags: []}),
-}));
-
-export const useTrashStore = create((set, get) => ({
- trash: [],
- setTrash: items => {
- if (!items) {
- set({
- trash: db.trash.all,
- });
- return;
- }
- let prev = get().trash;
- for (var i = 0; i < items.length; i++) {
- let item = items[i];
- let index = prev.findIndex(v => v.id === item.id);
- if (index !== -1) {
- prev[index] = item;
- }
- }
- set({trash: prev});
- },
- clearTrash: () => set({trash: []}),
-}));
-
-export const useUserStore = create((set, get) => ({
- user: null,
- premium: false,
- lastSynced: 'Never',
- syncing: false,
- setUser: user => set({user: user}),
- setPremium: premium => set({premium: premium}),
- setSyncing: syncing => set({syncing: syncing}),
- setLastSynced: lastSynced => set({lastSynced: lastSynced}),
-}));
-
-export const useSettingStore = create((set, get) => ({
- settings: {
- showToolbarOnTop: false,
- showKeyboardOnOpen: false,
- fontScale: 1,
- forcePortraitOnTablet: false,
- useSystemTheme: false,
- reminder: 'off',
- encryptedBackup: false,
- homepage: 'Notes',
- sort: 'default',
- sortOrder: 'desc',
- screenshotMode: true,
- privacyScreen: false,
- appLockMode: 'none',
- },
- fullscreen: false,
- deviceMode: null,
-}));
-
-export const useMenuStore = create((set, get) => ({
- menuPins: [],
- colorNotes: [],
- setMenuPins: () => set({menuPins: db.settings.pins}),
- setColorNotes: () => set({colorNotes: db.colors.all}),
-}));
-
-export const useEditorStore = create((set, get) => ({
- currentEditingNote: null,
- setCurrentlyEditingNote: note => set({currentEditingNote: note}),
-}));
-
-export const useSearchStore = create((set, get) => ({
- searchResults: [],
- searching: false,
- searchStatus: null,
- setSearchResults: results => set({searchResults: results}),
- setSearchStatus: ({searching, status}) =>
- set({searching, searchStatus: status}),
-}));
-
-export const useSelectionStore = create((set, get) => ({
- selectedItemsList: [],
- selectionMode: false,
- setAll: all => {
- history.selectedItemsList = all;
- set({selectedItemsList: all});
- },
- setSelectionMode: mode => set({selectionMode: mode}),
- setSelectedItem: item => {
- let selectedItems = get().selectedItemsList;
- let index = selectedItems.findIndex(i => i.id === item.id);
- if (index !== -1) {
- selectedItems.splice(index, 1);
- } else {
- selectedItems.push(item);
- }
- selectedItems = [...new Set(selectedItems)];
- history.selectedItemsList = selectedItems;
- if (selectedItems.length === 0) {
- eSendEvent(eOpenSideMenu);
- }
- history.selectionMode =
- selectedItems.length > 0 ? state.selectionMode : false;
-
- set({
- selectedItemsList: selectedItems,
- selectionMode: history.selectionMode,
- });
- },
- clearSelection: () => {
- eSendEvent(eOpenSideMenu);
- set({selectionMode: false, selectedItemsList: []});
- },
-}));
-
-export const useMessageStore = create((set, get) => ({
- message: {
- visible: false,
- message: null,
- actionText: null,
- onPress: () => {},
- data: {},
- icon: 'account-outline',
- },
- setMessage: message => set({message}),
-}));
+);
\ No newline at end of file
diff --git a/apps/mobile/src/provider/interfaces.ts b/apps/mobile/src/provider/interfaces.ts
index d07327571..485b5b6cf 100644
--- a/apps/mobile/src/provider/interfaces.ts
+++ b/apps/mobile/src/provider/interfaces.ts
@@ -9,13 +9,13 @@ export interface NoteStore extends State {
notes: Item[],
loading: boolean,
setLoading: (loading: boolean) => void,
- setNotes: (items: Item[]) => void,
+ setNotes: (items?: Item[]) => void,
clearNotes: () => void
}
export interface NotebookStore extends State {
notebooks: Item[],
- setNotebooks: (items: Item[]) => void,
+ setNotebooks: (items?: Item[]) => void,
clearNotebooks: () => void
}
@@ -23,7 +23,7 @@ export interface NotebookStore extends State {
export interface FavoriteStore extends State {
favorites: Item[],
- setFavorites: (items: Item[]) => void,
+ setFavorites: (items?: Item[]) => void,
clearFavorites: () => void
}
@@ -31,14 +31,14 @@ export interface FavoriteStore extends State {
export interface TagStore extends State {
tags: Item[],
- setTags: (items: Item[]) => void,
+ setTags: (items?: Item[]) => void,
clearTags: () => void
}
export interface TrashStore extends State {
trash: Item[],
- setTrash: (items: Item[]) => void,
+ setTrash: (items?: Item[]) => void,
clearTrash: () => void
}
diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.ts
index 1fcc330fb..e039c9726 100644
--- a/apps/mobile/src/provider/stores.ts
+++ b/apps/mobile/src/provider/stores.ts
@@ -19,6 +19,7 @@ import {
UserStore,
} from './interfaces';
+
export const useNoteStore = create<NoteStore>((set, get) => ({
notes: [],
loading: true,
@@ -232,3 +233,20 @@ export const useMessageStore = create<MessageStore>((set, get) => ({
},
setMessage: message => set({message}),
}));
+
+export function initialize() {
+ useMenuStore.getState().setColorNotes();
+ useMenuStore.getState().setMenuPins();
+ useNotebookStore.getState().setNotebooks();
+ useTagStore.getState().setTags();
+ useFavoriteStore.getState().setFavorites();
+ useNoteStore.getState().setNotes();
+}
+
+export function clearAllStores() {
+ useNotebookStore.getState().clearNotebooks();
+ useTagStore.getState().clearTags();
+ useFavoriteStore.getState().clearFavorites();
+ useNoteStore.getState().clearNotes();
+}
+
diff --git a/apps/mobile/src/services/Message.js b/apps/mobile/src/services/Message.js
index fc2d321df..6f1d6f9d5 100644
--- a/apps/mobile/src/services/Message.js
+++ b/apps/mobile/src/services/Message.js
@@ -1,52 +1,60 @@
import { Actions } from '../provider/Actions';
+import { useMessageStore } from '../provider/stores';
import { eOpenLoginDialog } from '../utils/Events';
import { eSendEvent } from './EventManager';
import PremiumService from './PremiumService';
-export function setLoginMessage(dispatch) {
- dispatch({
- type: Actions.MESSAGE_BOARD_STATE,
- state: {
- visible: true,
- message: 'You are not logged in',
- actionText: 'Login to encrypt and sync notes.',
- onPress: () => {
- eSendEvent(eOpenLoginDialog);
- },
- data: {},
- icon: 'account-outline',
- type: 'normal',
+const loginMessage = {
+ type: Actions.MESSAGE_BOARD_STATE,
+ state: {
+ visible: true,
+ message: 'You are not logged in',
+ actionText: 'Login to encrypt and sync notes.',
+ onPress: () => {
+ eSendEvent(eOpenLoginDialog);
},
- });
+ data: {},
+ icon: 'account-outline',
+ type: 'normal',
+ }
}
-export function setEmailVerifyMessage(dispatch) {
- dispatch({
- type: Actions.MESSAGE_BOARD_STATE,
- state: {
- visible: true,
- message: 'Email not confirmed',
- actionText: 'Please confrim your email to encrypt and sync notes.',
- onPress: () => {
- PremiumService.showVerifyEmailDialog();
- },
- data: {},
- icon: 'alert',
- type: 'error',
- },
- });
+export function setLoginMessage() {
+ useMessageStore.getState().setMessage(loginMessage)
+
}
-export function clearMessage(dispatch) {
- dispatch({
- type: Actions.MESSAGE_BOARD_STATE,
- state: {
- visible: false,
- message: '',
- actionText: '',
- onPress: null,
- data: {},
- icon: 'account-outline',
+const emailMessage = {
+ type: Actions.MESSAGE_BOARD_STATE,
+ state: {
+ visible: true,
+ message: 'Email not confirmed',
+ actionText: 'Please confrim your email to encrypt and sync notes.',
+ onPress: () => {
+ PremiumService.showVerifyEmailDialog();
},
- });
+ data: {},
+ icon: 'alert',
+ type: 'error',
+ },
+}
+
+export function setEmailVerifyMessage() {
+ useMessageStore.getState().setMessage(emailMessage)
+}
+
+const noMessage = {
+ type: Actions.MESSAGE_BOARD_STATE,
+ state: {
+ visible: false,
+ message: '',
+ actionText: '',
+ onPress: null,
+ data: {},
+ icon: 'account-outline',
+ },
+}
+
+export function clearMessage() {
+ useMessageStore.getState().setMessage(noMessage)
}
diff --git a/apps/mobile/src/services/Navigation.js b/apps/mobile/src/services/Navigation.js
index 7f8da0bdb..e1060f2ac 100755
--- a/apps/mobile/src/services/Navigation.js
+++ b/apps/mobile/src/services/Navigation.js
@@ -1,6 +1,7 @@
import {DrawerActions, StackActions} from '@react-navigation/native';
import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
+import { useFavoriteStore, useNotebookStore, useNoteStore, useTagStore, useTrashStore } from '../provider/stores';
import {eOnNewTopicAdded, refreshNotesPage} from '../utils/Events';
import {rootNavigatorRef, sideMenuRef, tabBarRef} from '../utils/Refs';
import {eSendEvent} from './EventManager';
@@ -77,7 +78,17 @@ function setRoutesToUpdate(routes) {
: eOnNewTopicAdded,
);
} else {
- updateEvent({type: Actions[currentScreen.toUpperCase()]});
+ if (currentScreen === routeNames.Notes) {
+ useNoteStore.getState().setNotes()
+ } else if (currentScreen === routeNames.Notebooks) {
+ useNotebookStore.getState().setNotebooks();
+ } else if (currentScreen === routeNames.Favorites) {
+ useFavoriteStore.getState().setFavorites();
+ } else if (currentScreen === routeNames.Tags) {
+ useTagStore.getState().setTags();
+ } else if (currentScreen === routeNames.Trash) {
+ useTrashStore.getState().setTrash();
+ }
}
clearRouteFromUpdates(currentScreen);
routes.splice(routes.indexOf(currentScreen), 1);
diff --git a/apps/mobile/src/services/PremiumService.js b/apps/mobile/src/services/PremiumService.js
index 766d4461f..493d8a839 100644
--- a/apps/mobile/src/services/PremiumService.js
+++ b/apps/mobile/src/services/PremiumService.js
@@ -1,16 +1,15 @@
-import {CHECK_IDS} from 'notes-core/common';
-import {updateEvent} from '../components/DialogManager/recievers';
-import {Actions} from '../provider/Actions';
-import {db} from '../utils/DB';
+import { CHECK_IDS } from 'notes-core/common';
+import * as RNIap from 'react-native-iap';
+import { useUserStore } from '../provider/stores';
+import { itemSkus } from '../utils';
+import { db } from '../utils/DB';
import {
eOpenPremiumDialog,
eOpenProgressDialog,
- eShowGetPremium,
+ eShowGetPremium
} from '../utils/Events';
-import {MMKV} from '../utils/mmkv';
-import {eSendEvent, ToastEvent} from './EventManager';
-import * as RNIap from 'react-native-iap';
-import {itemSkus} from '../utils';
+import { MMKV } from '../utils/mmkv';
+import { eSendEvent, ToastEvent } from './EventManager';
let premiumStatus = 0;
let products = [];
@@ -21,15 +20,16 @@ function getUser() {
}
async function setPremiumStatus() {
+ let userstore = useUserStore.getState();
try {
user = await db.user.getUser();
if (!user) {
premiumStatus = null;
- updateEvent({type: Actions.PREMIUM, state: get()});
+ userstore.setPremium(get())
} else {
premiumStatus = user.subscription.type;
- updateEvent({type: Actions.PREMIUM, state: get()});
- updateEvent({type: Actions.USER, user: user});
+ userstore.setPremium(get())
+ userstore.setUser(user);
if (!get()) {
await RNIap.initConnection();
products = await RNIap.getSubscriptions(itemSkus);
diff --git a/apps/mobile/src/services/SearchService.js b/apps/mobile/src/services/SearchService.js
index 46ea51d82..073afe377 100644
--- a/apps/mobile/src/services/SearchService.js
+++ b/apps/mobile/src/services/SearchService.js
@@ -1,6 +1,5 @@
-import {updateEvent} from '../components/DialogManager/recievers';
-import {Actions} from '../provider/Actions';
-import {db} from '../utils/DB';
+import { useSearchStore } from '../provider/stores';
+import { db } from '../utils/DB';
let searchInformation = {
placeholder: 'Search in all notes',
@@ -19,21 +18,15 @@ function setTerm(term) {
}
async function search() {
+ let searchstore = useSearchStore.getState();
+
let term = keyword;
if (!term || term.length === 0) {
- updateEvent({
- type: Actions.SEARCH_RESULTS,
- results: [],
- });
+ searchstore.setSearchResults([]);
return;
}
- updateEvent({
- type: Actions.SEARCHING,
- searching: {
- isSearching: true,
- status: `Searching for "${term}" in ${searchInformation.title}`,
- },
- });
+ searchstore.setSearchStatus(true,`Searching for "${term}" in ${searchInformation.title}`)
+
let results;
if (!searchInformation.type) return;
@@ -43,31 +36,12 @@ async function search() {
);
if (!results || results.length === 0) {
- updateEvent({type: Actions.SEARCHING, searching: false});
- updateEvent({
- type: Actions.SEARCHING,
- searching: {
- isSearching: false,
- status: `No search results found for "${term}" in ${searchInformation.title}`,
- },
- });
- updateEvent({
- type: Actions.SEARCH_RESULTS,
- results: results,
- });
+ searchstore.setSearchStatus(false,`No search results found for "${term}" in ${searchInformation.title}`)
+ searchstore.setSearchResults(results);
return;
}
- updateEvent({
- type: Actions.SEARCHING,
- searching: {
- isSearching: false,
- status: null,
- },
- });
- updateEvent({
- type: Actions.SEARCH_RESULTS,
- results: results,
- });
+ searchstore.setSearchStatus(false,null)
+ searchstore.setSearchResults(results);
}
function getSearchInformation() {
diff --git a/apps/mobile/src/services/SettingsService.js b/apps/mobile/src/services/SettingsService.js
index 08b1a28c5..b097fcbdb 100644
--- a/apps/mobile/src/services/SettingsService.js
+++ b/apps/mobile/src/services/SettingsService.js
@@ -8,8 +8,23 @@ import {scale, updateSize} from '../utils/SizeUtils';
import {enabled} from 'react-native-privacy-snapshot';
import {Platform} from 'react-native';
import Navigation from './Navigation';
+import { useSettingStore } from '../provider/stores';
-let settings = defaultState.settings;
+let settings = {
+ showToolbarOnTop: false,
+ showKeyboardOnOpen: false,
+ fontScale: 1,
+ forcePortraitOnTablet: false,
+ useSystemTheme: false,
+ reminder: 'off',
+ encryptedBackup: false,
+ homepage: 'Notes',
+ sort: 'default',
+ sortOrder: 'desc',
+ screenshotMode: true,
+ privacyScreen: false,
+ appLockMode: 'none', //none or // background // launch
+};
let appLoaded = false;
@@ -25,7 +40,21 @@ async function init() {
scale.fontScale = 1;
settings = await MMKV.getItem('appSettings');
if (!settings) {
- settings = defaultState.settings;
+ settings = {
+ showToolbarOnTop: false,
+ showKeyboardOnOpen: false,
+ fontScale: 1,
+ forcePortraitOnTablet: false,
+ useSystemTheme: false,
+ reminder: 'off',
+ encryptedBackup: false,
+ homepage: 'Notes',
+ sort: 'default',
+ sortOrder: 'desc',
+ screenshotMode: true,
+ privacyScreen: false,
+ appLockMode: 'none', //none or // background // launch
+ }
await MMKV.setItem('appSettings', JSON.stringify(settings));
} else {
settings = JSON.parse(settings);
@@ -64,7 +93,7 @@ async function init() {
sortSettings.sort = settings.sort;
sortSettings.sortOrder = settings.sortOrder;
updateSize();
- updateEvent({type: Actions.SETTINGS, settings: {...settings}});
+ useSettingStore.getState().setSettings({...settings});
setTheme();
return;
}
@@ -81,7 +110,7 @@ async function set(name, value) {
settings[name] = value;
settings = {...settings};
await MMKV.setItem('appSettings', JSON.stringify(settings));
- updateEvent({type: Actions.SETTINGS, settings: settings});
+ useSettingStore.getState().setSettings({...settings});
}
function get() {
diff --git a/apps/mobile/src/services/Sync.js b/apps/mobile/src/services/Sync.js
index 83a718fe9..99f75287d 100644
--- a/apps/mobile/src/services/Sync.js
+++ b/apps/mobile/src/services/Sync.js
@@ -1,16 +1,15 @@
import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions';
+import { initialize, useUserStore } from '../provider/stores';
import {doInBackground} from '../utils';
import {db} from '../utils/DB';
import {eOpenLoginDialog} from '../utils/Events';
import {eSendEvent, ToastEvent} from './EventManager';
const run = async (context = 'global', forced) => {
- updateEvent({
- type: Actions.SYNCING,
- syncing: true,
- });
-
+
+ let userstore = useUserStore.getState()
+ userstore.setSyncing(true);
try {
let res = await doInBackground(async () => {
try {
@@ -41,10 +40,8 @@ const run = async (context = 'global', forced) => {
actionText: 'Login',
});
} else {
- updateEvent({
- type: Actions.SYNCING,
- syncing: false,
- });
+
+ userstore.setSyncing(false);
ToastEvent.show({
heading: 'Sync failed',
message: e.message,
@@ -52,15 +49,9 @@ const run = async (context = 'global', forced) => {
});
}
} finally {
- updateEvent({
- type: Actions.LAST_SYNC,
- lastSync: await db.lastSynced(),
- });
- updateEvent({type: Actions.ALL});
- updateEvent({
- type: Actions.SYNCING,
- syncing: false,
- });
+ userstore.setLastSynced(await db.lastSynced())
+ initialize();
+ userstore.setSyncing(false);
}
};
diff --git a/apps/mobile/src/utils/functions.js b/apps/mobile/src/utils/functions.js
index 33a50b3ee..b6f104f63 100644
--- a/apps/mobile/src/utils/functions.js
+++ b/apps/mobile/src/utils/functions.js
@@ -1,12 +1,11 @@
-import {Linking} from 'react-native';
-import {InAppBrowser} from 'react-native-inappbrowser-reborn';
-import {history} from '.';
-import {updateEvent} from '../components/DialogManager/recievers';
-import {Actions} from '../provider/Actions';
-import {eSendEvent, ToastEvent} from '../services/EventManager';
+import { Linking } from 'react-native';
+import { InAppBrowser } from 'react-native-inappbrowser-reborn';
+import { history } from '.';
+import { useMenuStore, useSelectionStore } from '../provider/stores';
+import { eSendEvent, ToastEvent } from '../services/EventManager';
import Navigation from '../services/Navigation';
-import {db} from './DB';
-import {eClearEditor} from './Events';
+import { db } from './DB';
+import { eClearEditor } from './Events';
export const deleteItems = async (item) => {
if (item && item.id && history.selectedItemsList.length === 0) {
@@ -38,7 +37,7 @@ export const deleteItems = async (item) => {
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notebook,
]);
- updateEvent({type: Actions.MENU_PINS});
+ useMenuStore.getState().setMenuPins();
ToastEvent.show({
heading: 'Topics deleted',
type: 'success',
@@ -52,7 +51,7 @@ export const deleteItems = async (item) => {
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
]);
- updateEvent({type: Actions.MENU_PINS});
+ useMenuStore.getState().setMenuPins();
}
let msgPart = history.selectedItemsList.length === 1 ? ' item' : ' items';
@@ -80,17 +79,16 @@ export const deleteItems = async (item) => {
Navigation.routeNames.Notebook,
Navigation.routeNames.Trash,
]);
- updateEvent({type: Actions.COLORS});
- updateEvent({type: Actions.MENU_PINS});
+ useMenuStore.getState().setMenuPins();
+ useMenuStore.getState().setColorNotes();
ToastEvent.hide();
},
actionText: 'Undo',
});
}
Navigation.setRoutesToUpdate([Navigation.routeNames.Trash]);
- updateEvent({type: Actions.CLEAR_SELECTION});
- updateEvent({type: Actions.COLORS});
- updateEvent({type: Actions.SELECTION_MODE, enabled: false});
+ useSelectionStore.getState().clearSelection();
+ useMenuStore.getState().setColorNotes();
};
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index 04afdbfea..a6f8cef5f 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -1,20 +1,18 @@
-import {createRef} from 'react';
-import {Dimensions, NativeModules, Platform} from 'react-native';
-import RNTooltips from 'react-native-tooltips';
-import {updateEvent} from '../components/DialogManager/recievers';
-import {dummyRef} from '../components/DummyText';
-import {Actions} from '../provider/Actions';
-import {defaultState} from '../provider/DefaultState';
-import {eSendEvent, ToastEvent} from '../services/EventManager';
-import {MMKV} from './mmkv';
-import {tabBarRef} from './Refs';
-import {SIZE} from './SizeUtils';
-import FastImage from 'react-native-fast-image';
+import { createRef } from 'react';
+import { Dimensions, NativeModules, Platform } from 'react-native';
import BackgroundService from 'react-native-background-actions';
import {
beginBackgroundTask,
- endBackgroundTask,
+ endBackgroundTask
} from 'react-native-begin-background-task';
+import FastImage from 'react-native-fast-image';
+import RNTooltips from 'react-native-tooltips';
+import { dummyRef } from '../components/DummyText';
+import { useSettingStore } from '../provider/stores';
+import { eSendEvent } from '../services/EventManager';
+import { MMKV } from './mmkv';
+import { tabBarRef } from './Refs';
+import { SIZE } from './SizeUtils';
const imgNames = [
'favorites',
@@ -99,7 +97,7 @@ export async function setSetting(settings, name, value) {
let s = {...settings};
s[name] = value;
await MMKV.setStringAsync('appSettings', JSON.stringify(s));
- updateEvent({type: Actions.SETTINGS, settings: s});
+ useSettingStore.getState().setSettings(s)
}
export const scrollRef = createRef();
@@ -117,7 +115,7 @@ export const getElevation = elevation => {
export const sortSettings = {
- sort: defaultState.settings.sort,
+ sort: 'default',
/**
* @type {"desc" | "asc"}
*/
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js
index 099de0bd5..887a1b23a 100644
--- a/apps/mobile/src/views/Editor/EditorHeader.js
+++ b/apps/mobile/src/views/Editor/EditorHeader.js
@@ -5,6 +5,7 @@ import { notesnook } from '../../../e2e/test.ids';
import { ActionIcon } from '../../components/ActionIcon';
import { ActionSheetEvent } from '../../components/DialogManager/recievers';
import { useTracked } from '../../provider';
+import { useSettingStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent, ToastEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
@@ -34,7 +35,9 @@ import { toolbarRef } from './tiny/toolbar/constants';
const EditorHeader = () => {
const [state] = useTracked();
- const {colors, fullscreen, deviceMode} = state;
+ const {colors} = state;
+
+ const fullscreen = useSettingStore(state => state.fullscreen);
const insets = useSafeAreaInsets();
useEffect(() => {
diff --git a/apps/mobile/src/views/Editor/EditorRoot.js b/apps/mobile/src/views/Editor/EditorRoot.js
index eec8645f7..24104375e 100644
--- a/apps/mobile/src/views/Editor/EditorRoot.js
+++ b/apps/mobile/src/views/Editor/EditorRoot.js
@@ -1,43 +1,38 @@
-import React, {useEffect} from 'react';
-import {BackHandler, InteractionManager, Keyboard} from 'react-native';
-import RNExitApp from 'react-native-exit-app';
-import {simpleDialogEvent} from '../../components/DialogManager/recievers';
-import {TEMPLATE_EXIT_FULLSCREEN} from '../../components/DialogManager/Templates';
-import {useTracked} from '../../provider';
-import {DDS} from '../../services/DeviceDetection';
+import React, { useEffect } from 'react';
+import { BackHandler, InteractionManager, Keyboard } from 'react-native';
+import { simpleDialogEvent } from '../../components/DialogManager/recievers';
+import { TEMPLATE_EXIT_FULLSCREEN } from '../../components/DialogManager/Templates';
+import { useSettingStore } from '../../provider/stores';
+import { DDS } from '../../services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
- ToastEvent,
+ ToastEvent
} from '../../services/EventManager';
-import {editing} from '../../utils';
+import { editing } from '../../utils';
import {
eClearEditor,
eCloseFullscreenEditor,
- eOnLoadNote,
+ eOnLoadNote
} from '../../utils/Events';
-import {sideMenuRef, tabBarRef} from '../../utils/Refs';
+import { tabBarRef } from '../../utils/Refs';
import {
checkNote,
clearEditor,
clearTimer,
- EditorWebView,
+
isNotedEdited,
- loadNote,
- post,
- saveNote,
- setIntent,
+ loadNote
} from './Functions';
-import tiny, { keyboardStateChanged } from './tiny/tiny';
-import {toolbarRef} from './tiny/toolbar/constants';
+import tiny from './tiny/tiny';
+import { toolbarRef } from './tiny/toolbar/constants';
let handleBack;
-let tapCount = 0;
const EditorRoot = () => {
- const [state] = useTracked();
- const {fullscreen} = state;
+ const fullscreen = useSettingStore(state => state.fullscreen);
+
useEffect(() => {
eSubscribeEvent(eOnLoadNote, load);
eSubscribeEvent(eClearEditor, onCallClear);
diff --git a/apps/mobile/src/views/Editor/EditorSettings.js b/apps/mobile/src/views/Editor/EditorSettings.js
index 26aecbbe0..12c590a68 100644
--- a/apps/mobile/src/views/Editor/EditorSettings.js
+++ b/apps/mobile/src/views/Editor/EditorSettings.js
@@ -16,10 +16,13 @@ import {sleep} from '../../utils/TimeUtils';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import Seperator from '../../components/Seperator';
import SettingsService from '../../services/SettingsService';
+import { useSettingStore } from '../../provider/stores';
export const EditorSettings = () => {
const [state,dispatch] = useTracked();
- const {colors, settings} = state;
+ const {colors} = state;
+
+ const settings = useSettingStore(state => state.settings);
const [visible, setVisible] = useState(false);
const [savePreset, setSavePreset] = useState(false);
diff --git a/apps/mobile/src/views/Editor/EditorWrapper.js b/apps/mobile/src/views/Editor/EditorWrapper.js
index e2ae81da3..dae7eedfa 100644
--- a/apps/mobile/src/views/Editor/EditorWrapper.js
+++ b/apps/mobile/src/views/Editor/EditorWrapper.js
@@ -7,6 +7,7 @@ import Editor from '.';
import {GetPremium} from '../../components/ActionSheetComponent/GetPremium';
import Paragraph from '../../components/Typography/Paragraph';
import {useTracked} from '../../provider';
+import { useNoteStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import {eOnLoadNote} from '../../utils/Events';
@@ -88,7 +89,10 @@ const AnimatedKeyboardView = Animated.createAnimatedComponent(
export const EditorWrapper = ({dimensions}) => {
const [state] = useTracked();
- const {colors, loading} = state;
+ const {colors} = state;
+
+ const loading = useNoteStore(state => state.loading);
+
const insets = useSafeAreaInsets();
const floating = useIsFloatingKeyboard();
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 5e34669f1..a3bc277f8 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -2,6 +2,7 @@ import {createRef} from 'react';
import {Platform} from 'react-native';
import {updateEvent} from '../../components/DialogManager/recievers';
import {Actions} from '../../provider/Actions';
+import {useEditorStore, useMenuStore} from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent, sendNoteEditedEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
@@ -216,7 +217,7 @@ export const loadNote = async item => {
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes,
]);
- updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: item.id});
+ useEditorStore.getState().setCurrentlyEditingNote(item.id);
checkStatus();
}, 50);
}
@@ -425,9 +426,7 @@ export async function clearEditor() {
redo: 0,
});
saveCounter = 0;
- setTimeout(() => {
- updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: null});
- }, 1);
+ useEditorStore.getState().setCurrentlyEditingNote(null);
} catch (e) {
console.log(e);
}
@@ -487,7 +486,7 @@ async function addToCollection(id) {
type: null,
};
Navigation.setRoutesToUpdate([Navigation.routeNames.NotesPage]);
- updateEvent({type: Actions.COLORS});
+ useMenuStore.getState().setColorNotes();
break;
}
default: {
@@ -526,7 +525,7 @@ export async function saveNote(preventUpdate) {
}
if (!id) {
- updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: noteId});
+ useEditorStore.getState().setCurrentlyEditingNote(noteId);
await addToCollection(noteId);
}
await setNoteInEditorAfterSaving(id, noteId);
@@ -588,7 +587,6 @@ async function restoreEditorState() {
return;
}
editing.isRestoringState = false;
-
}
export let isFromIntent = false;
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 5ca83b5f6..36215b966 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -6,6 +6,7 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context';
import WebView from 'react-native-webview';
import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
+import { useUserStore } from '../../provider/stores';
import {
eSendEvent,
eSubscribeEvent,
@@ -46,8 +47,8 @@ const style = {
const Editor = React.memo(
() => {
- const [state] = useTracked();
- const {premiumUser} = state;
+ const premiumUser = useUserStore(state => state.premium);
+
const [resetting, setResetting] = useState(false);
const onLoad = async () => {
await onWebViewLoad(premiumUser, getCurrentColors());
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 9f1b7777e..ae83bf460 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -6,6 +6,7 @@ import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useFavoriteStore, useNoteStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
@@ -14,16 +15,17 @@ import {InteractionManager} from '../../utils';
import {eScrollEvent} from '../../utils/Events';
export const Favorites = ({route, navigation}) => {
- const [state, dispatch] = useTracked();
- const favorites = state.favorites;
- const {loading} = state;
+ const favorites = useFavoriteStore(state => state.favorites);
+ const setFavorites = useFavoriteStore(state =>state.setFavorites);
+ const loading = useNoteStore(state => state.loading);
+
let pageIsLoaded = false;
let ranAfterInteractions = false;
const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
Navigation.routeNeedsUpdate('Favorites', () => {
- dispatch({type: Actions.FAVORITES});
+ setFavorites();
});
});
eSendEvent(eScrollEvent, {name: 'Favorites', type: 'in'});
@@ -90,10 +92,10 @@ export const Favorites = ({route, navigation}) => {
<Header title="Favorites" isBack={false} screen="Favorites" />
</ContainerTopSection>
<SimpleList
- listData={state.favorites}
+ listData={favorites}
type="notes"
refreshCallback={() => {
- dispatch({type: Actions.FAVORITES});
+ setFavorites();
}}
screen="Favorites"
loading={loading}
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 47b038b26..ac5071b5e 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -7,6 +7,7 @@ import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useNotebookStore } from '../../provider/stores';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
@@ -15,8 +16,8 @@ import {db} from '../../utils/DB';
import {eScrollEvent} from '../../utils/Events';
export const Folders = ({route, navigation}) => {
- const [state, dispatch] = useTracked();
- const notebooks = state.notebooks;
+ const notebooks = useNotebookStore(state => state.notebooks);
+ const setNotebooks = useNotebookStore(state => state.setNotebooks);
let ranAfterInteractions = false;
const onFocus = useCallback(() => {
@@ -39,7 +40,7 @@ export const Folders = ({route, navigation}) => {
const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
Navigation.routeNeedsUpdate('Notebooks', () => {
- dispatch({type: Actions.NOTEBOOKS});
+ setNotebooks()
});
});
eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});
@@ -66,7 +67,7 @@ export const Folders = ({route, navigation}) => {
const updateSearch = React.useCallback(() => {
SearchService.update({
placeholder: 'Type a keyword to search in notebooks',
- data: db.notebooks.all,
+ data: notebooks,
type: 'notebooks',
title: 'Notebooks',
});
@@ -86,7 +87,7 @@ export const Folders = ({route, navigation}) => {
/>
</ContainerTopSection>
<SimpleList
- listData={state.notebooks}
+ listData={notebooks}
type="notebooks"
screen="Notebooks"
focused={() => navigation.isFocused()}
@@ -102,7 +103,7 @@ export const Folders = ({route, navigation}) => {
}}
/>
- {!state.notebooks || state.notebooks.length === 0 ? null : (
+ {!notebooks || notebooks.length === 0 ? null : (
<ContainerBottomButton
title="Create a new notebook"
onPress={_onPressBottomButton}
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index a7317206e..cf56cc413 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -6,6 +6,7 @@ import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
import { useTracked } from '../../provider';
import { Actions } from '../../provider/Actions';
+import { useNoteStore } from '../../provider/stores';
import { DDS } from '../../services/DeviceDetection';
import { eSendEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
@@ -14,11 +15,13 @@ import { InteractionManager, scrollRef } from '../../utils';
import { db } from '../../utils/DB';
import { eOnLoadNote, eScrollEvent } from '../../utils/Events';
import { tabBarRef } from '../../utils/Refs';
+import Storage from '../../utils/storage';
export const Home = ({navigation}) => {
- const [state, dispatch] = useTracked();
- const {loading} = state;
- const notes = state.notes
+ const notes = useNoteStore(state => state.notes);
+ const setNotes = useNoteStore(state => state.setNotes);
+ const loading = useNoteStore(state => state.loading);
+
let ranAfterInteractions = false;
const onFocus = useCallback(() => {
@@ -47,7 +50,7 @@ export const Home = ({navigation}) => {
InteractionManager.runAfterInteractions(() => {
Navigation.routeNeedsUpdate('Notes', () => {
- dispatch({type: Actions.NOTES});
+ setNotes()
});
});
ranAfterInteractions = false;
@@ -80,6 +83,11 @@ export const Home = ({navigation}) => {
};
const _onPressBottomButton = React.useCallback(async () => {
+ let result = Storage.encrypt({
+ password:""
+ },"hello world");
+ console.log(result);
+ return;
if (!DDS.isLargeTablet()) {
eSendEvent(eOnLoadNote, {type: 'new'});
tabBarRef.current?.goToPage(1);
@@ -101,7 +109,7 @@ export const Home = ({navigation}) => {
</ContainerTopSection>
<SimpleList
- listData={state.notes.slice()}
+ listData={notes}
scrollRef={scrollRef}
type="notes"
isHome={true}
@@ -123,7 +131,7 @@ export const Home = ({navigation}) => {
}}
/>
- {!state.notes || state.notes.length === 0 ? null : (
+ {!notes || notes.length === 0 ? null : (
<ContainerBottomButton
title="Create a new note"
onPress={_onPressBottomButton}
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 8f59229c0..b199c6c4b 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -6,6 +6,7 @@ import {Header} from '../../components/Header';
import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
+import { useNoteStore } from '../../provider/stores';
import {DDS} from '../../services/DeviceDetection';
import {
eSendEvent,
@@ -25,9 +26,9 @@ import {
import {tabBarRef} from '../../utils/Refs';
export const Notes = ({route, navigation}) => {
- const [state, dispatch] = useTracked();
- const {loading} = state;
const [notes, setNotes] = useState([]);
+ const loading = useNoteStore(state =>state.loading);
+
let params = route.params ? route.params : null;
let ranAfterInteractions = false;
diff --git a/apps/mobile/src/views/Search/index.js b/apps/mobile/src/views/Search/index.js
index b9ff04122..fc444c653 100644
--- a/apps/mobile/src/views/Search/index.js
+++ b/apps/mobile/src/views/Search/index.js
@@ -5,13 +5,19 @@ import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useSearchStore } from '../../provider/stores';
import SearchService from '../../services/SearchService';
import {inputRef} from '../../utils/Refs';
import {sleep} from '../../utils/TimeUtils';
export const Search = ({route, navigation}) => {
const [state, dispatch] = useTracked();
- const {searchResults, searching, searchStatus} = state;
+
+ const searchResults = useSearchStore(state => state.searchResults);
+ const searching = useSearchStore(state => state.searching);
+ const searchStatus = useSearchStore(state => state.searchStatus);
+ const setSearchResults = useSearchStore(state => state.setSearchResults);
+ const setSearchStatus = useSearchStore(state => state.setSearchStatus)
const onFocus = useCallback(() => {
sleep(300).then(() => inputRef.current?.focus());
@@ -20,17 +26,8 @@ export const Search = ({route, navigation}) => {
useEffect(() => {
navigation.addListener('focus', onFocus);
return () => {
- dispatch({
- type: Actions.SEARCH_RESULTS,
- results: [],
- });
- dispatch({
- type: Actions.SEARCHING,
- searching: {
- isSearching: false,
- status: null,
- },
- });
+ setSearchResults([]);
+ setSearchStatus(false,null);
navigation.removeListener('focus', onFocus);
};
}, []);
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 15543c87f..79e27d833 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -28,6 +28,7 @@ import Heading from '../../components/Typography/Heading';
import Paragraph from '../../components/Typography/Paragraph';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import { useMessageStore, useSettingStore, useUserStore } from '../../provider/stores';
import Backup from '../../services/Backup';
import BiometricService from '../../services/BiometricService';
import {DDS} from '../../services/DeviceDetection';
@@ -321,7 +322,9 @@ const SectionHeader = ({title}) => {
let passwordValue = null;
const AccoutLogoutSection = () => {
const [state, dispatch] = useTracked();
- const {colors, user} = state;
+ const {colors} = state;
+
+ const user = useUserStore(state => state.user);
const [visible, setVisible] = useState(false);
const [deleteAccount, setDeleteAccount] = useState(false);
const [loading, setLoading] = useState(false);
@@ -578,7 +581,10 @@ const getTimeLeft = t2 => {
const SettingsUserSection = () => {
const [state] = useTracked();
- const {colors, user, messageBoardState} = state;
+ const {colors} = state;
+
+ const user = useUserStore(state => state.user);
+ const messageBoardState = useMessageStore(state => state.message);
const subscriptionDaysLeft =
user && getTimeLeft(parseInt(user.subscription?.expiry));
const isExpired = user && subscriptionDaysLeft.time < 0;
@@ -893,7 +899,8 @@ const SettingsUserSection = () => {
const SettingsAppearanceSection = () => {
const [state, dispatch] = useTracked();
const {colors} = state;
- const settings = {...state.settings};
+ const settings = useSettingStore(state => state.settings);
+
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
let newColors = setColorScheme(colors, accent);
dispatch({type: Actions.THEME, colors: newColors});
@@ -1127,7 +1134,9 @@ const SettingsAppearanceSection = () => {
const SettingsPrivacyAndSecurity = () => {
const [state] = useTracked();
- const {colors, settings} = state;
+ const {colors} = state;
+ const settings = useSettingStore(state => state.settings);
+
const [appLockVisible, setAppLockVisible] = useState(false);
const [vaultStatus, setVaultStatus] = React.useState({
@@ -1353,8 +1362,10 @@ const SettingsPrivacyAndSecurity = () => {
const SettingsBackupAndRestore = () => {
const [state] = useTracked();
- const {colors, settings, user} = state;
-
+ const {colors} = state;
+ const settings = useSettingStore(state => state.settings);
+ const user = useUserStore(state => state.user);
+
const backupItemsList = [
{
name: 'Backup data',
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index 70772820a..104eaf0a6 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -1,28 +1,25 @@
-import React, {useCallback, useEffect, useState} from 'react';
-import {ContainerTopSection} from '../../components/Container/ContainerTopSection';
-import {Header} from '../../components/Header';
-import {Placeholder} from '../../components/ListPlaceholders';
+import React, { useCallback, useEffect } from 'react';
+import { ContainerTopSection } from '../../components/Container/ContainerTopSection';
+import { Header } from '../../components/Header';
+import { Placeholder } from '../../components/ListPlaceholders';
import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
-import {useTracked} from '../../provider';
-import {Actions} from '../../provider/Actions';
-import {DDS} from '../../services/DeviceDetection';
-import {eSendEvent} from '../../services/EventManager';
+import { useTagStore } from '../../provider/stores';
+import { eSendEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
-import {InteractionManager} from '../../utils';
-import {eScrollEvent} from '../../utils/Events';
+import { InteractionManager } from '../../utils';
+import { eScrollEvent } from '../../utils/Events';
export const Tags = ({route, navigation}) => {
- const [state, dispatch] = useTracked();
- const tags = state.tags;
-
+ const tags = useTagStore(state => state.tags);
+ const setTags = useTagStore(state =>state.setTags);
let ranAfterInteractions = false;
const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
Navigation.routeNeedsUpdate('Tags', () => {
- dispatch({type: Actions.TAGS});
+ setTags();
});
});
eSendEvent(eScrollEvent, {name: 'Tags', type: 'in'});
@@ -78,7 +75,7 @@ export const Tags = ({route, navigation}) => {
<Header title="Tags" isBack={false} screen="Tags" />
</ContainerTopSection>
<SimpleList
- listData={state.tags}
+ listData={tags}
type="tags"
headerProps={{
heading: 'Tags',
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 51c89fe0e..f950b19e2 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -1,31 +1,30 @@
-import React, {useCallback, useEffect, useState} from 'react';
-
-import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
-import {ContainerTopSection} from '../../components/Container/ContainerTopSection';
-import {simpleDialogEvent} from '../../components/DialogManager/recievers';
-import {TEMPLATE_EMPTY_TRASH} from '../../components/DialogManager/Templates';
-import {Header} from '../../components/Header';
-import {Placeholder} from '../../components/ListPlaceholders';
+import React, { useCallback, useEffect } from 'react';
+import { ContainerBottomButton } from '../../components/Container/ContainerBottomButton';
+import { ContainerTopSection } from '../../components/Container/ContainerTopSection';
+import { simpleDialogEvent } from '../../components/DialogManager/recievers';
+import { TEMPLATE_EMPTY_TRASH } from '../../components/DialogManager/Templates';
+import { Header } from '../../components/Header';
+import { Placeholder } from '../../components/ListPlaceholders';
import SelectionHeader from '../../components/SelectionHeader';
import SimpleList from '../../components/SimpleList';
-import {useTracked} from '../../provider';
-import {Actions} from '../../provider/Actions';
-import {DDS} from '../../services/DeviceDetection';
-import {eSendEvent} from '../../services/EventManager';
+import { useTrashStore } from '../../provider/stores';
+import { eSendEvent } from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import SearchService from '../../services/SearchService';
-import {InteractionManager} from '../../utils';
-import {eScrollEvent} from '../../utils/Events';
+import { InteractionManager } from '../../utils';
+import { eScrollEvent } from '../../utils/Events';
+
export const Trash = ({route, navigation}) => {
- const [state, dispatch] = useTracked();
+ const trash = useTrashStore(state => state.trash);
+ const setTrash = useTrashStore(state => state.setTrash);
let pageIsLoaded = false;
let ranAfterInteractions = false;
const runAfterInteractions = () => {
InteractionManager.runAfterInteractions(() => {
Navigation.routeNeedsUpdate('Trash', () => {
- dispatch({type: Actions.TRASH});
+ setTrash();
});
});
@@ -73,12 +72,12 @@ export const Trash = ({route, navigation}) => {
if (navigation.isFocused()) {
updateSearch();
}
- }, [state.trash]);
+ }, [trash]);
const updateSearch = () => {
SearchService.update({
placeholder: 'Search in trash',
- data: state.trash,
+ data: trash,
type: 'trash',
title: 'Trash',
});
@@ -98,7 +97,7 @@ export const Trash = ({route, navigation}) => {
/>
</ContainerTopSection>
<SimpleList
- listData={state.trash}
+ listData={trash}
type="trash"
screen="Trash"
focused={() => navigation.isFocused()}
@@ -116,7 +115,7 @@ export const Trash = ({route, navigation}) => {
placeholderText="Deleted notes & notebooks appear here."
/>
- {state.trash && state.trash.length !== 0 && (
+ {trash && trash.length !== 0 && (
<ContainerBottomButton
title="Clear all trash"
onPress={_onPressBottomButton}