Skip to content

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

refactor

ammarahm-ed496f550a19f3
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index 386a2a9fe..717483011 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -1,38 +1,42 @@
import React, { useEffect } from 'react';
+import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import Launcher from './src/components/launcher';
import { ApplicationHolder } from './src/navigation';
import Notifications from './src/services/notifications';
import SettingsService from './src/services/settings';
import { TipManager } from './src/services/tip-manager';
-import { useUserStore } from './src/stores/stores';
+import { useUserStore } from './src/stores/use-user-store';
import { useAppEvents } from './src/utils/hooks/use-app-events';
+SettingsService.init();
SettingsService.checkOrientation();
const App = () => {
useAppEvents();
-
useEffect(() => {
- (async () => {
- try {
- SettingsService.init();
-
- let appLockMode = SettingsService.get().appLockMode;
- if (appLockMode && appLockMode !== 'none') {
- useUserStore.getState().setVerifyUser(true);
- }
- TipManager.init();
- Notifications.get();
- await SettingsService.onFirstLaunch();
- } catch (e) {}
- })();
+ let { appLockMode } = SettingsService.get();
+ if (appLockMode && appLockMode !== 'none') {
+ useUserStore.getState().setVerifyUser(true);
+ }
+ setTimeout(() => {
+ console.log('run later');
+ SettingsService.onFirstLaunch();
+ Notifications.get();
+ TipManager.init();
+ }, 100);
}, []);
return (
- <SafeAreaProvider>
- <ApplicationHolder />
- <Launcher />
- </SafeAreaProvider>
+ <GestureHandlerRootView
+ style={{
+ flex: 1
+ }}
+ >
+ <SafeAreaProvider>
+ <ApplicationHolder />
+ <Launcher />
+ </SafeAreaProvider>
+ </GestureHandlerRootView>
);
};
diff --git a/apps/mobile/index.js b/apps/mobile/index.js
index d21c33c30..2036e59ad 100644
--- a/apps/mobile/index.js
+++ b/apps/mobile/index.js
@@ -1,3 +1,4 @@
+/* eslint-disable @typescript-eslint/no-var-requires */
import React from 'react';
import { AppRegistry, LogBox, Platform, UIManager } from 'react-native';
import Config from 'react-native-config';
@@ -7,6 +8,7 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
import { enableScreens } from 'react-native-screens';
import { name as appName } from './app.json';
import Notifications from './src/services/notifications';
+
global.Buffer = require('buffer').Buffer;
enableLayoutAnimations(true);
diff --git a/apps/mobile/src/components/announcements/announcement.js b/apps/mobile/src/components/announcements/announcement.js
index ce93926cf..e2d7ff177 100644
--- a/apps/mobile/src/components/announcements/announcement.js
+++ b/apps/mobile/src/components/announcements/announcement.js
@@ -1,7 +1,8 @@
import React from 'react';
import { FlatList, View } from 'react-native';
-import { useMessageStore, useSelectionStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSelectionStore } from '../../stores/use-selection-store';
+import { useMessageStore } from '../../stores/use-message-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { allowedOnPlatform, renderItem } from './functions';
export const Announcement = ({ color }) => {
diff --git a/apps/mobile/src/components/announcements/body.js b/apps/mobile/src/components/announcements/body.js
index 0b0ac6896..eaceb2c60 100644
--- a/apps/mobile/src/components/announcements/body.js
+++ b/apps/mobile/src/components/announcements/body.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import Paragraph from '../ui/typography/paragraph';
import { getStyle } from './functions';
diff --git a/apps/mobile/src/components/announcements/cta.js b/apps/mobile/src/components/announcements/cta.js
index 5cdce2366..db40ccb54 100644
--- a/apps/mobile/src/components/announcements/cta.js
+++ b/apps/mobile/src/components/announcements/cta.js
@@ -2,7 +2,7 @@ import React from 'react';
import { Linking, View } from 'react-native';
import SettingsBackupAndRestore from '../../screens/settings/backup-restore';
import { eSendEvent, presentSheet } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eCloseAnnouncementDialog } from '../../utils/events';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
diff --git a/apps/mobile/src/components/announcements/description.js b/apps/mobile/src/components/announcements/description.js
index 3c64be336..82e799cde 100644
--- a/apps/mobile/src/components/announcements/description.js
+++ b/apps/mobile/src/components/announcements/description.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import Paragraph from '../ui/typography/paragraph';
import { getStyle } from './functions';
diff --git a/apps/mobile/src/components/announcements/functions.js b/apps/mobile/src/components/announcements/functions.js
index e549c6c2e..18de20495 100644
--- a/apps/mobile/src/components/announcements/functions.js
+++ b/apps/mobile/src/components/announcements/functions.js
@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import { View } from 'react-native';
-import { allowedPlatforms } from '../../stores/stores';
+import { allowedPlatforms } from '../../stores';
import { ProFeatures } from '../dialogs/result/pro-features';
import { Body } from './body';
import { Cta } from './cta';
diff --git a/apps/mobile/src/components/announcements/index.js b/apps/mobile/src/components/announcements/index.js
index e27972d6f..70dd72069 100644
--- a/apps/mobile/src/components/announcements/index.js
+++ b/apps/mobile/src/components/announcements/index.js
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { FlatList, View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
-import { useMessageStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useMessageStore } from '../../stores/use-message-store';
import { DDS } from '../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { eCloseAnnouncementDialog, eOpenAnnouncementDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/announcements/list.js b/apps/mobile/src/components/announcements/list.js
index 3b2a13222..2eef25059 100644
--- a/apps/mobile/src/components/announcements/list.js
+++ b/apps/mobile/src/components/announcements/list.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import Paragraph from '../ui/typography/paragraph';
import { getStyle } from './functions';
diff --git a/apps/mobile/src/components/announcements/subheading.js b/apps/mobile/src/components/announcements/subheading.js
index c44066eca..e5ff43537 100644
--- a/apps/mobile/src/components/announcements/subheading.js
+++ b/apps/mobile/src/components/announcements/subheading.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import Heading from '../ui/typography/heading';
import { getStyle } from './functions';
diff --git a/apps/mobile/src/components/announcements/title.js b/apps/mobile/src/components/announcements/title.js
index b723cfc70..5f41a7d97 100644
--- a/apps/mobile/src/components/announcements/title.js
+++ b/apps/mobile/src/components/announcements/title.js
@@ -1,6 +1,6 @@
import React from 'react';
import { View } from 'react-native';
-import { useMessageStore } from '../../stores/stores';
+import { useMessageStore } from '../../stores/use-message-store';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
import Heading from '../ui/typography/heading';
diff --git a/apps/mobile/src/components/attachments/actions.js b/apps/mobile/src/components/attachments/actions.js
index 0f7188b99..749a348ff 100644
--- a/apps/mobile/src/components/attachments/actions.js
+++ b/apps/mobile/src/components/attachments/actions.js
@@ -5,8 +5,8 @@ import { ScrollView } from 'react-native-gesture-handler';
import picker from '../../screens/editor/tiny/toolbar/picker';
import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium';
-import { useAttachmentStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { formatBytes } from '../../utils';
import { db } from '../../utils/database';
import { eCloseAttachmentDialog, eCloseProgressDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/attachments/attachmentitem.js b/apps/mobile/src/components/attachments/attachmentitem.js
index 17b25ca75..73bc3d744 100644
--- a/apps/mobile/src/components/attachments/attachmentitem.js
+++ b/apps/mobile/src/components/attachments/attachmentitem.js
@@ -2,8 +2,8 @@ import React from 'react';
import { TouchableOpacity, View } from 'react-native';
import * as Progress from 'react-native-progress';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useAttachmentStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { formatBytes } from '../../utils';
import { db } from '../../utils/database';
import { useAttachmentProgress } from '../../utils/hooks/use-attachment-progress';
diff --git a/apps/mobile/src/components/attachments/index.js b/apps/mobile/src/components/attachments/index.js
index 0bf17b7c9..0cff3620b 100644
--- a/apps/mobile/src/components/attachments/index.js
+++ b/apps/mobile/src/components/attachments/index.js
@@ -3,7 +3,7 @@ import { View } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import { eCloseAttachmentDialog, eOpenAttachmentsDialog } from '../../utils/events';
import filesystem from '../../utils/filesystem';
diff --git a/apps/mobile/src/components/auth/changepassword.js b/apps/mobile/src/components/auth/changepassword.js
index a0be4952d..f134fe2aa 100644
--- a/apps/mobile/src/components/auth/changepassword.js
+++ b/apps/mobile/src/components/auth/changepassword.js
@@ -1,7 +1,7 @@
import React, { useRef, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
import { db } from '../../utils/database';
import { eCloseProgressDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/auth/forgotpassword.js b/apps/mobile/src/components/auth/forgotpassword.js
index eb6019f81..e7d613913 100644
--- a/apps/mobile/src/components/auth/forgotpassword.js
+++ b/apps/mobile/src/components/auth/forgotpassword.js
@@ -4,7 +4,7 @@ import ActionSheet from 'react-native-actions-sheet';
import { DDS } from '../../services/device-detection';
import { ToastEvent } from '../../services/event-manager';
import SettingsService from '../../services/settings';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import DialogHeader from '../dialog/dialog-header';
import { Button } from '../ui/button';
diff --git a/apps/mobile/src/components/auth/index.js b/apps/mobile/src/components/auth/index.js
index 26630c67f..35205adc7 100644
--- a/apps/mobile/src/components/auth/index.js
+++ b/apps/mobile/src/components/auth/index.js
@@ -1,10 +1,13 @@
import React, { useEffect, useRef, useState } from 'react';
-import { useThemeStore } from '../../stores/theme';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import { Platform } from 'react-native';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
+import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eCloseLoginDialog, eOpenLoginDialog } from '../../utils/events';
import { sleep } from '../../utils/time';
import BaseDialog from '../dialog/base-dialog';
import { Toast } from '../toast';
+import { IconButton } from '../ui/icon-button';
import { Login } from './login';
import { Signup } from './signup';
@@ -20,6 +23,7 @@ const Auth = () => {
const [visible, setVisible] = useState(false);
const [currentAuthMode, setCurrentAuthMode] = useState(AuthMode.login);
const actionSheetRef = useRef();
+ const insets = useSafeAreaInsets();
useEffect(() => {
eSubscribeEvent(eOpenLoginDialog, open);
@@ -55,8 +59,6 @@ const Auth = () => {
background={colors.bg}
transparent={false}
>
- <Toast context="local" />
-
{currentAuthMode !== AuthMode.login ? (
<Signup
changeMode={mode => setCurrentAuthMode(mode)}
@@ -66,6 +68,24 @@ const Auth = () => {
) : (
<Login changeMode={mode => setCurrentAuthMode(mode)} />
)}
+
+ {currentAuthMode === AuthMode.welcomeSignup ? null : (
+ <IconButton
+ name="arrow-left"
+ onPress={() => {
+ eSendEvent(eCloseLoginDialog);
+ }}
+ color={colors.pri}
+ customStyle={{
+ position: 'absolute',
+ zIndex: 999,
+ left: 12,
+ top: Platform.OS === 'ios' ? 12 + insets.top : 12
+ }}
+ />
+ )}
+
+ <Toast context="local" />
</BaseDialog>
);
};
diff --git a/apps/mobile/src/components/auth/login.js b/apps/mobile/src/components/auth/login.js
index 59474bdd9..d686e924c 100644
--- a/apps/mobile/src/components/auth/login.js
+++ b/apps/mobile/src/components/auth/login.js
@@ -3,18 +3,19 @@ import { Platform, View } from 'react-native';
import { SheetManager } from 'react-native-actions-sheet';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { DDS } from '../../services/device-detection';
-import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
+import { eSendEvent, ToastEvent } from '../../services/event-manager';
import { clearMessage } from '../../services/message';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
-import { useUserStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useUserStore } from '../../stores/use-user-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import { eCloseLoginDialog } from '../../utils/events';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
import BaseDialog from '../dialog/base-dialog';
import SheetProvider from '../sheet-provider';
+import { Progress } from '../sheets/progress';
import { Button } from '../ui/button';
import { IconButton } from '../ui/icon-button';
import Input from '../ui/input';
@@ -25,7 +26,6 @@ import Paragraph from '../ui/typography/paragraph';
import { SVG } from './background';
import { ForgotPassword } from './forgot-password';
import TwoFactorVerification from './two-factor';
-import { Progress } from '../sheets/progress';
export const Login = ({ changeMode }) => {
const colors = useThemeStore(state => state.colors);
const email = useRef();
@@ -130,20 +130,6 @@ export const Login = ({ changeMode }) => {
return (
<>
- <IconButton
- name="arrow-left"
- onPress={() => {
- eSendEvent(eCloseLoginDialog);
- }}
- color={colors.pri}
- customStyle={{
- position: 'absolute',
- zIndex: 999,
- left: 12,
- top: Platform.OS === 'ios' ? 12 + insets.top : 12
- }}
- />
-
<ForgotPassword />
<SheetProvider context="two_factor_verify" />
@@ -167,123 +153,121 @@ export const Login = ({ changeMode }) => {
<SvgView src={SVG(colors.night ? colors.icon : 'black')} height={700} />
</BouncingView>
</View>
- <BouncingView initialScale={0.98} duration={3000}>
- <View
+ <View
+ style={{
+ width: '100%',
+ justifyContent: 'center',
+ alignSelf: 'center',
+ paddingHorizontal: 12,
+ marginBottom: 30,
+ marginTop: 15
+ }}
+ >
+ <Heading
style={{
- width: '100%',
- justifyContent: 'center',
- alignSelf: 'center',
- paddingHorizontal: 12,
- marginBottom: 30,
- marginTop: 15
+ textAlign: 'center'
}}
+ size={30}
+ color={colors.heading}
>
- <Heading
- style={{
- textAlign: 'center'
- }}
- size={30}
- color={colors.heading}
- >
- Welcome back!
- </Heading>
- <Paragraph
- style={{
- textDecorationLine: 'underline',
- textAlign: 'center',
- marginTop: 5
- }}
- onPress={() => {
- changeMode(1);
- }}
- size={SIZE.md}
- >
- Don't have an account? Sign up
- </Paragraph>
- </View>
- <View
+ Welcome back!
+ </Heading>
+ <Paragraph
style={{
- width: focused ? '100%' : '99.9%',
- padding: 12,
- backgroundColor: colors.bg,
- flexGrow: 1
+ textDecorationLine: 'underline',
+ textAlign: 'center',
+ marginTop: 5
+ }}
+ onPress={() => {
+ changeMode(1);
}}
+ size={SIZE.md}
>
- <Input
- fwdRef={emailInputRef}
- onChangeText={value => {
- email.current = value;
- }}
- testID="input.email"
- onErrorCheck={e => setError(e)}
- returnKeyLabel="Next"
- returnKeyType="next"
- autoComplete="email"
- validationType="email"
- autoCorrect={false}
- autoCapitalize="none"
- errorMessage="Email is invalid"
- placeholder="Email"
- onSubmit={() => {
- passwordInputRef.current?.focus();
- }}
- />
+ Don't have an account? Sign up
+ </Paragraph>
+ </View>
+ <View
+ style={{
+ width: focused ? '100%' : '99.9%',
+ padding: 12,
+ backgroundColor: colors.bg,
+ flexGrow: 1
+ }}
+ >
+ <Input
+ fwdRef={emailInputRef}
+ onChangeText={value => {
+ email.current = value;
+ }}
+ testID="input.email"
+ onErrorCheck={e => setError(e)}
+ returnKeyLabel="Next"
+ returnKeyType="next"
+ autoComplete="email"
+ validationType="email"
+ autoCorrect={false}
+ autoCapitalize="none"
+ errorMessage="Email is invalid"
+ placeholder="Email"
+ onSubmit={() => {
+ passwordInputRef.current?.focus();
+ }}
+ />
- <Input
- fwdRef={passwordInputRef}
- onChangeText={value => {
- password.current = value;
- }}
- testID="input.password"
- returnKeyLabel="Done"
- returnKeyType="done"
- secureTextEntry
- autoComplete="password"
- autoCapitalize="none"
- autoCorrect={false}
- placeholder="Password"
- marginBottom={0}
- onSubmit={() => login()}
- />
+ <Input
+ fwdRef={passwordInputRef}
+ onChangeText={value => {
+ password.current = value;
+ }}
+ testID="input.password"
+ returnKeyLabel="Done"
+ returnKeyType="done"
+ secureTextEntry
+ autoComplete="password"
+ autoCapitalize="none"
+ autoCorrect={false}
+ placeholder="Password"
+ marginBottom={0}
+ onSubmit={() => login()}
+ />
+ <Button
+ title="Forgot your password?"
+ style={{
+ alignSelf: 'flex-end',
+ height: 30,
+ paddingHorizontal: 0
+ }}
+ onPress={() => {
+ SheetManager.show('forgotpassword_sheet', email.current);
+ }}
+ textStyle={{
+ textDecorationLine: 'underline'
+ }}
+ fontSize={SIZE.xs}
+ type="gray"
+ />
+
+ <View
+ style={{
+ // position: 'absolute',
+ marginTop: 50,
+ alignSelf: 'center'
+ }}
+ >
<Button
- title="Forgot your password?"
style={{
- alignSelf: 'flex-end',
- height: 30,
- paddingHorizontal: 0
- }}
- onPress={() => {
- SheetManager.show('forgotpassword_sheet', email.current);
+ marginTop: 10,
+ width: 250,
+ borderRadius: 100
}}
- textStyle={{
- textDecorationLine: 'underline'
- }}
- fontSize={SIZE.xs}
- type="gray"
+ loading={loading}
+ onPress={() => login()}
+ // width="100%"
+ type="accent"
+ title={loading ? null : 'Login to your account'}
/>
-
- <View
- style={{
- // position: 'absolute',
- marginTop: 50,
- alignSelf: 'center'
- }}
- >
- <Button
- style={{
- marginTop: 10,
- width: 250,
- borderRadius: 100
- }}
- loading={loading}
- onPress={() => login()}
- // width="100%"
- type="accent"
- title={loading ? null : 'Login to your account'}
- />
- </View>
</View>
- </BouncingView>
+ </View>
</View>
</>
);
diff --git a/apps/mobile/src/components/auth/sessionexpired.js b/apps/mobile/src/components/auth/sessionexpired.js
index 255dc4ed3..72fb6fdcd 100644
--- a/apps/mobile/src/components/auth/sessionexpired.js
+++ b/apps/mobile/src/components/auth/sessionexpired.js
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { Modal, View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
import BiometricService from '../../services/biometrics';
import {
eSendEvent,
diff --git a/apps/mobile/src/components/auth/signup.js b/apps/mobile/src/components/auth/signup.js
index 4ca95f838..b59295372 100644
--- a/apps/mobile/src/components/auth/signup.js
+++ b/apps/mobile/src/components/auth/signup.js
@@ -1,21 +1,21 @@
import React, { useRef, useState } from 'react';
import { Dimensions, Platform, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
import { DDS } from '../../services/device-detection';
import { eSendEvent, ToastEvent } from '../../services/event-manager';
import { clearMessage, setEmailVerifyMessage } from '../../services/message';
import PremiumService from '../../services/premium';
+import { useUserStore } from '../../stores/use-user-store';
+import { useThemeStore } from '../../stores/use-theme-store';
+import umami from '../../utils/analytics';
import { db } from '../../utils/database';
import { eCloseLoginDialog } from '../../utils/events';
import { openLinkInBrowser } from '../../utils/functions';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
-import umami from '../../utils/analytics';
-import { IconButton } from '../ui/icon-button';
-import { Button } from '../ui/button';
import BaseDialog from '../dialog/base-dialog';
+import { Button } from '../ui/button';
+import { IconButton } from '../ui/icon-button';
import Input from '../ui/input';
import { SvgView } from '../ui/svg';
import { BouncingView } from '../ui/transitions/bouncing-view';
@@ -85,22 +85,6 @@ export const Signup = ({ changeMode, welcome, trial }) => {
return (
<>
- {!welcome && (
- <IconButton
- name="arrow-left"
- onPress={() => {
- eSendEvent(eCloseLoginDialog);
- }}
- color={colors.pri}
- customStyle={{
- position: 'absolute',
- zIndex: 999,
- left: 12,
- top: Platform.OS === 'ios' ? 12 + insets.top : 12
- }}
- />
- )}
-
{loading ? <BaseDialog transparent={true} visible={true} animation="fade" /> : null}
<View
style={{
@@ -117,179 +101,177 @@ export const Signup = ({ changeMode, welcome, trial }) => {
overflow: 'hidden'
}}
>
- <BouncingView initialScale={1.05} duration={5000}>
+ <BouncingView initialScale={1.05}>
<SvgView src={SVG(colors.night ? colors.icon : 'black')} height={700} />
</BouncingView>
</View>
- <BouncingView initialScale={0.98} duration={5000}>
- <View
+ <View
+ style={{
+ width: '100%',
+ justifyContent: 'center',
+ alignSelf: 'center',
+ paddingHorizontal: 12,
+ marginBottom: 30,
+ marginTop: Dimensions.get('window').height < 700 ? -75 : 15
+ }}
+ >
+ <Heading
style={{
- width: '100%',
- justifyContent: 'center',
- alignSelf: 'center',
- paddingHorizontal: 12,
- marginBottom: 30,
- marginTop: Dimensions.get('window').height < 700 ? -75 : 15
+ textAlign: 'center'
}}
+ size={30}
+ color={colors.heading}
>
- <Heading
+ Create your account
+ </Heading>
+ <Paragraph
+ style={{
+ textDecorationLine: 'underline',
+ textAlign: 'center'
+ }}
+ onPress={() => {
+ changeMode(0);
+ }}
+ size={SIZE.md}
+ >
+ Already have an account? Log in
+ </Paragraph>
+ </View>
+ <View
+ style={{
+ width: '100%',
+ padding: 12,
+ backgroundColor: colors.bg,
+ flexGrow: 1
+ }}
+ >
+ <Input
+ fwdRef={emailInputRef}
+ onChangeText={value => {
+ email.current = value;
+ }}
+ testID="input.email"
+ onErrorCheck={e => setError(e)}
+ returnKeyLabel="Next"
+ returnKeyType="next"
+ autoComplete="email"
+ validationType="email"
+ autoCorrect={false}
+ autoCapitalize="none"
+ errorMessage="Email is invalid"
+ placeholder="Email"
+ onSubmit={() => {
+ passwordInputRef.current?.focus();
+ }}
+ />
+
+ <Input
+ fwdRef={passwordInputRef}
+ onChangeText={value => {
+ password.current = value;
+ }}
+ testID="input.password"
+ onErrorCheck={e => setError(e)}
+ returnKeyLabel="Next"
+ returnKeyType="next"
+ secureTextEntry
+ autoComplete="password"
+ autoCapitalize="none"
+ validationType="password"
+ autoCorrect={false}
+ placeholder="Password"
+ onSubmit={() => {
+ confirmPasswordInputRef.current?.focus();
+ }}
+ />
+
+ <Input
+ fwdRef={confirmPasswordInputRef}
+ onChangeText={value => {
+ confirmPassword.current = value;
+ }}
+ testID="input.confirmPassword"
+ onErrorCheck={e => setError(e)}
+ returnKeyLabel="Signup"
+ returnKeyType="done"
+ secureTextEntry
+ autoComplete="password"
+ autoCapitalize="none"
+ autoCorrect={false}
+ validationType="confirmPassword"
+ customValidator={() => password.current}
+ placeholder="Confirm password"
+ marginBottom={5}
+ onSubmit={signup}
+ />
+ <Paragraph size={SIZE.xs} color={colors.icon}>
+ By signing up, you agree to our{' '}
+ <Paragraph
+ size={SIZE.xs}
+ onPress={() => {
+ openLinkInBrowser('https://notesnook.com/tos', colors)
+ .catch(e => {})
+ .then(r => {});
+ }}
style={{
- textAlign: 'center'
+ textDecorationLine: 'underline'
}}
- size={30}
- color={colors.heading}
+ color={colors.accent}
>
- Create your account
- </Heading>
+ terms of service{' '}
+ </Paragraph>
+ and{' '}
<Paragraph
- style={{
- textDecorationLine: 'underline',
- textAlign: 'center'
- }}
+ size={SIZE.xs}
onPress={() => {
- changeMode(0);
+ openLinkInBrowser('https://notesnook.com/privacy', colors)
+ .catch(e => {})
+ .then(r => {});
+ }}
+ style={{
+ textDecorationLine: 'underline'
}}
- size={SIZE.md}
+ color={colors.accent}
>
- Already have an account? Log in
+ privacy policy.
</Paragraph>
- </View>
+ </Paragraph>
+
<View
style={{
- width: '100%',
- padding: 12,
- backgroundColor: colors.bg,
- flexGrow: 1
+ marginTop: 50,
+ alignSelf: 'center'
}}
>
- <Input
- fwdRef={emailInputRef}
- onChangeText={value => {
- email.current = value;
- }}
- testID="input.email"
- onErrorCheck={e => setError(e)}
- returnKeyLabel="Next"
- returnKeyType="next"
- autoComplete="email"
- validationType="email"
- autoCorrect={false}
- autoCapitalize="none"
- errorMessage="Email is invalid"
- placeholder="Email"
- onSubmit={() => {
- passwordInputRef.current?.focus();
- }}
- />
-
- <Input
- fwdRef={passwordInputRef}
- onChangeText={value => {
- password.current = value;
- }}
- testID="input.password"
- onErrorCheck={e => setError(e)}
- returnKeyLabel="Next"
- returnKeyType="next"
- secureTextEntry
- autoComplete="password"
- autoCapitalize="none"
- validationType="password"
- autoCorrect={false}
- placeholder="Password"
- onSubmit={() => {
- confirmPasswordInputRef.current?.focus();
- }}
- />
-
- <Input
- fwdRef={confirmPasswordInputRef}
- onChangeText={value => {
- confirmPassword.current = value;
+ <Button
+ style={{
+ marginTop: 10,
+ width: 250,
+ borderRadius: 100
}}
- testID="input.confirmPassword"
- onErrorCheck={e => setError(e)}
- returnKeyLabel="Signup"
- returnKeyType="done"
- secureTextEntry
- autoComplete="password"
- autoCapitalize="none"
- autoCorrect={false}
- validationType="confirmPassword"
- customValidator={() => password.current}
- placeholder="Confirm password"
- marginBottom={5}
- onSubmit={signup}
+ loading={loading}
+ onPress={signup}
+ type="accent"
+ title={loading ? null : 'Agree and continue'}
/>
- <Paragraph size={SIZE.xs} color={colors.icon}>
- By signing up, you agree to our{' '}
- <Paragraph
- size={SIZE.xs}
- onPress={() => {
- openLinkInBrowser('https://notesnook.com/tos', colors)
- .catch(e => {})
- .then(r => {});
- }}
- style={{
- textDecorationLine: 'underline'
- }}
- color={colors.accent}
- >
- terms of service{' '}
- </Paragraph>
- and{' '}
- <Paragraph
- size={SIZE.xs}
- onPress={() => {
- openLinkInBrowser('https://notesnook.com/privacy', colors)
- .catch(e => {})
- .then(r => {});
- }}
- style={{
- textDecorationLine: 'underline'
- }}
- color={colors.accent}
- >
- privacy policy.
- </Paragraph>
- </Paragraph>
- <View
- style={{
- marginTop: 50,
- alignSelf: 'center'
- }}
- >
+ {loading || !welcome ? null : (
<Button
style={{
marginTop: 10,
width: 250,
borderRadius: 100
}}
- loading={loading}
- onPress={signup}
- type="accent"
- title={loading ? null : 'Agree and continue'}
+ onPress={() => {
+ eSendEvent(eCloseLoginDialog);
+ }}
+ type="grayBg"
+ title="Skip for now"
/>
-
- {loading || !welcome ? null : (
- <Button
- style={{
- marginTop: 10,
- width: 250,
- borderRadius: 100
- }}
- onPress={() => {
- eSendEvent(eCloseLoginDialog);
- }}
- type="grayBg"
- title="Skip for now"
- />
- )}
- </View>
+ )}
</View>
- </BouncingView>
+ </View>
</View>
</>
);
diff --git a/apps/mobile/src/components/auth/twofactor.js b/apps/mobile/src/components/auth/twofactor.js
index 3e13958de..eb2ed896b 100644
--- a/apps/mobile/src/components/auth/twofactor.js
+++ b/apps/mobile/src/components/auth/twofactor.js
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { View } from 'react-native';
import { eSendEvent, presentSheet } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eCloseProgressDialog } from '../../utils/events';
import useTimer from '../../utils/hooks/use-timer';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/container/containerheader.js b/apps/mobile/src/components/container/containerheader.js
index 8d0580731..8134f2f31 100644
--- a/apps/mobile/src/components/container/containerheader.js
+++ b/apps/mobile/src/components/container/containerheader.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
-import { useSelectionStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useSelectionStore } from '../../stores/use-selection-store';
export const ContainerHeader = ({ children }) => {
const colors = useThemeStore(state => state.colors);
diff --git a/apps/mobile/src/components/container/floatingbutton.js b/apps/mobile/src/components/container/floatingbutton.js
index 51e2c68b3..f94ed2e32 100644
--- a/apps/mobile/src/components/container/floatingbutton.js
+++ b/apps/mobile/src/components/container/floatingbutton.js
@@ -9,12 +9,12 @@ import Animated, {
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids';
-import { useSelectionStore, useSettingStore } from '../../stores/stores';
+import { useSelectionStore } from '../../stores/use-selection-store';
+import { useSettingStore } from '../../stores/use-setting-store';
import { editing, getElevation, showTooltip, TOOLTIP_POSITIONS } from '../../utils';
import { normalize, SIZE } from '../../utils/size';
import { PressableButton } from '../ui/pressable';
-const translateY = new Animated.Value(0);
export const FloatingButton = ({ title, onPress, color = 'accent', shouldShow = false }) => {
const insets = useSafeAreaInsets();
const deviceMode = useSettingStore(state => state.deviceMode);
@@ -77,7 +77,7 @@ export const FloatingButton = ({ title, onPress, color = 'accent', shouldShow =
? Platform.isPad
? insets.bottom - 12
: insets.bottom - 24
- : insets.bottom + 12,
+ : insets.bottom,
zIndex: 10
},
animatedStyle
diff --git a/apps/mobile/src/components/container/index.js b/apps/mobile/src/components/container/index.js
index 59af9fbce..aa067527c 100644
--- a/apps/mobile/src/components/container/index.js
+++ b/apps/mobile/src/components/container/index.js
@@ -1,24 +1,24 @@
import React from 'react';
import { KeyboardAvoidingView, Platform, SafeAreaView } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
import useIsFloatingKeyboard from '../../utils/hooks/use-is-floating-keyboard';
+import { Header } from '../header';
+import SelectionHeader from '../selection-header';
export const Container = ({ children }) => {
- const colors = useThemeStore(state => state.colors);
const floating = useIsFloatingKeyboard();
return (
<KeyboardAvoidingView
behavior="padding"
enabled={Platform.OS === 'ios' && !floating}
style={{
- backgroundColor: colors.bg,
- width: '100%',
- height: '100%'
+ flex: 1
}}
>
+ <SelectionHeader />
+ <Header title="Header" screen="Header" />
<SafeAreaView
style={{
- height: '100%',
- backgroundColor: colors.bg,
+ flex: 1,
overflow: 'hidden'
}}
>
diff --git a/apps/mobile/src/components/dialog/BaseDialog.js b/apps/mobile/src/components/dialog/BaseDialog.js
index e9b3690b7..0618b6dbf 100644
--- a/apps/mobile/src/components/dialog/BaseDialog.js
+++ b/apps/mobile/src/components/dialog/BaseDialog.js
@@ -8,7 +8,7 @@ import {
TouchableOpacity,
View
} from 'react-native';
-import { useSettingStore } from '../../stores/stores';
+import { useSettingStore } from '../../stores/use-setting-store';
import useIsFloatingKeyboard from '../../utils/hooks/use-is-floating-keyboard';
import { BouncingView } from '../ui/transitions/bouncing-view';
diff --git a/apps/mobile/src/components/dialog/DialogButtons.js b/apps/mobile/src/components/dialog/DialogButtons.js
index 50029cfa3..14489cc6e 100644
--- a/apps/mobile/src/components/dialog/DialogButtons.js
+++ b/apps/mobile/src/components/dialog/DialogButtons.js
@@ -1,6 +1,6 @@
import React from 'react';
import { ActivityIndicator, StyleSheet, View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
import Paragraph from '../ui/typography/paragraph';
diff --git a/apps/mobile/src/components/dialog/DialogContainer.js b/apps/mobile/src/components/dialog/DialogContainer.js
index f3be91445..d1c5a5e6c 100644
--- a/apps/mobile/src/components/dialog/DialogContainer.js
+++ b/apps/mobile/src/components/dialog/DialogContainer.js
@@ -1,6 +1,6 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { DDS } from '../../services/device-detection';
import { getElevation } from '../../utils';
diff --git a/apps/mobile/src/components/dialog/DialogHeader.tsx b/apps/mobile/src/components/dialog/DialogHeader.tsx
index 4d79df639..0cc66b8e6 100644
--- a/apps/mobile/src/components/dialog/DialogHeader.tsx
+++ b/apps/mobile/src/components/dialog/DialogHeader.tsx
@@ -1,7 +1,7 @@
import React from 'react';
import { Text } from 'react-native';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
import { PressableButtonProps } from '../ui/pressable';
diff --git a/apps/mobile/src/components/dialog/index.js b/apps/mobile/src/components/dialog/index.js
index 89e85b336..bd646ca6a 100644
--- a/apps/mobile/src/components/dialog/index.js
+++ b/apps/mobile/src/components/dialog/index.js
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { DDS } from '../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { getElevation } from '../../utils';
diff --git a/apps/mobile/src/components/dialogprovider/index.js b/apps/mobile/src/components/dialogprovider/index.js
index d8c2a5887..1a6a7861a 100644
--- a/apps/mobile/src/components/dialogprovider/index.js
+++ b/apps/mobile/src/components/dialogprovider/index.js
@@ -1,5 +1,5 @@
import React from 'react';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { EditorSettings } from '../../screens/editor/EditorSettings';
import { AddNotebookSheet } from '../sheets/add-notebook';
import { AddTopicDialog } from '../dialogs/add-topic';
diff --git a/apps/mobile/src/components/dialogs/addtopic/index.js b/apps/mobile/src/components/dialogs/addtopic/index.js
index efe48dfc0..eb54751a3 100644
--- a/apps/mobile/src/components/dialogs/addtopic/index.js
+++ b/apps/mobile/src/components/dialogs/addtopic/index.js
@@ -1,7 +1,7 @@
import React, { createRef } from 'react';
import { Keyboard, LayoutAnimation, UIManager, View } from 'react-native';
import { Transition, Transitioning, TransitioningView } from 'react-native-reanimated';
-import { useMenuStore } from '../../../stores/stores';
+import { useMenuStore } from '../../../stores/use-menu-store';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { db } from '../../../utils/database';
@@ -54,11 +54,7 @@ export class AddTopicDialog extends React.Component {
}
this.setState({ loading: false });
this.close();
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.Notebook,
- Navigation.routeNames.NotesPage
- ]);
+ Navigation.queueRoutesForUpdate('Notebooks', 'Notebook', 'TopicNotes');
useMenuStore.getState().setMenuPins();
} catch (e) {}
};
diff --git a/apps/mobile/src/components/dialogs/jumptosection/index.js b/apps/mobile/src/components/dialogs/jumptosection/index.js
index a7ccc6756..baaa30968 100644
--- a/apps/mobile/src/components/dialogs/jumptosection/index.js
+++ b/apps/mobile/src/components/dialogs/jumptosection/index.js
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { ScrollView, View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { useMessageStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useMessageStore } from '../../../stores/use-message-store';
import { DDS } from '../../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../services/event-manager';
import { getElevation } from '../../../utils';
diff --git a/apps/mobile/src/components/dialogs/result/ProFeatures.js b/apps/mobile/src/components/dialogs/result/ProFeatures.js
index 7793a6a40..2450d96f1 100644
--- a/apps/mobile/src/components/dialogs/result/ProFeatures.js
+++ b/apps/mobile/src/components/dialogs/result/ProFeatures.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { eSendEvent } from '../../../services/event-manager';
import {
eCloseProgressDialog,
diff --git a/apps/mobile/src/components/dialogs/result/index.js b/apps/mobile/src/components/dialogs/result/index.js
index 751e390e4..96071b787 100644
--- a/apps/mobile/src/components/dialogs/result/index.js
+++ b/apps/mobile/src/components/dialogs/result/index.js
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { DDS } from '../../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../services/event-manager';
import { getElevation } from '../../../utils';
diff --git a/apps/mobile/src/components/dialogs/vault/index.js b/apps/mobile/src/components/dialogs/vault/index.js
index 8a6494104..d8c5a7a26 100644
--- a/apps/mobile/src/components/dialogs/vault/index.js
+++ b/apps/mobile/src/components/dialogs/vault/index.js
@@ -187,17 +187,15 @@ export class VaultDialog extends Component {
});
return;
}
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notes,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Notebook
- ]);
+
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'TopicNotes',
+ 'TaggedNotes',
+ 'ColoredNotes'
+ );
+
this.password = null;
this.confirmPassword = null;
SearchService.updateAndSearch();
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.js
index bda375480..cbc578387 100644
--- a/apps/mobile/src/components/header/index.js
+++ b/apps/mobile/src/components/header/index.js
@@ -2,23 +2,24 @@ import React, { useEffect, useState } from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eScrollEvent } from '../../utils/events';
import { LeftMenus } from './left-menus';
import { RightMenus } from './right-menus';
import { Title } from './title';
export const Header = React.memo(
- ({ root, title, screen, isBack, color, action, rightButtons, notebook, onBackPress }) => {
+ () => {
const colors = useThemeStore(state => state.colors);
const insets = useSafeAreaInsets();
const [hide, setHide] = useState(true);
const onScroll = data => {
- if (data.screen !== screen) return;
if (data.y > 150) {
+ if (!hide) return;
setHide(false);
} else {
+ if (hide) return;
setHide(true);
}
};
@@ -28,7 +29,7 @@ export const Header = React.memo(
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
};
- }, []);
+ }, [hide]);
return (
<View
@@ -45,22 +46,14 @@ export const Header = React.memo(
]}
>
<View style={styles.leftBtnContainer}>
- <LeftMenus onBackPress={onBackPress} headerMenuState={!isBack} currentScreen={screen} />
-
- <Title
- notebook={notebook}
- headerColor={color}
- heading={title}
- screen={screen}
- root={root}
- />
+ <LeftMenus />
+ <Title />
</View>
-
- <RightMenus rightButtons={rightButtons} action={action} currentScreen={screen} />
+ <RightMenus />
</View>
);
},
- (prev, next) => prev.title === next.title
+ () => true
);
const styles = StyleSheet.create({
diff --git a/apps/mobile/src/components/header/leftmenus.js b/apps/mobile/src/components/header/leftmenus.js
index e7a9f3803..934f675d9 100644
--- a/apps/mobile/src/components/header/leftmenus.js
+++ b/apps/mobile/src/components/header/leftmenus.js
@@ -1,52 +1,50 @@
import React from 'react';
import { notesnook } from '../../../e2e/test.ids';
-import { useThemeStore } from '../../stores/theme';
-import { useSettingStore } from '../../stores/stores';
import { DDS } from '../../services/device-detection';
import Navigation from '../../services/navigation';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { IconButton } from '../ui/icon-button';
-export const LeftMenus = ({ currentScreen, headerMenuState, onBackPress }) => {
+export const LeftMenus = () => {
const colors = useThemeStore(state => state.colors);
const deviceMode = useSettingStore(state => state.deviceMode);
+ const canGoBack = useNavigationStore(state => state.canGoBack);
+ const isTablet = deviceMode === 'tablet';
const onLeftButtonPress = () => {
- if (onBackPress) return onBackPress();
- if (headerMenuState) {
+ if (!canGoBack) {
Navigation.openDrawer();
return;
}
Navigation.goBack();
};
- return (
- <>
- {deviceMode !== 'tablet' || currentScreen === 'Search' || !headerMenuState ? (
- <IconButton
- testID={notesnook.ids.default.header.buttons.left}
- customStyle={{
- justifyContent: 'center',
- alignItems: 'center',
- height: 40,
- width: 40,
- borderRadius: 100,
- marginLeft: -5,
- marginRight: DDS.isLargeTablet() ? 10 : 25
- }}
- left={40}
- top={40}
- right={DDS.isLargeTablet() ? 10 : 25}
- onPress={onLeftButtonPress}
- onLongPress={() => {
- Navigation.popToTop();
- }}
- name={!headerMenuState ? 'arrow-left' : 'menu'}
- color={colors.pri}
- iconStyle={{
- marginLeft: !headerMenuState ? -5 : 0
- }}
- />
- ) : undefined}
- </>
+ return isTablet ? null : (
+ <IconButton
+ testID={notesnook.ids.default.header.buttons.left}
+ customStyle={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ height: 40,
+ width: 40,
+ borderRadius: 100,
+ marginLeft: -5,
+ marginRight: DDS.isLargeTablet() ? 10 : 25
+ }}
+ left={40}
+ top={40}
+ right={DDS.isLargeTablet() ? 10 : 25}
+ onPress={onLeftButtonPress}
+ onLongPress={() => {
+ Navigation.popToTop();
+ }}
+ name={canGoBack ? 'arrow-left' : 'menu'}
+ color={colors.pri}
+ iconStyle={{
+ marginLeft: canGoBack ? -5 : 0
+ }}
+ />
);
};
diff --git a/apps/mobile/src/components/header/rightmenus.js b/apps/mobile/src/components/header/rightmenus.js
index 9e657ef36..73e89bf09 100644
--- a/apps/mobile/src/components/header/rightmenus.js
+++ b/apps/mobile/src/components/header/rightmenus.js
@@ -2,24 +2,30 @@ import React, { useRef } from 'react';
import { StyleSheet, View } from 'react-native';
import Menu from 'react-native-reanimated-material-menu';
import { notesnook } from '../../../e2e/test.ids';
-import { useThemeStore } from '../../stores/theme';
-import { useSettingStore } from '../../stores/stores';
import Navigation from '../../services/navigation';
+import SearchService from '../../services/search';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
import { IconButton } from '../ui/icon-button';
-export const RightMenus = ({ currentScreen, action, rightButtons }) => {
+export const RightMenus = () => {
const colors = useThemeStore(state => state.colors);
const deviceMode = useSettingStore(state => state.deviceMode);
+ const rightButtons = useNavigationStore(state => state.headerRightButtons);
+ const currentScreen = useNavigationStore(state => state.currentScreen.name);
const menuRef = useRef();
+
return (
<View style={styles.rightBtnContainer}>
{!currentScreen.startsWith('Settings') ? (
<IconButton
onPress={async () => {
- Navigation.navigate('Search', {
- menu: false
+ SearchService.prepareSearch();
+ Navigation.navigate({
+ name: 'Search'
});
}}
testID="icon-search"
@@ -31,7 +37,7 @@ export const RightMenus = ({ currentScreen, action, rightButtons }) => {
{deviceMode !== 'mobile' ? (
<Button
- onPress={action}
+ onPress={RightMenus.floatingButtonAction}
testID={notesnook.ids.default.addBtn}
icon={currentScreen === 'Trash' ? 'delete' : 'plus'}
iconSize={SIZE.xl}
@@ -54,7 +60,7 @@ export const RightMenus = ({ currentScreen, action, rightButtons }) => {
/>
) : null}
- {rightButtons ? (
+ {rightButtons && rightButtons.length > 0 ? (
<Menu
ref={menuRef}
animationDuration={200}
@@ -67,7 +73,6 @@ export const RightMenus = ({ currentScreen, action, rightButtons }) => {
onPress={() => {
menuRef.current?.show();
}}
- //testID={notesnook.ids.default.header.buttons.left}
name="dots-vertical"
color={colors.pri}
customStyle={styles.rightBtn}
@@ -87,7 +92,7 @@ export const RightMenus = ({ currentScreen, action, rightButtons }) => {
}}
key={item.title}
title={item.title}
- onPress={item.func}
+ onPress={item.onPress}
/>
))}
</Menu>
@@ -96,6 +101,8 @@ export const RightMenus = ({ currentScreen, action, rightButtons }) => {
);
};
+RightMenus.floatingButtonAction = () => {};
+
const styles = StyleSheet.create({
rightBtnContainer: {
flexDirection: 'row',
diff --git a/apps/mobile/src/components/header/title.js b/apps/mobile/src/components/header/title.js
index 8249d6543..64c2a8500 100644
--- a/apps/mobile/src/components/header/title.js
+++ b/apps/mobile/src/components/header/title.js
@@ -1,51 +1,76 @@
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import Animated, { Layout } from 'react-native-reanimated';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
-import { eOnNewTopicAdded, eScrollEvent } from '../../utils/events';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { db } from '../../utils/database';
+import { eScrollEvent } from '../../utils/events';
import { SIZE } from '../../utils/size';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
-export const Title = ({ heading, headerColor, screen, notebook }) => {
+const titleState = {};
+
+export const Title = () => {
const colors = useThemeStore(state => state.colors);
- const [hide, setHide] = useState(screen === 'Notebook' ? true : false);
+ const currentScreen = useNavigationStore(state => state.currentScreen);
+ const isTopic = currentScreen.type === 'topic';
+ const [hide, setHide] = useState(isTopic ? true : false);
+ const isHidden = titleState[currentScreen.id];
+ const notebook = isTopic ? db.notebooks?.notebook(currentScreen.notebookId)?.data : null;
+ const title = currentScreen.title;
+ const isTag = title.slice(0, 1) === '#';
const onScroll = data => {
- if (screen !== 'Notebook') {
+ if (currentScreen.name !== 'Notebook') {
setHide(false);
return;
}
if (data.y > 150) {
+ if (!hide) return;
setHide(false);
} else {
+ if (hide) return;
setHide(true);
}
};
+ useEffect(() => {
+ if (currentScreen.name === 'Notebook') {
+ let value =
+ typeof titleState[currentScreen.id] === 'boolean' ? titleState[currentScreen.id] : true;
+ setHide(value);
+ } else {
+ setHide(titleState[currentScreen.id]);
+ }
+ }, [currentScreen.id]);
+
+ useEffect(() => {
+ titleState[currentScreen.id] = hide;
+ }, [hide]);
+
useEffect(() => {
eSubscribeEvent(eScrollEvent, onScroll);
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
};
- }, []);
+ }, [hide]);
function navigateToNotebook() {
- if (!notebook) return;
- let routeName = 'Notebook';
- let params = {
- menu: false,
- notebook: notebook,
- title: notebook.title
- };
- let headerState = {
- heading: notebook.title,
- id: notebook.id,
- type: notebook.type
- };
- eSendEvent(eOnNewTopicAdded, params);
- Navigation.navigate(routeName, params, headerState);
+ if (!isTopic) return;
+ Navigation.navigate(
+ {
+ name: 'Notebook',
+ id: isTopic.id,
+ type: isTopic.type
+ },
+ {
+ notebook: isTopic,
+ title: isTopic.title
+ }
+ );
}
return (
@@ -56,24 +81,28 @@ export const Title = ({ heading, headerColor, screen, notebook }) => {
flexDirection: 'row'
}}
>
- {!hide ? (
+ {!hide && !isHidden ? (
<Heading
onPress={navigateToNotebook}
- numberOfLines={notebook ? 2 : 1}
- size={notebook ? SIZE.md + 2 : SIZE.xl}
+ numberOfLines={isTopic ? 2 : 1}
+ size={isTopic ? SIZE.md + 2 : SIZE.xl}
style={{
flexWrap: 'wrap'
}}
- color={headerColor}
+ color={currentScreen.color}
>
- {notebook ? (
+ {isTopic ? (
<Paragraph numberOfLines={1} size={SIZE.xs + 1}>
{notebook?.title}
{'\n'}
</Paragraph>
) : null}
- <Heading color={colors.accent}>{heading.slice(0, 1) === '#' ? '#' : null}</Heading>
- {heading.slice(0, 1) === '#' ? heading.slice(1) : heading}
+ {isTag ? (
+ <Heading size={isTopic ? SIZE.md + 2 : SIZE.xl} color={colors.accent}>
+ #
+ </Heading>
+ ) : null}
+ {isTag ? title.slice(1) : title}
</Heading>
) : null}
</View>
diff --git a/apps/mobile/src/components/intro/index.js b/apps/mobile/src/components/intro/index.js
index 0eb515dca..55fd9b3e8 100644
--- a/apps/mobile/src/components/intro/index.js
+++ b/apps/mobile/src/components/intro/index.js
@@ -5,8 +5,8 @@ import { SafeAreaView } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import AppLock from '../../screens/settings/app-lock';
import SettingsService from '../../services/settings';
-import { useSettingStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { getElevation } from '../../utils';
import umami from '../../utils/analytics';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/intro/welcome.js b/apps/mobile/src/components/intro/welcome.js
index e5b2f0d00..b13b32f48 100644
--- a/apps/mobile/src/components/intro/welcome.js
+++ b/apps/mobile/src/components/intro/welcome.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
import umami from '../../utils/analytics';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent } from '../../services/event-manager';
import { getElevation } from '../../utils';
import { eCloseProgressDialog, eOpenLoginDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/launcher/index.js b/apps/mobile/src/components/launcher/index.js
index 1b7574f20..7f5370116 100644
--- a/apps/mobile/src/components/launcher/index.js
+++ b/apps/mobile/src/components/launcher/index.js
@@ -9,15 +9,13 @@ import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manag
import { setRateAppMessage } from '../../services/message';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
-import {
- initialize,
- useFavoriteStore,
- useMessageStore,
- useNoteStore,
- useSettingStore,
- useUserStore
-} from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { initialize } from '../../stores';
+import { useUserStore } from '../../stores/use-user-store';
+import { useMessageStore } from '../../stores/use-message-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useFavoriteStore } from '../../stores/use-favorite-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { editing } from '../../utils';
import { db } from '../../utils/database';
import { MMKV } from '../../utils/database/mmkv';
@@ -52,9 +50,10 @@ const Launcher = React.memo(
const deviceMode = useSettingStore(state => state.deviceMode);
const passwordInputRef = useRef();
const password = useRef();
+ const introCompleted = SettingsService.get().introCompleted;
const [requireIntro, setRequireIntro] = useState({
- updated: false,
- value: false
+ updated: introCompleted,
+ value: !introCompleted
});
const dbInitCompleted = useRef(false);
@@ -63,18 +62,20 @@ const Launcher = React.memo(
return;
}
await restoreEditorState();
- await db.notes.init();
- setNotes();
- setFavorites();
- setLoading(false);
- Walkthrough.init();
+ setImmediate(() => {
+ db.notes.init().then(() => {
+ setNotes();
+ setFavorites();
+ setLoading(false);
+ Walkthrough.init();
+ });
+ });
};
const init = async () => {
if (!dbInitCompleted.current) {
await db.init();
initialize();
- useUserStore.getState().setUser(await db.user.getUser());
dbInitCompleted.current = true;
}
@@ -84,7 +85,7 @@ const Launcher = React.memo(
};
const hideSplashScreen = async () => {
- await sleep(requireIntro.value ? 500 : 0);
+ if (requireIntro.value) await sleep(500);
await RNBootSplash.hide({ fade: true });
setTimeout(async () => {
if (Platform.OS === 'android') {
@@ -100,22 +101,22 @@ const Launcher = React.memo(
} else {
StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
}
- }, 500);
+ }, 1000);
};
useEffect(() => {
+ console.log('hide splash', requireIntro.updated);
if (requireIntro.updated) {
hideSplashScreen();
+ return;
}
- }, [requireIntro, verifyUser]);
-
- useEffect(() => {
let introCompleted = SettingsService.get().introCompleted;
+ console.log(requireIntro);
setRequireIntro({
updated: true,
value: !introCompleted
});
- }, []);
+ }, [requireIntro, verifyUser]);
useEffect(() => {
if (!loading) {
diff --git a/apps/mobile/src/components/list/card.js b/apps/mobile/src/components/list/card.js
index 2eb52b0a2..755dceb3c 100644
--- a/apps/mobile/src/components/list/card.js
+++ b/apps/mobile/src/components/list/card.js
@@ -2,8 +2,9 @@ import React from 'react';
import { View } from 'react-native';
import Animated, { FadeInUp, FadeOutUp } from 'react-native-reanimated';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useMessageStore, useSelectionStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSelectionStore } from '../../stores/use-selection-store';
+import { useMessageStore } from '../../stores/use-message-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { hexToRGBA } from '../../utils/color-scheme/utils';
import { SIZE } from '../../utils/size';
import { PressableButton } from '../ui/pressable';
diff --git a/apps/mobile/src/components/list/empty.js b/apps/mobile/src/components/list/empty.js
index 21e32e44e..3c188ca67 100644
--- a/apps/mobile/src/components/list/empty.js
+++ b/apps/mobile/src/components/list/empty.js
@@ -1,8 +1,8 @@
import React from 'react';
import { ActivityIndicator, useWindowDimensions, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
-import { useThemeStore } from '../../stores/theme';
-import { useSettingStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useSettingStore } from '../../stores/use-setting-store';
import { useTip } from '../../services/tip-manager';
import { COLORS_NOTE } from '../../utils/color-scheme';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/list/index.js b/apps/mobile/src/components/list/index.js
index e5f501e41..632e5d304 100644
--- a/apps/mobile/src/components/list/index.js
+++ b/apps/mobile/src/components/list/index.js
@@ -3,8 +3,7 @@ import { FlatList, RefreshControl, View } from 'react-native';
import { notesnook } from '../../../e2e/test.ids';
import { eSendEvent } from '../../services/event-manager';
import Sync from '../../services/sync';
-import { useUserStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import { eScrollEvent } from '../../utils/events';
import { tabBarRef } from '../../utils/global-refs';
@@ -56,7 +55,8 @@ const List = ({
placeholderData,
loading,
headerProps = {
- heading: 'Home'
+ heading: 'Home',
+ color: null
},
screen,
ListHeader,
@@ -65,11 +65,11 @@ const List = ({
const colors = useThemeStore(state => state.colors);
const scrollRef = useRef();
const [_loading, _setLoading] = useState(true);
- const syncing = useUserStore(state => state.syncing);
useEffect(() => {
let timeout = null;
if (!loading) {
+ console.log('LOADING ENDED');
timeout = setTimeout(
() => {
_setLoading(false);
@@ -77,6 +77,7 @@ const List = ({
listData.length === 0 ? 0 : 300
);
} else {
+ console.log('STILL LOADING');
_setLoading(true);
}
return () => {
@@ -149,7 +150,7 @@ const List = ({
colors={[colors.accent]}
progressBackgroundColor={colors.nav}
onRefresh={_onRefresh}
- refreshing={syncing}
+ refreshing={false}
/>
}
ListEmptyComponent={
@@ -169,9 +170,6 @@ const List = ({
) : (
<Header
title={headerProps.heading}
- paragraph={headerProps.paragraph}
- onPress={headerProps.onPress}
- icon={headerProps.icon}
color={headerProps.color}
type={type}
screen={screen}
diff --git a/apps/mobile/src/components/listitems/headers/header.js b/apps/mobile/src/components/listitems/headers/header.js
index 9e87c0dd4..35ff16d37 100644
--- a/apps/mobile/src/components/listitems/headers/header.js
+++ b/apps/mobile/src/components/listitems/headers/header.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { useMessageStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useMessageStore } from '../../../stores/use-message-store';
import { COLORS_NOTE } from '../../../utils/color-scheme';
import { Announcement } from '../../announcements/announcement';
import { Card } from '../../list/card';
diff --git a/apps/mobile/src/components/listitems/headers/notebookheader.js b/apps/mobile/src/components/listitems/headers/notebookheader.js
index a684c0edb..c38016182 100644
--- a/apps/mobile/src/components/listitems/headers/notebookheader.js
+++ b/apps/mobile/src/components/listitems/headers/notebookheader.js
@@ -1,7 +1,7 @@
import React, { useRef, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { useMenuStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useMenuStore } from '../../../stores/use-menu-store';
import { ToastEvent } from '../../../services/event-manager';
import { getTotalNotes } from '../../../utils';
import { db } from '../../../utils/database';
diff --git a/apps/mobile/src/components/listitems/headers/sectionheader.js b/apps/mobile/src/components/listitems/headers/sectionheader.js
index 6cd6b2a49..0c2dec957 100644
--- a/apps/mobile/src/components/listitems/headers/sectionheader.js
+++ b/apps/mobile/src/components/listitems/headers/sectionheader.js
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { TouchableOpacity, useWindowDimensions, View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { useSettingStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useSettingStore } from '../../../stores/use-setting-store';
import {
eSendEvent,
eSubscribeEvent,
diff --git a/apps/mobile/src/components/listitems/note/index.js b/apps/mobile/src/components/listitems/note/index.js
index 70e0c53e0..7fb3e8db3 100644
--- a/apps/mobile/src/components/listitems/note/index.js
+++ b/apps/mobile/src/components/listitems/note/index.js
@@ -3,8 +3,8 @@ import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../../e2e/test.ids';
-import { useThemeStore } from '../../../stores/theme';
-import { useSettingStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useSettingStore } from '../../../stores/use-setting-store';
import { eSendEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { COLORS_NOTE } from '../../../utils/color-scheme';
@@ -19,32 +19,33 @@ import Heading from '../../ui/typography/heading';
import Paragraph from '../../ui/typography/paragraph';
const navigateToTopic = topic => {
- let routeName = 'NotesPage';
- let params = { ...topic, menu: false, get: 'topics' };
- let headerState = {
- heading: topic.title,
- id: topic.id,
- type: topic.type
- };
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate(routeName, params, headerState);
+ Navigation.navigate(
+ {
+ name: 'NotesPage',
+ title: topic.title,
+ id: topic.id,
+ type: topic.type
+ },
+ { ...topic, menu: false, get: 'topics' }
+ );
};
function navigateToTag(item) {
- let _tag = db.tags.tag(item.id);
- if (!_tag) return;
- let params = {
- ..._tag,
- type: 'tag',
- get: 'tagged'
- };
-
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: '#' + _tag.title,
- id: _tag.id,
- type: _tag.type
- });
+ const tag = db.tags.tag(item.id);
+ if (!tag) return;
+ Navigation.navigate(
+ {
+ name: 'NotesPage',
+ title: '#' + tag.title,
+ id: tag.id,
+ type: tag.type
+ },
+ {
+ ...tag,
+ type: 'tag',
+ get: 'tagged'
+ }
+ );
}
const showActionSheet = item => {
diff --git a/apps/mobile/src/components/listitems/note/wrapper.js b/apps/mobile/src/components/listitems/note/wrapper.js
index eff886928..32851a8dc 100644
--- a/apps/mobile/src/components/listitems/note/wrapper.js
+++ b/apps/mobile/src/components/listitems/note/wrapper.js
@@ -1,7 +1,9 @@
import React from 'react';
import NoteItem from '.';
import { notesnook } from '../../../../e2e/test.ids';
-import { useEditorStore, useSelectionStore, useTrashStore } from '../../../stores/stores';
+import { useSelectionStore } from '../../../stores/use-selection-store';
+import { useTrashStore } from '../../../stores/use-trash-store';
+import { useEditorStore } from '../../../stores/use-editor-store';
import { DDS } from '../../../services/device-detection';
import { eSendEvent, openVault, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
@@ -66,14 +68,16 @@ export const openNote = async (item, isTrash, setSelectedItem) => {
negativeText: 'Delete',
positivePress: async () => {
await db.trash.restore(item.id);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Tags,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Trash
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Tags',
+ 'Notes',
+ 'Notebooks',
+ 'Favorites',
+ 'Trash',
+ 'TaggedNotes',
+ 'ColoredNotes',
+ 'TopicNotes'
+ );
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Restore successful',
diff --git a/apps/mobile/src/components/listitems/notebook/index.js b/apps/mobile/src/components/listitems/notebook/index.js
index 31ebf8004..e2e196ea4 100644
--- a/apps/mobile/src/components/listitems/notebook/index.js
+++ b/apps/mobile/src/components/listitems/notebook/index.js
@@ -2,8 +2,8 @@ import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../../e2e/test.ids';
-import { useThemeStore } from '../../../stores/theme';
-import { useSettingStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useSettingStore } from '../../../stores/use-setting-store';
import { eSendEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { getTotalNotes, history } from '../../../utils';
@@ -27,15 +27,15 @@ export const NotebookItem = ({ item, isTopic = false, notebookID, isTrash, dateB
const navigateToTopic = topic => {
if (history.selectedItemsList.length > 0) return;
- let routeName = 'NotesPage';
- let params = { ...topic, menu: false, get: 'topics' };
- let headerState = {
- heading: topic.title,
- id: topic.id,
- type: topic.type
- };
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate(routeName, params, headerState);
+ Navigation.navigate(
+ {
+ name: 'NotesPage',
+ title: topic.title,
+ id: topic.id,
+ type: topic.type
+ },
+ { ...topic, menu: false, get: 'topics' }
+ );
};
return (
diff --git a/apps/mobile/src/components/listitems/notebook/wrapper.js b/apps/mobile/src/components/listitems/notebook/wrapper.js
index 1d7d04415..0787bdca9 100644
--- a/apps/mobile/src/components/listitems/notebook/wrapper.js
+++ b/apps/mobile/src/components/listitems/notebook/wrapper.js
@@ -1,13 +1,15 @@
import React from 'react';
import { NotebookItem } from '.';
-import { eSendEvent, ToastEvent } from '../../../services/event-manager';
+import Notebook from '../../../screens/notebook';
+import { TopicNotes } from '../../../screens/notes/topic-notes';
+import { ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
-import { useSelectionStore, useTrashStore } from '../../../stores/stores';
+import { useSelectionStore } from '../../../stores/use-selection-store';
+import { useTrashStore } from '../../../stores/use-trash-store';
import { history } from '../../../utils';
-import { eOnNewTopicAdded, refreshNotesPage } from '../../../utils/events';
+import { db } from '../../../utils/database';
import { presentDialog } from '../../dialog/functions';
import SelectionWrapper from '../selection-wrapper';
-import { db } from '../../../utils/database';
export const NotebookWrapper = React.memo(
({ item, index, dateBy }) => {
@@ -30,14 +32,16 @@ export const NotebookWrapper = React.memo(
negativeText: 'Delete',
positivePress: async () => {
await db.trash.restore(item.id);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Tags,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Trash
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Tags',
+ 'Notes',
+ 'Notebooks',
+ 'Favorites',
+ 'Trash',
+ 'TaggedNotes',
+ 'ColoredNotes',
+ 'TopicNotes'
+ );
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Restore successful',
@@ -57,28 +61,11 @@ export const NotebookWrapper = React.memo(
});
return;
}
-
- let routeName = item.type === 'topic' ? 'NotesPage' : 'Notebook';
-
- let params =
- item.type === 'topic'
- ? { ...item, menu: false }
- : {
- menu: false,
- notebook: item,
- title: item.title
- };
- let headerState = {
- heading: item.title,
- id: item.id,
- type: item.type
- };
if (item.type === 'topic') {
- eSendEvent(refreshNotesPage, params);
+ TopicNotes.navigate(item, true);
} else {
- eSendEvent(eOnNewTopicAdded, params);
+ Notebook.navigate(item, true);
}
- Navigation.navigate(routeName, params, headerState);
};
return (
<SelectionWrapper
diff --git a/apps/mobile/src/components/listitems/selectionwrapper/actionstrip.js b/apps/mobile/src/components/listitems/selectionwrapper/actionstrip.js
index 196f5bd12..8e8df807e 100644
--- a/apps/mobile/src/components/listitems/selectionwrapper/actionstrip.js
+++ b/apps/mobile/src/components/listitems/selectionwrapper/actionstrip.js
@@ -1,16 +1,14 @@
import Clipboard from '@react-native-clipboard/clipboard';
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
-import Animated, { SlideInUp, SlideOutDown, useValue } from 'react-native-reanimated';
+import Animated, { SlideInUp, SlideOutDown } from 'react-native-reanimated';
import { openVault, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
-import {
- useMenuStore,
- useNotebookStore,
- useSelectionStore,
- useTrashStore
-} from '../../../stores/stores';
-import { useThemeStore } from '../../../stores/theme';
+import { useSelectionStore } from '../../../stores/use-selection-store';
+import { useTrashStore } from '../../../stores/use-trash-store';
+import { useMenuStore } from '../../../stores/use-menu-store';
+import { useNotebookStore } from '../../../stores/use-notebook-store';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { dWidth, getElevation, toTXT } from '../../../utils';
import { db } from '../../../utils/database';
import { deleteItems } from '../../../utils/functions';
@@ -28,18 +26,19 @@ export const ActionStrip = ({ note, setActionStrip }) => {
const [isPinnedToMenu, setIsPinnedToMenu] = useState(false);
const [width, setWidth] = useState(dWidth - 16);
- const opacity = useValue(0);
useEffect(() => {
if (note.type === 'note') return;
setIsPinnedToMenu(db.settings.isPinned(note.id));
}, []);
const updateNotes = () => {
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
};
const actions = [
@@ -155,13 +154,15 @@ export const ActionStrip = ({ note, setActionStrip }) => {
icon: 'delete-restore',
onPress: async () => {
await db.trash.restore(note.id);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Trash
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Trash',
+ 'Notebooks'
+ );
ToastEvent.show({
heading:
diff --git a/apps/mobile/src/components/listitems/selectionwrapper/backfill.js b/apps/mobile/src/components/listitems/selectionwrapper/backfill.js
index 4f76ce772..b6fe3921b 100644
--- a/apps/mobile/src/components/listitems/selectionwrapper/backfill.js
+++ b/apps/mobile/src/components/listitems/selectionwrapper/backfill.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { useEditorStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useEditorStore } from '../../../stores/use-editor-store';
import { hexToRGBA } from '../../../utils/color-scheme/utils';
export const Filler = ({ item, background }) => {
diff --git a/apps/mobile/src/components/listitems/selectionwrapper/index.js b/apps/mobile/src/components/listitems/selectionwrapper/index.js
index 0850d0416..c99b42c5d 100644
--- a/apps/mobile/src/components/listitems/selectionwrapper/index.js
+++ b/apps/mobile/src/components/listitems/selectionwrapper/index.js
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../services/event-manager';
-import { useSettingStore } from '../../../stores/stores';
-import { useThemeStore } from '../../../stores/theme';
+import { useSettingStore } from '../../../stores/use-setting-store';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { history } from '../../../utils';
import { PressableButton } from '../../ui/pressable';
import { ActionStrip } from './action-strip';
diff --git a/apps/mobile/src/components/listitems/selectionwrapper/selection.js b/apps/mobile/src/components/listitems/selectionwrapper/selection.js
index 926a019dc..bd68ee44e 100644
--- a/apps/mobile/src/components/listitems/selectionwrapper/selection.js
+++ b/apps/mobile/src/components/listitems/selectionwrapper/selection.js
@@ -1,9 +1,9 @@
import React, { useEffect, useState } from 'react';
import { TouchableOpacity, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { Actions } from '../../../stores/Actions';
-import { useSelectionStore } from '../../../stores/stores';
+import { useSelectionStore } from '../../../stores/use-selection-store';
import { SIZE } from '../../../utils/size';
export const SelectionIcon = ({ setActionStrip, item, compactMode }) => {
diff --git a/apps/mobile/src/components/listitems/tag/index.js b/apps/mobile/src/components/listitems/tag/index.js
index 558e4bcf5..7ccb49129 100644
--- a/apps/mobile/src/components/listitems/tag/index.js
+++ b/apps/mobile/src/components/listitems/tag/index.js
@@ -1,35 +1,21 @@
import React from 'react';
-import { useWindowDimensions, View } from 'react-native';
+import { View } from 'react-native';
import { notesnook } from '../../../../e2e/test.ids';
-import { PressableButton } from '../../ui/pressable';
-import { useThemeStore } from '../../../stores/theme';
-import { eSendEvent } from '../../../services/event-manager';
-import Navigation from '../../../services/navigation';
+import { TaggedNotes } from '../../../screens/notes/tagged';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { db } from '../../../utils/database';
-import { refreshNotesPage } from '../../../utils/events';
import { SIZE } from '../../../utils/size';
-import { IconButton } from '../../ui/icon-button';
import { Properties } from '../../properties';
+import { IconButton } from '../../ui/icon-button';
+import { PressableButton } from '../../ui/pressable';
import Heading from '../../ui/typography/heading';
import Paragraph from '../../ui/typography/paragraph';
const TagItem = React.memo(
({ item, index }) => {
const colors = useThemeStore(state => state.colors);
- const { fontScale } = useWindowDimensions();
const onPress = () => {
- let params = {
- ...item,
- type: 'tag',
- get: 'tagged'
- };
-
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: '#' + item.title,
- id: item.id,
- type: item.type
- });
+ TaggedNotes.navigate(item, true);
};
return (
diff --git a/apps/mobile/src/components/mergeconflicts/index.js b/apps/mobile/src/components/mergeconflicts/index.js
index 81d9cc35c..e1f56bcf8 100644
--- a/apps/mobile/src/components/mergeconflicts/index.js
+++ b/apps/mobile/src/components/mergeconflicts/index.js
@@ -5,7 +5,7 @@ import { Modal, Platform, SafeAreaView, Text, View } from 'react-native';
import Animated from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import WebView from 'react-native-webview';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { DDS } from '../../services/device-detection';
import {
eSendEvent,
@@ -156,11 +156,13 @@ const MergeConflicts = () => {
});
}
eSendEvent(refreshNotesPage);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
if (getNote()?.id === note.id) {
updateNoteInEditor();
}
diff --git a/apps/mobile/src/components/notehistory/index.js b/apps/mobile/src/components/notehistory/index.js
index 69b256529..09823163f 100644
--- a/apps/mobile/src/components/notehistory/index.js
+++ b/apps/mobile/src/components/notehistory/index.js
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import { Text, View } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { presentSheet } from '../../services/event-manager';
import { db } from '../../utils/database';
import { openLinkInBrowser } from '../../utils/functions';
diff --git a/apps/mobile/src/components/notehistory/preview.js b/apps/mobile/src/components/notehistory/preview.js
index a6706aca4..36b8c23b8 100644
--- a/apps/mobile/src/components/notehistory/preview.js
+++ b/apps/mobile/src/components/notehistory/preview.js
@@ -1,8 +1,8 @@
import React, { useRef } from 'react';
import { Alert, Platform, View } from 'react-native';
import WebView from 'react-native-webview';
-import { useThemeStore } from '../../stores/theme';
-import { useEditorStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useEditorStore } from '../../stores/use-editor-store';
import { eSendEvent, ToastEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
import { db } from '../../utils/database';
@@ -78,11 +78,13 @@ export default function NotePreview({ session, content }) {
}
eSendEvent(eCloseProgressDialog, 'note_history');
eSendEvent(eCloseProgressDialog);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
ToastEvent.show({
heading: 'Note restored successfully',
diff --git a/apps/mobile/src/components/premium/component.js b/apps/mobile/src/components/premium/component.js
index 4db72337a..684821036 100644
--- a/apps/mobile/src/components/premium/component.js
+++ b/apps/mobile/src/components/premium/component.js
@@ -1,8 +1,8 @@
import React, { useState } from 'react';
import { ActivityIndicator, ScrollView, View } from 'react-native';
import { LAUNCH_ROCKET } from '../../assets/images/assets';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
import { DDS } from '../../services/device-detection';
import { eSendEvent, presentSheet } from '../../services/event-manager';
import PremiumService from '../../services/premium';
diff --git a/apps/mobile/src/components/premium/expiring.js b/apps/mobile/src/components/premium/expiring.js
index c88ed6a10..cffd2f316 100644
--- a/apps/mobile/src/components/premium/expiring.js
+++ b/apps/mobile/src/components/premium/expiring.js
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium';
import { eOpenPremiumDialog, eOpenResultDialog, eOpenTrialEndingDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/premium/feature.js b/apps/mobile/src/components/premium/feature.js
index 6716d751b..f15ff763a 100644
--- a/apps/mobile/src/components/premium/feature.js
+++ b/apps/mobile/src/components/premium/feature.js
@@ -1,7 +1,7 @@
import React from 'react';
import { Text, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import Paragraph from '../ui/typography/paragraph';
import { ProTag } from './pro-tag';
diff --git a/apps/mobile/src/components/premium/group.js b/apps/mobile/src/components/premium/group.js
index 809946be2..0b607840f 100644
--- a/apps/mobile/src/components/premium/group.js
+++ b/apps/mobile/src/components/premium/group.js
@@ -1,6 +1,6 @@
import React from 'react';
import { ScrollView, View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
diff --git a/apps/mobile/src/components/premium/offer.js b/apps/mobile/src/components/premium/offer.js
index be0144000..3f2bd9765 100644
--- a/apps/mobile/src/components/premium/offer.js
+++ b/apps/mobile/src/components/premium/offer.js
@@ -1,6 +1,6 @@
import React from 'react';
import { Text } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import Paragraph from '../ui/typography/paragraph';
diff --git a/apps/mobile/src/components/premium/premiumtoast.js b/apps/mobile/src/components/premium/premiumtoast.js
index 15ef26a91..d8ac2ebb0 100644
--- a/apps/mobile/src/components/premium/premiumtoast.js
+++ b/apps/mobile/src/components/premium/premiumtoast.js
@@ -5,7 +5,7 @@ import { EditorWebView } from '../../screens/editor/Functions';
import tiny from '../../screens/editor/tiny/tiny';
import { DDS } from '../../services/device-detection';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { editing, getElevation } from '../../utils';
import { eCloseActionSheet, eOpenPremiumDialog, eShowGetPremium } from '../../utils/events';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/premium/pricingitem.js b/apps/mobile/src/components/premium/pricingitem.js
index e10ec5e5f..8b22c8e0f 100644
--- a/apps/mobile/src/components/premium/pricingitem.js
+++ b/apps/mobile/src/components/premium/pricingitem.js
@@ -1,6 +1,6 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { getElevation } from '../../utils';
import { SIZE } from '../../utils/size';
import { PressableButton } from '../ui/pressable';
diff --git a/apps/mobile/src/components/premium/pricingplans.js b/apps/mobile/src/components/premium/pricingplans.js
index 4103dbf29..fa3cf992c 100644
--- a/apps/mobile/src/components/premium/pricingplans.js
+++ b/apps/mobile/src/components/premium/pricingplans.js
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react';
import { ActivityIndicator, Platform, Text, View } from 'react-native';
import * as RNIap from 'react-native-iap';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium';
import { db } from '../../utils/database';
diff --git a/apps/mobile/src/components/premium/protag.js b/apps/mobile/src/components/premium/protag.js
index c4ad010a3..e375990fc 100644
--- a/apps/mobile/src/components/premium/protag.js
+++ b/apps/mobile/src/components/premium/protag.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import Paragraph from '../ui/typography/paragraph';
export const ProTag = ({ width, size, background }) => {
diff --git a/apps/mobile/src/components/properties/colortags.js b/apps/mobile/src/components/properties/colortags.js
index f90440a93..339c036cc 100644
--- a/apps/mobile/src/components/properties/colortags.js
+++ b/apps/mobile/src/components/properties/colortags.js
@@ -2,7 +2,8 @@ import React, { useState } from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids';
-import { useMenuStore, useSettingStore } from '../../stores/stores';
+import { useMenuStore } from '../../stores/use-menu-store';
+import { useSettingStore } from '../../stores/use-setting-store';
import { DDS } from '../../services/device-detection';
import { eSendEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
@@ -28,11 +29,13 @@ export const ColorTags = ({ item, close }) => {
let _note = db.notes.note(note.id).data;
setNote({ ..._note });
setColorNotes();
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
eSendEvent(refreshNotesPage);
};
diff --git a/apps/mobile/src/components/properties/datemeta.js b/apps/mobile/src/components/properties/datemeta.js
index b4970a153..dc24c5332 100644
--- a/apps/mobile/src/components/properties/datemeta.js
+++ b/apps/mobile/src/components/properties/datemeta.js
@@ -1,6 +1,6 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { timeConverter } from '../../utils/time';
import Paragraph from '../ui/typography/paragraph';
diff --git a/apps/mobile/src/components/properties/devmode.js b/apps/mobile/src/components/properties/devmode.js
index 81647e282..3b1cac019 100644
--- a/apps/mobile/src/components/properties/devmode.js
+++ b/apps/mobile/src/components/properties/devmode.js
@@ -1,7 +1,7 @@
import Clipboard from '@react-native-clipboard/clipboard';
import React from 'react';
import { View } from 'react-native';
-import { useSettingStore } from '../../stores/stores';
+import { useSettingStore } from '../../stores/use-setting-store';
import { ToastEvent } from '../../services/event-manager';
import { db } from '../../utils/database';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/properties/index.js b/apps/mobile/src/components/properties/index.js
index 0f7efb47e..c4154d2b2 100644
--- a/apps/mobile/src/components/properties/index.js
+++ b/apps/mobile/src/components/properties/index.js
@@ -1,6 +1,6 @@
import React from 'react';
import { Platform, ScrollView, View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { DDS } from '../../services/device-detection';
import { presentSheet } from '../../services/event-manager';
import { db } from '../../utils/database';
diff --git a/apps/mobile/src/components/properties/items.js b/apps/mobile/src/components/properties/items.js
index c85133f9a..c842d6167 100644
--- a/apps/mobile/src/components/properties/items.js
+++ b/apps/mobile/src/components/properties/items.js
@@ -2,8 +2,8 @@ import React from 'react';
import { View } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
-import { useSettingStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useSettingStore } from '../../stores/use-setting-store';
import { DDS } from '../../services/device-detection';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
diff --git a/apps/mobile/src/components/properties/notebooks.js b/apps/mobile/src/components/properties/notebooks.js
index 47bdd3ceb..351a6f8fb 100644
--- a/apps/mobile/src/components/properties/notebooks.js
+++ b/apps/mobile/src/components/properties/notebooks.js
@@ -1,7 +1,7 @@
import React from 'react';
import { ScrollView, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
import { db } from '../../utils/database';
@@ -42,34 +42,33 @@ export default function Notebooks({ note, close }) {
}
const navigateNotebook = id => {
- let routeName = 'Notebook';
- let item = db.notebooks.notebook(id).data;
+ let item = db.notebooks.notebook(id)?.data;
+ if (!item) return;
let params = {
menu: false,
notebook: item,
title: item.title
};
- let headerState = {
- heading: item.title,
+ let currentScreen = {
+ name: 'Notebook',
+ title: item.title,
id: item.id,
type: item.type
};
- eSendEvent(eOnNewTopicAdded, params);
- Navigation.navigate(routeName, params, headerState);
+ Navigation.navigate(currentScreen, params);
};
const navigateTopic = (id, notebookId) => {
- let routeName = 'NotesPage';
- let item = db.notebooks.notebook(notebookId).topics.topic(id)._topic;
-
+ let item = db.notebooks.notebook(notebookId)?.topics?.topic(id)?._topic;
+ if (!item) return;
let params = { ...item, menu: false };
- let headerState = {
- heading: item.title,
+ let currentScreen = {
+ name: 'NotesPage',
+ title: item.title,
id: item.id,
type: item.type
};
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate(routeName, params, headerState);
+ Navigation.navigate(currentScreen, params);
};
return !note.notebooks || note.notebooks.length === 0 ? null : (
diff --git a/apps/mobile/src/components/properties/synced.js b/apps/mobile/src/components/properties/synced.js
index c4557a13c..2ad2af330 100644
--- a/apps/mobile/src/components/properties/synced.js
+++ b/apps/mobile/src/components/properties/synced.js
@@ -1,8 +1,8 @@
import React from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
import { openLinkInBrowser } from '../../utils/functions';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
diff --git a/apps/mobile/src/components/properties/tags.js b/apps/mobile/src/components/properties/tags.js
index 35c5a7d83..348bcb6f1 100644
--- a/apps/mobile/src/components/properties/tags.js
+++ b/apps/mobile/src/components/properties/tags.js
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
import { db } from '../../utils/database';
@@ -64,13 +64,15 @@ const TagItem = ({ tag, close }) => {
type: 'tag',
get: 'tagged'
};
-
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: '#' + _tag.title,
- id: _tag.id,
- type: _tag.type
- });
+ Navigation.navigate(
+ {
+ name: 'NotesPage',
+ title: '#' + _tag.title,
+ id: _tag.id,
+ type: _tag.type
+ },
+ params
+ );
await sleep(300);
close();
};
diff --git a/apps/mobile/src/components/properties/topics.js b/apps/mobile/src/components/properties/topics.js
index 7cce9a4b4..4c3f24f24 100644
--- a/apps/mobile/src/components/properties/topics.js
+++ b/apps/mobile/src/components/properties/topics.js
@@ -1,24 +1,20 @@
import React from 'react';
import { View } from 'react-native';
-import { eSendEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
-import { refreshNotesPage } from '../../utils/events';
import { SIZE } from '../../utils/size';
import { Button } from '../ui/button';
export const Topics = ({ item, close }) => {
const open = topic => {
close();
-
- let routeName = 'NotesPage';
let params = { ...topic, menu: false, get: 'topics' };
- let headerState = {
- heading: topic.title,
+ let currentScreen = {
+ name: 'NotesPage',
+ title: topic.title,
id: topic.id,
type: topic.type
};
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate(routeName, params, headerState);
+ Navigation.navigate(currentScreen, params);
};
const renderItem = topic => (
diff --git a/apps/mobile/src/components/selectionheader/index.js b/apps/mobile/src/components/selectionheader/index.js
index 4588a2665..34dbf84dd 100644
--- a/apps/mobile/src/components/selectionheader/index.js
+++ b/apps/mobile/src/components/selectionheader/index.js
@@ -1,8 +1,8 @@
import React, { useEffect } from 'react';
import { BackHandler, Platform, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
-import { useThemeStore } from '../../stores/theme';
-import { useSelectionStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useSelectionStore } from '../../stores/use-selection-store';
import { eSendEvent, ToastEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
import { db } from '../../utils/database';
@@ -15,19 +15,24 @@ import { sleep } from '../../utils/time';
import { presentDialog } from '../dialog/functions';
import { IconButton } from '../ui/icon-button';
import Heading from '../ui/typography/heading';
+import useNavigationStore from '../../stores/use-navigation-store';
-export const SelectionHeader = React.memo(({ screen, type, extras }) => {
+export const SelectionHeader = React.memo(() => {
const colors = useThemeStore(state => state.colors);
-
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 currentScreen = useNavigationStore(state => state.currentScreen);
+ const screen = currentScreen.name;
const insets = useSafeAreaInsets();
useEffect(() => {
- tabBarRef.current?.setScrollEnabled(!selectionMode);
+ if (selectionMode) {
+ tabBarRef.current?.lock();
+ } else {
+ tabBarRef.current?.unlock();
+ }
}, [selectionMode]);
const addToFavorite = async () => {
@@ -35,11 +40,13 @@ export const SelectionHeader = React.memo(({ screen, type, extras }) => {
selectedItemsList.forEach(item => {
db.notes.note(item.id).favorite();
});
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notes,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
clearSelection();
}
};
@@ -51,14 +58,17 @@ export const SelectionHeader = React.memo(({ screen, type, extras }) => {
noteIds.push(item.id);
});
await db.trash.restore(...noteIds);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Tags,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Trash
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Trash',
+ 'Notebooks',
+ 'Tags'
+ );
+
clearSelection();
ToastEvent.show({
heading: 'Restore successful',
@@ -82,14 +92,16 @@ export const SelectionHeader = React.memo(({ screen, type, extras }) => {
noteIds.push(item.id);
});
await db.trash.delete(...noteIds);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Tags,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Trash
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Trash',
+ 'Notebooks',
+ 'Tags'
+ );
clearSelection();
}
},
@@ -111,7 +123,7 @@ export const SelectionHeader = React.memo(({ screen, type, extras }) => {
}
}, [selectionMode]);
- return !selectionMode || Navigation.getCurrentScreen() !== screen ? null : (
+ return !selectionMode ? null : (
<View
style={{
width: '100%',
@@ -205,23 +217,27 @@ export const SelectionHeader = React.memo(({ screen, type, extras }) => {
/>
)}
- {type === 'topic' ? (
+ {screen === 'TopicNotes' ? (
<IconButton
onPress={async () => {
if (selectedItemsList.length > 0) {
+ //TODO
+ let extras = {};
await db.notebooks
.notebook(extras.notebook)
.topics.topic(extras.topic)
.delete(...selectedItemsList.map(item => item.id));
eSendEvent(refreshNotesPage);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebook,
- Navigation.routeNames.Notebooks
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Notebooks',
+ 'Notebook'
+ );
clearSelection();
}
}}
diff --git a/apps/mobile/src/components/sheetprovider/index.js b/apps/mobile/src/components/sheetprovider/index.js
index 53494e84e..afd212718 100644
--- a/apps/mobile/src/components/sheetprovider/index.js
+++ b/apps/mobile/src/components/sheetprovider/index.js
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import { ActivityIndicator, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { editing } from '../../utils';
import { eCloseProgressDialog, eOpenProgressDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/sheets/addnotebook/index.js b/apps/mobile/src/components/sheets/addnotebook/index.js
index 2534b0545..e839b80e1 100644
--- a/apps/mobile/src/components/sheets/addnotebook/index.js
+++ b/apps/mobile/src/components/sheets/addnotebook/index.js
@@ -2,7 +2,7 @@ import React, { createRef } from 'react';
import { Keyboard, StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import { notesnook } from '../../../../e2e/test.ids';
-import { useMenuStore } from '../../../stores/stores';
+import { useMenuStore } from '../../../stores/use-menu-store';
import { DDS } from '../../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
@@ -198,11 +198,15 @@ export class AddNotebookSheet extends React.Component {
});
}
useMenuStore.getState().setMenuPins();
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.Notebook,
- Navigation.routeNames.NotesPage
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Notebooks',
+ 'Notebook'
+ );
+
this.setState({
loading: false
});
diff --git a/apps/mobile/src/components/sheets/addto/index.js b/apps/mobile/src/components/sheets/addto/index.js
index 30dace5c6..0885087b3 100644
--- a/apps/mobile/src/components/sheets/addto/index.js
+++ b/apps/mobile/src/components/sheets/addto/index.js
@@ -5,8 +5,9 @@ import { notesnook } from '../../../../e2e/test.ids';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import SearchService from '../../../services/search';
-import { useNotebookStore, useSelectionStore } from '../../../stores/stores';
-import { useThemeStore } from '../../../stores/theme';
+import { useSelectionStore } from '../../../stores/use-selection-store';
+import { useNotebookStore } from '../../../stores/use-notebook-store';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { getTotalNotes } from '../../../utils';
import { db } from '../../../utils/database';
import { eOpenMoveNoteDialog } from '../../../utils/events';
@@ -50,13 +51,15 @@ const AddToNotebookSheet = () => {
setVisible(false);
newNotebookTitle = null;
setNote(null);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notes,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Notebook,
- Navigation.routeNames.Notebooks
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Notebooks',
+ 'Notebook'
+ );
};
return !visible ? null : (
@@ -135,11 +138,14 @@ const MoveNoteComponent = ({ note }) => {
);
}
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
+
setNotebooks();
updateNoteExists();
SearchService.updateAndSearch();
diff --git a/apps/mobile/src/components/sheets/exportnotes/index.js b/apps/mobile/src/components/sheets/exportnotes/index.js
index 4dda5e305..d803819da 100644
--- a/apps/mobile/src/components/sheets/exportnotes/index.js
+++ b/apps/mobile/src/components/sheets/exportnotes/index.js
@@ -4,7 +4,7 @@ import FileViewer from 'react-native-file-viewer';
import Share from 'react-native-share';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../../e2e/test.ids';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { ToastEvent } from '../../../services/event-manager';
import Exporter from '../../../services/exporter';
import { getElevation } from '../../../utils';
diff --git a/apps/mobile/src/components/sheets/github/issue.js b/apps/mobile/src/components/sheets/github/issue.js
index bf90b8968..18ac71255 100644
--- a/apps/mobile/src/components/sheets/github/issue.js
+++ b/apps/mobile/src/components/sheets/github/issue.js
@@ -1,8 +1,8 @@
import Clipboard from '@react-native-clipboard/clipboard';
import React, { useRef, useState } from 'react';
import { Linking, Platform, Text, TextInput, View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
-import { useUserStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useUserStore } from '../../../stores/use-user-store';
import { eSendEvent, ToastEvent } from '../../../services/event-manager';
import PremiumService from '../../../services/premium';
import { APP_VERSION } from '../../../../version';
diff --git a/apps/mobile/src/components/sheets/managetags/index.js b/apps/mobile/src/components/sheets/managetags/index.js
index 83ff5c705..428f26856 100644
--- a/apps/mobile/src/components/sheets/managetags/index.js
+++ b/apps/mobile/src/components/sheets/managetags/index.js
@@ -1,8 +1,8 @@
import React, { useEffect, useRef, useState } from 'react';
import { ScrollView, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
-import { useTagStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useTagStore } from '../../../stores/use-tag-store';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { db } from '../../../utils/database';
@@ -113,11 +113,15 @@ const ManageTagsSheet = () => {
});
}
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Notebooks',
+ 'Notebook'
+ );
};
return !visible ? null : (
@@ -230,11 +234,13 @@ const TagItem = ({ tag, note, setNote }) => {
setNote(db.notes.note(note.id).data);
} catch (e) {}
setTimeout(() => {
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
}, 1);
};
diff --git a/apps/mobile/src/components/sheets/movenotes/movenote.tsx b/apps/mobile/src/components/sheets/movenotes/movenote.tsx
index 0c0b2e6d2..52cee4d7f 100644
--- a/apps/mobile/src/components/sheets/movenotes/movenote.tsx
+++ b/apps/mobile/src/components/sheets/movenotes/movenote.tsx
@@ -2,7 +2,7 @@ import React, { RefObject, useState } from 'react';
import { Platform, View } from 'react-native';
import ActionSheet from 'react-native-actions-sheet';
import { FlatList } from 'react-native-gesture-handler';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { eSendEvent, presentSheet, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { db } from '../../../utils/database';
@@ -82,13 +82,16 @@ export const MoveNotes = ({
}
await db.notebooks?.notebook(currentNotebook.id).topics.add(value);
setCurrentNotebook(db.notebooks?.notebook(currentNotebook.id).data);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.Notebook
- ]);
+
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Notebook',
+ 'Notebooks'
+ );
return true;
};
@@ -269,13 +272,15 @@ export const MoveNotes = ({
},
...selectedNoteIds
);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites,
- Navigation.routeNames.Notes,
- Navigation.routeNames.Notebooks,
- Navigation.routeNames.Notebook
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes',
+ 'Notebook',
+ 'Notebooks'
+ );
SearchService.updateAndSearch();
eSendEvent(eCloseProgressDialog);
}}
diff --git a/apps/mobile/src/components/sheets/newfeature/index.tsx b/apps/mobile/src/components/sheets/newfeature/index.tsx
index dd9e87bbd..ff6aeea16 100644
--- a/apps/mobile/src/components/sheets/newfeature/index.tsx
+++ b/apps/mobile/src/components/sheets/newfeature/index.tsx
@@ -3,7 +3,7 @@ import { View } from 'react-native';
import { APP_VERSION } from '../../../../version';
import { eSendEvent, presentSheet } from '../../../services/event-manager';
import SettingsService from '../../../services/settings';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { eCloseProgressDialog } from '../../../utils/events';
import { SIZE } from '../../../utils/size';
import { Button } from '../../ui/button';
diff --git a/apps/mobile/src/components/sheets/progress/index.tsx b/apps/mobile/src/components/sheets/progress/index.tsx
index 655e571fe..40d616dea 100644
--- a/apps/mobile/src/components/sheets/progress/index.tsx
+++ b/apps/mobile/src/components/sheets/progress/index.tsx
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
import * as ProgressBar from 'react-native-progress';
import { presentSheet } from '../../../services/event-manager';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import useSyncProgress from '../../../utils/hooks/use-sync-progress';
import { SIZE } from '../../../utils/size';
import Seperator from '../../ui/seperator';
diff --git a/apps/mobile/src/components/sheets/publishnote/index.js b/apps/mobile/src/components/sheets/publishnote/index.js
index 657ae478c..49c5199bb 100644
--- a/apps/mobile/src/components/sheets/publishnote/index.js
+++ b/apps/mobile/src/components/sheets/publishnote/index.js
@@ -2,8 +2,8 @@ import Clipboard from '@react-native-clipboard/clipboard';
import React, { useEffect, useRef, useState } from 'react';
import { ActivityIndicator, TouchableOpacity, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
-import { useAttachmentStore } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { useAttachmentStore } from '../../../stores/use-attachment-store';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
import { db } from '../../../utils/database';
@@ -76,11 +76,13 @@ const PublishNoteSheet = () => {
password: isLocked && passwordValue
});
setNote(db.notes.note(note.id)?.data);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notes,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
}
} catch (e) {
ToastEvent.show({
@@ -101,11 +103,13 @@ const PublishNoteSheet = () => {
if (note?.id) {
await db.monographs.unpublish(note.id);
setNote(db.notes.note(note.id)?.data);
- Navigation.setRoutesToUpdate([
- Navigation.routeNames.Notes,
- Navigation.routeNames.NotesPage,
- Navigation.routeNames.Favorites
- ]);
+ Navigation.queueRoutesForUpdate(
+ 'Notes',
+ 'Favorites',
+ 'ColoredNotes',
+ 'TaggedNotes',
+ 'TopicNotes'
+ );
}
} catch (e) {
ToastEvent.show({
diff --git a/apps/mobile/src/components/sheets/restoredata/index.js b/apps/mobile/src/components/sheets/restoredata/index.js
index cd33ac20a..175d35576 100644
--- a/apps/mobile/src/components/sheets/restoredata/index.js
+++ b/apps/mobile/src/components/sheets/restoredata/index.js
@@ -3,8 +3,8 @@ import { ActivityIndicator, Platform, View } from 'react-native';
import DocumentPicker from 'react-native-document-picker';
import { FlatList } from 'react-native-gesture-handler';
import * as ScopedStorage from 'react-native-scoped-storage';
-import { useThemeStore } from '../../../stores/theme';
-import { initialize } from '../../../stores/stores';
+import { useThemeStore } from '../../../stores/use-theme-store';
+import { initialize } from '../../../stores';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../../services/event-manager';
import { db } from '../../../utils/database';
import { MMKV } from '../../../utils/database/mmkv';
diff --git a/apps/mobile/src/components/sheets/sort/index.js b/apps/mobile/src/components/sheets/sort/index.js
index 27399cd5f..76d58472a 100644
--- a/apps/mobile/src/components/sheets/sort/index.js
+++ b/apps/mobile/src/components/sheets/sort/index.js
@@ -1,8 +1,8 @@
import React, { useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
import { eSendEvent } from '../../../services/event-manager';
import Navigation from '../../../services/navigation';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { GROUP, SORT } from '../../../utils/constants';
import { db } from '../../../utils/database';
import { refreshNotesPage } from '../../../utils/events';
@@ -11,7 +11,6 @@ import { SIZE } from '../../../utils/size';
import { Button } from '../../ui/button';
import Seperator from '../../ui/seperator';
import Heading from '../../ui/typography/heading';
-import Animated, { Layout } from 'react-native-reanimated';
const Sort = ({ type, screen }) => {
const colors = useThemeStore(state => state.colors);
@@ -23,7 +22,7 @@ const Sort = ({ type, screen }) => {
layoutmanager.withSpringAnimation(600);
setGroupOptions(_groupOptions);
setTimeout(() => {
- Navigation.setRoutesToUpdate([screen]);
+ Navigation.queueRoutesForUpdate(screen);
eSendEvent('groupOptionsUpdate');
eSendEvent(refreshNotesPage);
}, 1);
diff --git a/apps/mobile/src/components/sheets/update/index.js b/apps/mobile/src/components/sheets/update/index.js
index a5de56def..c657cfeab 100644
--- a/apps/mobile/src/components/sheets/update/index.js
+++ b/apps/mobile/src/components/sheets/update/index.js
@@ -1,7 +1,7 @@
import React from 'react';
import { Linking, View } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { STORE_LINK } from '../../../utils/constants';
import { SIZE } from '../../../utils/size';
import { Button } from '../../ui/button';
diff --git a/apps/mobile/src/components/sidemenu/colorsection.js b/apps/mobile/src/components/sidemenu/colorsection.js
index 81654db80..1c130f477 100644
--- a/apps/mobile/src/components/sidemenu/colorsection.js
+++ b/apps/mobile/src/components/sidemenu/colorsection.js
@@ -1,12 +1,12 @@
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
-import { useMenuStore, useNoteStore } from '../../stores/stores';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useMenuStore } from '../../stores/use-menu-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { COLORS_NOTE } from '../../utils/color-scheme';
import { db } from '../../utils/database';
-import { refreshNotesPage } from '../../utils/events';
import { normalize, SIZE } from '../../utils/size';
import { presentDialog } from '../dialog/functions';
import { PressableButton } from '../ui/pressable';
@@ -40,10 +40,11 @@ const ColorItem = React.memo(
const [headerTextState, setHeaderTextState] = useState(null);
alias = db.colors.alias(item.id) || '';
- const onHeaderStateChange = event => {
+ const onHeaderStateChange = state => {
setTimeout(() => {
- if (event.id === item.id) {
- setHeaderTextState(event);
+ let id = state.currentScreen?.id;
+ if (id === item.id) {
+ setHeaderTextState({ id: state.currentScreen.id });
} else {
if (headerTextState !== null) {
setHeaderTextState(null);
@@ -53,9 +54,9 @@ const ColorItem = React.memo(
};
useEffect(() => {
- eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ let unsub = useNavigationStore.subscribe(onHeaderStateChange);
return () => {
- eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ unsub();
};
}, [headerTextState]);
@@ -66,14 +67,19 @@ const ColorItem = React.memo(
menu: true,
get: 'colored'
};
+ Navigation.navigate(
+ {
+ name: 'NotesPage',
+ title: alias.slice(0, 1).toUpperCase() + alias.slice(1),
+ id: item.id,
+ type: 'color'
+ },
+ params
+ );
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: alias.slice(0, 1).toUpperCase() + alias.slice(1),
- id: item.id,
- type: 'color'
+ setImmediate(() => {
+ Navigation.closeDrawer();
});
- Navigation.closeDrawer();
};
const onLongPress = () => {
diff --git a/apps/mobile/src/components/sidemenu/index.js b/apps/mobile/src/components/sidemenu/index.js
index fde61a0a4..2026e6af8 100644
--- a/apps/mobile/src/components/sidemenu/index.js
+++ b/apps/mobile/src/components/sidemenu/index.js
@@ -5,8 +5,10 @@ import { notesnook } from '../../../e2e/test.ids';
import Settings from '../../screens/settings';
import { DDS } from '../../services/device-detection';
import { eSendEvent } from '../../services/event-manager';
-import { useSettingStore, useUserStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useUserStore } from '../../stores/use-user-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import umami from '../../utils/analytics';
import { toggleDarkMode } from '../../utils/color-scheme/utils';
import { MenuItemsList, SUBSCRIPTION_STATUS } from '../../utils/constants';
@@ -22,7 +24,7 @@ export const SideMenu = React.memo(
const deviceMode = useSettingStore(state => state.deviceMode);
const insets = useSafeAreaInsets();
const subscriptionType = useUserStore(state => state.user?.subscription?.type);
- console.log(subscriptionType);
+ const loading = useNoteStore(state => state.loading);
const noTextMode = false;
const BottomItemsList = [
@@ -63,7 +65,7 @@ export const SideMenu = React.memo(
[]
);
- return (
+ return !loading ? (
<View
style={{
height: '100%',
@@ -129,7 +131,7 @@ export const SideMenu = React.memo(
</View>
</View>
</View>
- );
+ ) : null;
},
() => true
);
diff --git a/apps/mobile/src/components/sidemenu/menuitem.js b/apps/mobile/src/components/sidemenu/menuitem.js
index 1007b64d3..aff8df38a 100644
--- a/apps/mobile/src/components/sidemenu/menuitem.js
+++ b/apps/mobile/src/components/sidemenu/menuitem.js
@@ -2,9 +2,9 @@ import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import ToggleSwitch from 'toggle-switch-react-native';
-import { useThemeStore } from '../../stores/theme';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { normalize, SIZE } from '../../utils/size';
import { Button } from '../ui/button';
import { PressableButton } from '../ui/pressable';
@@ -14,34 +14,30 @@ import Paragraph from '../ui/typography/paragraph';
export const MenuItem = React.memo(
({ item, index, testID, rightBtn }) => {
const colors = useThemeStore(state => state.colors);
- const [headerTextState, setHeaderTextState] = useState(null);
- let isFocused = headerTextState?.id === item.name.toLowerCase() + '_navigation';
+ const [headerTextState, setHeaderTextState] = useState(
+ useNavigationStore.getState().currentScreen
+ );
+ const screenId = item.name.toLowerCase() + '_navigation';
+ let isFocused = headerTextState?.id === screenId;
- const _onPress = event => {
+ const _onPress = () => {
if (item.func) {
- console.log('item.func called');
item.func();
} else {
- Navigation.navigate(
- item.name,
- {
- menu: true
- },
- {
- heading: item.name,
- id: item.name.toLowerCase() + '_navigation'
- }
- );
+ Navigation.navigate({ name: item.name }, { menu: true });
}
if (item.close) {
- Navigation.closeDrawer();
+ setImmediate(() => {
+ Navigation.closeDrawer();
+ });
}
};
- const onHeaderStateChange = event => {
+ const onHeaderStateChange = state => {
setTimeout(() => {
- if (event.id === item.name.toLowerCase() + '_navigation') {
- setHeaderTextState(event);
+ let id = state.currentScreen?.id;
+ if (id === screenId) {
+ setHeaderTextState({ id: state.currentScreen.id });
} else {
if (headerTextState !== null) {
setHeaderTextState(null);
@@ -51,9 +47,9 @@ export const MenuItem = React.memo(
};
useEffect(() => {
- eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ let unsub = useNavigationStore.subscribe(onHeaderStateChange);
return () => {
- eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ unsub();
};
}, [headerTextState]);
diff --git a/apps/mobile/src/components/sidemenu/pinnedsection.js b/apps/mobile/src/components/sidemenu/pinnedsection.js
index e50045a04..650481b7b 100644
--- a/apps/mobile/src/components/sidemenu/pinnedsection.js
+++ b/apps/mobile/src/components/sidemenu/pinnedsection.js
@@ -1,21 +1,26 @@
import React, { useEffect, useRef, useState } from 'react';
import { FlatList, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
-import { useMenuStore, useNoteStore } from '../../stores/stores';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import { eSendEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useMenuStore } from '../../stores/use-menu-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import { eOnNewTopicAdded, refreshNotesPage } from '../../utils/events';
import { normalize, SIZE } from '../../utils/size';
+import { Properties } from '../properties';
import { Button } from '../ui/button';
import { Notice } from '../ui/notice';
import { PressableButton } from '../ui/pressable';
-import { Properties } from '../properties';
import Seperator from '../ui/seperator';
import SheetWrapper from '../ui/sheet';
import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph';
+import { TaggedNotes } from '../../screens/notes/tagged';
+import { TopicNotes } from '../../screens/notes/topic-notes';
+import Notebook from '../../screens/notebook';
export const TagsSection = React.memo(
() => {
@@ -30,42 +35,16 @@ export const TagsSection = React.memo(
}, [loading]);
const onPress = item => {
- let params = {};
if (item.type === 'notebook') {
- params = {
- notebook: item,
- title: item.title,
- menu: true
- };
- eSendEvent(eOnNewTopicAdded, params);
- Navigation.navigate('Notebook', params, {
- heading: item.title,
- id: item.id,
- type: item.type
- });
+ Notebook.navigate(item);
} else if (item.type === 'tag') {
- params = {
- ...item,
- type: 'tag',
- menu: true,
- get: 'tagged'
- };
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: '#' + db.tags.alias(item.id),
- id: item.id,
- type: item.type
- });
+ TaggedNotes.navigate(item);
} else {
- params = { ...item, menu: true, get: 'topics' };
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: item.title,
- id: item.id,
- type: item.type
- });
+ TopicNotes.navigate(item);
}
- Navigation.closeDrawer();
+ setImmediate(() => {
+ Navigation.closeDrawer();
+ });
};
const renderItem = ({ item, index }) => {
let alias = item ? (item.type === 'tag' ? db.tags.alias(item.title) : item.title) : null;
@@ -112,10 +91,13 @@ export const PinItem = React.memo(
const color = headerTextState?.id === item.id ? colors.accent : colors.pri;
const fwdRef = useRef();
- const onHeaderStateChange = event => {
+ const onHeaderStateChange = state => {
setTimeout(() => {
- if (event.id === item.id) {
- setHeaderTextState(event);
+ let id = state.currentScreen?.id;
+ if (id === item.id) {
+ setHeaderTextState({
+ id: state.currentScreen.id
+ });
} else {
if (headerTextState !== null) {
setHeaderTextState(null);
@@ -125,9 +107,9 @@ export const PinItem = React.memo(
};
useEffect(() => {
- eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ let unsub = useNavigationStore.subscribe(onHeaderStateChange);
return () => {
- eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ unsub();
};
}, [headerTextState]);
diff --git a/apps/mobile/src/components/sidemenu/userstatus.js b/apps/mobile/src/components/sidemenu/userstatus.js
index 4bcb91c2d..df879700f 100644
--- a/apps/mobile/src/components/sidemenu/userstatus.js
+++ b/apps/mobile/src/components/sidemenu/userstatus.js
@@ -2,8 +2,8 @@ import React from 'react';
import { ActivityIndicator, Platform, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../stores/theme';
-import { useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
import { eSendEvent } from '../../services/event-manager';
import Sync from '../../services/sync';
import { eOpenLoginDialog } from '../../utils/events';
diff --git a/apps/mobile/src/components/tabs/index.js b/apps/mobile/src/components/tabs/index.js
index 9a72747da..3a4d8c238 100644
--- a/apps/mobile/src/components/tabs/index.js
+++ b/apps/mobile/src/components/tabs/index.js
@@ -22,7 +22,6 @@ export default class Tabs extends Component {
this.lastOffset = this.props.offsets.a;
this.locked = false;
}
-
renderItem = ({ item, index }) => this.props.items[index];
onMoveShouldSetResponder = event => {
diff --git a/apps/mobile/src/components/tabs/new.tsx b/apps/mobile/src/components/tabs/new.tsx
new file mode 100644
index 000000000..918a6fb09
--- /dev/null
+++ b/apps/mobile/src/components/tabs/new.tsx
@@ -0,0 +1,244 @@
+import React, { forwardRef, useImperativeHandle } from 'react';
+import { ViewProps } from 'react-native';
+import { Gesture, GestureDetector } from 'react-native-gesture-handler';
+import Animated, {
+ runOnJS,
+ useAnimatedReaction,
+ useAnimatedStyle,
+ useSharedValue,
+ withSpring,
+ withTiming
+} from 'react-native-reanimated';
+
+interface TabProps extends ViewProps {
+ dimensions: { width: number; height: number };
+ widths: { a: number; b: number; c: number };
+ onChangeTab: (data: { i: number; from: number }) => void;
+ onScroll: (offset: number) => void;
+ enabled: boolean;
+ onDrawerStateChange: (state: boolean) => void;
+}
+
+export interface TabsRef {
+ goToPage: (page: number) => void;
+ goToIndex: (index: number) => 0 | undefined;
+ unlock: () => boolean;
+ lock: () => boolean;
+ openDrawer: () => void;
+ closeDrawer: () => void;
+ page: number;
+ setScrollEnabled: () => true;
+}
+
+export const NewTabs = forwardRef<TabsRef, TabProps>(
+ (
+ { children, dimensions, widths, onChangeTab, onScroll, enabled, onDrawerStateChange }: TabProps,
+ ref
+ ) => {
+ const translateX = useSharedValue(widths ? widths.a : 0);
+ const startX = useSharedValue(0);
+ const currentTab = useSharedValue(1);
+ const previousTab = useSharedValue(1);
+ const isDrawerOpen = useSharedValue(false);
+ const gestureStartValue = useSharedValue({
+ x: 0,
+ y: 0
+ });
+ const locked = useSharedValue(false);
+ const forcedLock = useSharedValue(false);
+ const containerWidth = widths ? widths.a + widths.b + widths.c : dimensions.width;
+ const drawerPosition = 0;
+ const homePosition = widths.a;
+ const editorPosition = widths.a + widths.b;
+
+ useImperativeHandle(
+ ref,
+ (): TabsRef => ({
+ goToPage: (page: number) => {
+ page = page + 1;
+ if (page === 1) {
+ onDrawerStateChange(false);
+ console.log('coming here');
+ translateX.value = withTiming(homePosition);
+ currentTab.value = 1;
+ } else if (page === 2) {
+ onDrawerStateChange(false);
+ translateX.value = withTiming(editorPosition);
+ currentTab.value = 2;
+ }
+ },
+ goToIndex: (index: number) => {
+ console.log('index', index);
+ if (index === 0) {
+ onDrawerStateChange(true);
+ return (translateX.value = withSpring(0));
+ }
+ if (index === 1) {
+ translateX.value = withTiming(homePosition);
+ currentTab.value = 1;
+ } else if (index === 2) {
+ translateX.value = withTiming(editorPosition);
+ currentTab.value = 2;
+ }
+ },
+ unlock: () => {
+ forcedLock.value = false;
+ console.log('forced lock status', forcedLock.value);
+ return false;
+ },
+ lock: () => {
+ forcedLock.value = true;
+ console.log('forced lock status', forcedLock.value);
+ return true;
+ },
+ openDrawer: () => {
+ translateX.value = withSpring(drawerPosition, {
+ mass: 0.5
+ });
+ onDrawerStateChange(true);
+ },
+ closeDrawer: () => {
+ translateX.value = withTiming(homePosition);
+ onDrawerStateChange(false);
+ },
+ page: currentTab.value,
+ setScrollEnabled: () => true
+ }),
+ []
+ );
+
+ useAnimatedReaction(
+ () => currentTab.value,
+ result => {
+ if (onChangeTab) {
+ runOnJS(onChangeTab)({ i: result, from: previousTab.value });
+ }
+ },
+ []
+ );
+
+ useAnimatedReaction(
+ () => translateX.value,
+ value => {
+ runOnJS(onScroll)(value);
+ },
+ []
+ );
+
+ const gesture = Gesture.Pan()
+ .maxPointers(1)
+ .enabled(enabled)
+ .activeOffsetX([-20, 20])
+ .failOffsetY([-10, 10])
+ .onBegin(event => {
+ locked.value = false;
+ gestureStartValue.value = {
+ x: event.absoluteX,
+ y: event.absoluteY
+ };
+ })
+ .onStart(event => {
+ let diffX = gestureStartValue.value.x - event.absoluteX;
+ let diffY = gestureStartValue.value.y - event.absoluteY;
+
+ let vx = event.velocityX;
+ let vy = event.velocityY;
+
+ if (vx < 0) vx = vx * -1;
+ if (vy < 0) vy = vy * -1;
+
+ console.log(event.velocityX, event.velocityY, diffX, diffY);
+ console.log('diff: ', vx / vy, 'lock: ', vx / vy < 5, vy > vx);
+ // if vy is greater than vx, user is swiping vertically. lock swiping.
+ if (vy > vx) locked.value = true;
+ // if dividend of vx/vy is less than 4, user is swiping diagonally. lock swiping
+ if (vx / vy < 4) locked.value = true;
+ startX.value = translateX.value;
+ })
+ .onChange(event => {
+ if (locked.value || forcedLock.value) return;
+ let value = translateX.value + event.changeX * -1;
+ if (value < 0 || currentTab.value === 2 || value > editorPosition) return;
+ translateX.value = value;
+ })
+ .onEnd(event => {
+ if (currentTab.value === 2) return;
+ let velocityX = event.velocityX < 0 ? event.velocityX * -1 : event.velocityX;
+ let isSwipeLeft = startX.value > translateX.value;
+ let finalValue = isSwipeLeft
+ ? translateX.value - velocityX / 40.0
+ : translateX.value + velocityX / 40.0;
+
+ const animationConfig = {
+ velocity: event.velocityX,
+ overshootClamping: true,
+ stiffness: 200,
+ mass: 0.1
+ };
+
+ if (finalValue < homePosition) {
+ if (isSwipeLeft && finalValue < homePosition - 150) {
+ translateX.value = withSpring(0, animationConfig);
+ isDrawerOpen.value = true;
+ currentTab.value = 1;
+ runOnJS(onDrawerStateChange)(true);
+ return;
+ } else if (!isSwipeLeft && finalValue > 100) {
+ translateX.value = withSpring(homePosition, animationConfig);
+ isDrawerOpen.value = false;
+ currentTab.value = 1;
+ runOnJS(onDrawerStateChange)(false);
+ return;
+ } else if (!isSwipeLeft && finalValue < 150) {
+ translateX.value = withSpring(0, animationConfig);
+ isDrawerOpen.value = true;
+ currentTab.value = 1;
+ return;
+ }
+ }
+
+ if (finalValue > homePosition && currentTab.value === 1) {
+ const sizeOfEditorInView = finalValue - homePosition;
+ if (!isSwipeLeft && sizeOfEditorInView > 150) {
+ translateX.value = withSpring(editorPosition, animationConfig);
+ currentTab.value = 2;
+ isDrawerOpen.value = false;
+ return;
+ }
+ }
+
+ runOnJS(onDrawerStateChange)(false);
+ translateX.value = withSpring(homePosition, animationConfig);
+ currentTab.value = 1;
+ startX.value = 0;
+ });
+
+ const animatedStyles = useAnimatedStyle(() => {
+ return {
+ transform: [
+ {
+ translateX: translateX.value * -1
+ }
+ ]
+ };
+ }, []);
+ return (
+ <GestureDetector gesture={gesture}>
+ <Animated.View
+ removeClippedSubviews={false}
+ collapsable={false}
+ style={[
+ {
+ flex: 1,
+ width: containerWidth,
+ flexDirection: 'row'
+ },
+ animatedStyles
+ ]}
+ >
+ {children}
+ </Animated.View>
+ </GestureDetector>
+ );
+ }
+);
diff --git a/apps/mobile/src/components/tip/index.tsx b/apps/mobile/src/components/tip/index.tsx
index 01dfd0347..4ee8ef14c 100644
--- a/apps/mobile/src/components/tip/index.tsx
+++ b/apps/mobile/src/components/tip/index.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { Image, TextStyle, View, ViewStyle } from 'react-native';
import { eSendEvent, presentSheet } from '../../services/event-manager';
import { TTip } from '../../services/tip-manager';
-import { ThemeStore, useThemeStore } from '../../stores/theme';
+import { ThemeStore, useThemeStore } from '../../stores/use-theme-store';
import { MMKV } from '../../utils/database/mmkv';
import { eCloseProgressDialog } from '../../utils/events';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/toast/index.js b/apps/mobile/src/components/toast/index.js
index d9d038f30..9e8e2f7ec 100644
--- a/apps/mobile/src/components/toast/index.js
+++ b/apps/mobile/src/components/toast/index.js
@@ -6,7 +6,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { notesnook } from '../../../e2e/test.ids';
import { DDS } from '../../services/device-detection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { getElevation } from '../../utils';
import { eHideToast, eShowToast } from '../../utils/events';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/components/ui/button/index.tsx b/apps/mobile/src/components/ui/button/index.tsx
index e35287660..7cb7914a4 100644
--- a/apps/mobile/src/components/ui/button/index.tsx
+++ b/apps/mobile/src/components/ui/button/index.tsx
@@ -1,16 +1,8 @@
import React from 'react';
import { ActivityIndicator, ColorValue, TextStyle } from 'react-native';
-import Animated, {
- FadeIn,
- FadeOut,
- Layout,
- LightSpeedInLeft,
- SlideInLeft,
- SlideInRight,
- SlideOutLeft
-} from 'react-native-reanimated';
+import Animated, { FadeIn, FadeOut, Layout, LightSpeedInLeft } from 'react-native-reanimated';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { showTooltip, TOOLTIP_POSITIONS } from '../../../utils';
import { BUTTON_TYPES } from '../../../utils/constants';
import { SIZE } from '../../../utils/size';
@@ -130,6 +122,7 @@ export const Button = ({
{!title ? null : (
<Component
layout={Layout}
+ animated={true}
color={textColor}
size={fontSize}
numberOfLines={1}
diff --git a/apps/mobile/src/components/ui/iconbutton/index.tsx b/apps/mobile/src/components/ui/iconbutton/index.tsx
index 022d8fb4f..d6f8983f3 100644
--- a/apps/mobile/src/components/ui/iconbutton/index.tsx
+++ b/apps/mobile/src/components/ui/iconbutton/index.tsx
@@ -1,7 +1,15 @@
import React from 'react';
import { ColorValue, GestureResponderEvent, ViewStyle } from 'react-native';
+import Animated, {
+ FadeIn,
+ FadeOut,
+ FlipInEasyX,
+ FlipInEasyY,
+ FlipOutEasyY,
+ Layout
+} from 'react-native-reanimated';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { showTooltip, TOOLTIP_POSITIONS } from '../../../utils';
import { hexToRGBA, RGB_Linear_Shade } from '../../../utils/color-scheme/utils';
import { SIZE } from '../../../utils/size';
@@ -21,6 +29,7 @@ interface IconButtonProps extends PressableButtonProps {
iconStyle?: ViewStyle;
}
+const AnimatedIcon = Animated.createAnimatedComponent(Icon);
export const IconButton = ({
onPress,
name,
@@ -68,7 +77,8 @@ export const IconButton = ({
...customStyle
}}
>
- <Icon
+ <AnimatedIcon
+ layout={Layout}
name={name}
style={iconStyle}
color={
diff --git a/apps/mobile/src/components/ui/input/index.tsx b/apps/mobile/src/components/ui/input/index.tsx
index 45b72a8d0..1fa49fb15 100644
--- a/apps/mobile/src/components/ui/input/index.tsx
+++ b/apps/mobile/src/components/ui/input/index.tsx
@@ -10,7 +10,7 @@ import {
} from 'react-native';
import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import {
ERRORS_LIST,
validateEmail,
diff --git a/apps/mobile/src/components/ui/notice/index.tsx b/apps/mobile/src/components/ui/notice/index.tsx
index f9384ef60..2d69f43a8 100644
--- a/apps/mobile/src/components/ui/notice/index.tsx
+++ b/apps/mobile/src/components/ui/notice/index.tsx
@@ -1,6 +1,6 @@
import React from 'react';
import { View } from 'react-native';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { SIZE } from '../../../utils/size';
import { IconButton } from '../icon-button';
import Paragraph from '../typography/paragraph';
diff --git a/apps/mobile/src/components/ui/pressable/index.tsx b/apps/mobile/src/components/ui/pressable/index.tsx
index ce4f30916..2f8f36f8a 100644
--- a/apps/mobile/src/components/ui/pressable/index.tsx
+++ b/apps/mobile/src/components/ui/pressable/index.tsx
@@ -8,7 +8,7 @@ import {
ViewStyle
} from 'react-native';
import Animated from 'react-native-reanimated';
-import { ThemeStore, useThemeStore } from '../../../stores/theme';
+import { ThemeStore, useThemeStore } from '../../../stores/use-theme-store';
import { hexToRGBA, RGB_Linear_Shade } from '../../../utils/color-scheme/utils';
import { BUTTON_TYPES } from '../../../utils/constants';
import { br } from '../../../utils/size';
diff --git a/apps/mobile/src/components/ui/sheet/index.js b/apps/mobile/src/components/ui/sheet/index.js
index c7eca7e5a..f7a8d45a5 100644
--- a/apps/mobile/src/components/ui/sheet/index.js
+++ b/apps/mobile/src/components/ui/sheet/index.js
@@ -2,8 +2,8 @@ import React from 'react';
import { Platform, View } from 'react-native';
import ActionSheet from 'react-native-actions-sheet';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
-import { useSettingStore } from '../../../stores/stores';
-import { useThemeStore } from '../../../stores/theme';
+import { useSettingStore } from '../../../stores/use-setting-store';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { PremiumToast } from '../../premium/premium-toast';
import { Toast } from '../../toast';
import { BouncingView } from '../transitions/bouncing-view';
diff --git a/apps/mobile/src/components/ui/transitions/bouncingview.js b/apps/mobile/src/components/ui/transitions/bouncingview.js
index 57d3c0dad..5ba82ff2a 100644
--- a/apps/mobile/src/components/ui/transitions/bouncingview.js
+++ b/apps/mobile/src/components/ui/transitions/bouncingview.js
@@ -32,10 +32,6 @@ export const BouncingView = ({
duration: duration,
easing: Easing.elastic(1)
});
- return () => {
- if (!animated) return;
- scale.value = initialScale;
- };
}, []);
return <Animated.View style={[style, animatedStyle]}>{children}</Animated.View>;
diff --git a/apps/mobile/src/components/ui/typography/heading.tsx b/apps/mobile/src/components/ui/typography/heading.tsx
index 6a77c7973..2df48f7cd 100644
--- a/apps/mobile/src/components/ui/typography/heading.tsx
+++ b/apps/mobile/src/components/ui/typography/heading.tsx
@@ -1,23 +1,25 @@
-import React from 'react';
+import React, { useMemo } from 'react';
import { Platform, TextProps } from 'react-native';
import { Text } from 'react-native';
import Animated, { ComplexAnimationBuilder, Layout } from 'react-native-reanimated';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { SIZE } from '../../../utils/size';
interface HeadingProps extends TextProps {
color?: string;
size?: number;
layout?: ComplexAnimationBuilder;
+ animated?: boolean;
}
const AnimatedText = Animated.createAnimatedComponent(Text);
-const Heading = ({ color, size = SIZE.xl, style, ...restProps }: HeadingProps) => {
+const Heading = ({ color, size = SIZE.xl, style, animated, ...restProps }: HeadingProps) => {
const colors = useThemeStore(state => state.colors);
+ const Component = useMemo(() => (animated ? AnimatedText : Text), [animated]);
return (
- <AnimatedText
+ <Component
layout={restProps.layout || Layout}
allowFontScaling={true}
maxFontSizeMultiplier={1}
@@ -31,7 +33,7 @@ const Heading = ({ color, size = SIZE.xl, style, ...restProps }: HeadingProps) =
},
style
]}
- ></AnimatedText>
+ ></Component>
);
};
diff --git a/apps/mobile/src/components/ui/typography/paragraph.tsx b/apps/mobile/src/components/ui/typography/paragraph.tsx
index 2f02f2b2d..9ab660e7f 100644
--- a/apps/mobile/src/components/ui/typography/paragraph.tsx
+++ b/apps/mobile/src/components/ui/typography/paragraph.tsx
@@ -1,21 +1,23 @@
-import React from 'react';
+import React, { useMemo } from 'react';
import { Text, TextProps } from 'react-native';
import Animated, { ComplexAnimationBuilder, Layout } from 'react-native-reanimated';
-import { useThemeStore } from '../../../stores/theme';
+import { useThemeStore } from '../../../stores/use-theme-store';
import { SIZE } from '../../../utils/size';
interface ParagraphProps extends TextProps {
color?: string;
size?: number;
layout?: ComplexAnimationBuilder;
+ animated?: boolean;
}
const AnimatedText = Animated.createAnimatedComponent(Text);
-const Paragraph = ({ color, size = SIZE.sm, style, ...restProps }: ParagraphProps) => {
+const Paragraph = ({ color, size = SIZE.sm, style, animated, ...restProps }: ParagraphProps) => {
const colors = useThemeStore(state => state.colors);
+ const Component = useMemo(() => (animated ? AnimatedText : Text), [animated]);
return (
- <AnimatedText
+ <Component
layout={restProps.layout || Layout}
allowFontScaling
maxFontSizeMultiplier={1}
@@ -29,7 +31,7 @@ const Paragraph = ({ color, size = SIZE.sm, style, ...restProps }: ParagraphProp
},
style
]}
- ></AnimatedText>
+ ></Component>
);
};
diff --git a/apps/mobile/src/components/walkthroughs/index.tsx b/apps/mobile/src/components/walkthroughs/index.tsx
index bbae270ba..94b73d16c 100644
--- a/apps/mobile/src/components/walkthroughs/index.tsx
+++ b/apps/mobile/src/components/walkthroughs/index.tsx
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { LayoutAnimation, View } from 'react-native';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent, presentSheet } from '../../services/event-manager';
import { eCloseProgressDialog } from '../../utils/events';
import { MMKV } from '../../utils/database/mmkv';
diff --git a/apps/mobile/src/components/walkthroughs/walkthroughs.tsx b/apps/mobile/src/components/walkthroughs/walkthroughs.tsx
index 186ee6a57..0fd38a829 100644
--- a/apps/mobile/src/components/walkthroughs/walkthroughs.tsx
+++ b/apps/mobile/src/components/walkthroughs/walkthroughs.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { Linking, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { COMMUNITY_SVG, LAUNCH_ROCKET, SUPPORT_SVG, WELCOME_SVG } from '../../assets/images/assets';
-import { ThemeStore, useThemeStore } from '../../stores/theme';
+import { ThemeStore, useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent } from '../../services/event-manager';
import { getElevation } from '../../utils';
import { eOpenAddNotebookDialog } from '../../utils/events';
diff --git a/apps/mobile/src/navigation/navigationstack.js b/apps/mobile/src/navigation/navigationstack.js
index f25e3cf9b..cd8a01ba8 100644
--- a/apps/mobile/src/navigation/navigationstack.js
+++ b/apps/mobile/src/navigation/navigationstack.js
@@ -1,32 +1,67 @@
+import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { NavigationContainer } from '@react-navigation/native';
-import { createNativeStackNavigator } from '@react-navigation/native-stack';
import * as React from 'react';
import Container from '../components/container';
-import { useThemeStore } from '../stores/theme';
-import { useSelectionStore } from '../stores/stores';
-import { eSendEvent } from '../services/event-manager';
-import Navigation from '../services/navigation';
-import { history } from '../utils';
-import { hideAllTooltips } from '../utils/hooks/use-tooltip';
-import { MMKV } from '../utils/database/mmkv';
-import { rootNavigatorRef } from '../utils/global-refs';
import Favorites from '../screens/favorites';
-import Notebooks from '../screens/notebooks';
import Home from '../screens/home';
import Notebook from '../screens/notebook';
-import Notes from '../screens/notes';
+import Notebooks from '../screens/notebooks';
+import { ColoredNotes } from '../screens/notes/colored';
+import { Monographs } from '../screens/notes/monographs';
+import { TaggedNotes } from '../screens/notes/tagged';
+import { TopicNotes } from '../screens/notes/topic-notes';
import { Search } from '../screens/search';
import Settings from '../screens/settings';
import Tags from '../screens/tags';
import Trash from '../screens/trash';
+import { eSendEvent } from '../services/event-manager';
+import SettingsService from '../services/settings';
+import useNavigationStore from '../stores/use-navigation-store';
+import { useSelectionStore } from '../stores/use-selection-store';
+import { history } from '../utils';
+import { rootNavigatorRef } from '../utils/global-refs';
+import { hideAllTooltips } from '../utils/hooks/use-tooltip';
+const Tab = createBottomTabNavigator();
+const Tabs = React.memo(
+ () => {
+ const homepage = SettingsService.get().homepage;
+ React.useEffect(() => {
+ setTimeout(() => {
+ useNavigationStore.getState().update({ name: homepage });
+ }, 1000);
+ }, []);
+
+ return (
+ <Tab.Navigator
+ tabBar={() => null}
+ initialRouteName={homepage}
+ backBehavior="history"
+ screenOptions={{
+ headerShown: false,
+ lazy: false
+ }}
+ >
+ <Tab.Screen name="Notes" component={Home} />
+ <Tab.Screen name="Notebooks" component={Notebooks} />
+ <Tab.Screen name="Favorites" component={Favorites} />
+ <Tab.Screen name="Trash" component={Trash} />
+ <Tab.Screen name="Tags" component={Tags} />
+ <Tab.Screen name="Settings" component={Settings} />
+ <Tab.Screen options={{ lazy: true }} name="TaggedNotes" component={TaggedNotes} />
+ <Tab.Screen options={{ lazy: true }} name="TopicNotes" component={TopicNotes} />
+ <Tab.Screen options={{ lazy: true }} name="ColoredNotes" component={ColoredNotes} />
+ <Tab.Screen options={{ lazy: true }} name="Monographs" component={Monographs} />
+ <Tab.Screen options={{ lazy: true }} name="Notebook" component={Notebook} />
+ <Tab.Screen options={{ lazy: true }} name="Search" component={Search} />
+ </Tab.Navigator>
+ );
+ },
+ () => true
+);
-const Stack = createNativeStackNavigator();
export const NavigationStack = React.memo(
() => {
- const colors = useThemeStore(state => state.colors);
- const [render, setRender] = React.useState(false);
const clearSelection = useSelectionStore(state => state.clearSelection);
- const homepage = React.useRef('Notes');
const onStateChange = React.useCallback(() => {
if (history.selectionMode) {
@@ -36,57 +71,10 @@ export const NavigationStack = React.memo(
eSendEvent('navigate');
});
- React.useEffect(() => {
- (async () => {
- let settings = MMKV.getString('appSettings');
- if (settings) {
- settings = JSON.parse(settings);
- homepage.current = settings.homepage;
- }
- setRender(true);
- Navigation.setHeaderState(
- settings.homepage,
- {
- menu: true
- },
- {
- heading: settings.homepage,
- id: settings.homepage.toLowerCase() + '_navigation'
- }
- );
- })();
- }, []);
-
return (
<Container root={true}>
- <NavigationContainer
- onStateChange={onStateChange}
- independent={true}
- ref={rootNavigatorRef}
- >
- {render ? (
- <Stack.Navigator
- initialRouteName={homepage.current}
- screenOptions={{
- headerShown: false,
- gestureEnabled: false,
- animation: 'none',
- contentStyle: {
- backgroundColor: colors.bg
- }
- }}
- >
- <Stack.Screen name="Notes" component={Home} />
- <Stack.Screen name="Notebooks" component={Notebooks} />
- <Stack.Screen name="Favorites" component={Favorites} />
- <Stack.Screen name="Trash" component={Trash} />
- <Stack.Screen name="NotesPage" component={Notes} />
- <Stack.Screen name="Tags" component={Tags} />
- <Stack.Screen name="Notebook" component={Notebook} />
- <Stack.Screen name="Search" component={Search} />
- <Stack.Screen name="Settings" component={Settings} />
- </Stack.Navigator>
- ) : null}
+ <NavigationContainer onStateChange={onStateChange} ref={rootNavigatorRef}>
+ <Tabs />
</NavigationContainer>
</Container>
);
diff --git a/apps/mobile/src/navigation/tabsholder.js b/apps/mobile/src/navigation/tabsholder.js
index 0539dcfa5..0faaf9dc9 100644
--- a/apps/mobile/src/navigation/tabsholder.js
+++ b/apps/mobile/src/navigation/tabsholder.js
@@ -2,18 +2,19 @@ import { activateKeepAwake, deactivateKeepAwake } from '@sayem314/react-native-k
import React, { useEffect, useRef } from 'react';
import { Platform, View } from 'react-native';
import { NavigationBar, StatusBar } from 'react-native-bars';
-import Animated, { useValue } from 'react-native-reanimated';
+import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { notesnook } from '../../e2e/test.ids';
import { SideMenu } from '../components/side-menu';
-import Tabs from '../components/tabs';
-import { useThemeStore } from '../stores/theme';
-import { useEditorStore, useSettingStore } from '../stores/stores';
+import { NewTabs } from '../components/tabs/new';
import { EditorWrapper } from '../screens/editor/EditorWrapper';
import { checkStatus, EditorWebView, getNote } from '../screens/editor/Functions';
import tiny from '../screens/editor/tiny/tiny';
import { DDS } from '../services/device-detection';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../services/event-manager';
+import { useEditorStore } from '../stores/use-editor-store';
+import { useSettingStore } from '../stores/use-setting-store';
+import { useThemeStore } from '../stores/use-theme-store';
import { editing, setWidthHeight } from '../utils';
import { updateStatusBarColor } from '../utils/color-scheme';
import {
@@ -26,12 +27,11 @@ import { editorRef, tabBarRef } from '../utils/global-refs';
import { hideAllTooltips } from '../utils/hooks/use-tooltip';
import { sleep } from '../utils/time';
import { NavigationStack } from './navigation-stack';
-import Settings from '../screens/settings';
let layoutTimer = null;
const onChangeTab = async obj => {
- if (obj.i === 1) {
+ if (obj.i === 2) {
editing.movedAway = false;
activateKeepAwake();
eSendEvent('navigate');
@@ -51,7 +51,7 @@ const onChangeTab = async obj => {
updateStatusBarColor();
});
} else {
- if (obj.from === 1) {
+ if (obj.from === 2) {
updateStatusBarColor();
deactivateKeepAwake();
eSendEvent(eClearEditor, 'removeHandler');
@@ -80,10 +80,9 @@ export const TabsHolder = React.memo(
const dimensions = useSettingStore(state => state.dimensions);
const setDimensions = useSettingStore(state => state.setDimensions);
const insets = useSafeAreaInsets();
- const animatedOpacity = useValue(0);
- const animatedTranslateY = useValue(-9999);
+ const animatedOpacity = useSharedValue(0);
+ const animatedTranslateY = useSharedValue(-9999);
const overlayRef = useRef();
- const initialLayoutCalled = useRef(false);
const showFullScreenEditor = () => {
setFullscreen(true);
@@ -128,6 +127,7 @@ export const TabsHolder = React.memo(
}, [deviceMode, dimensions, colors]);
const _onLayout = async event => {
+ console.log('layout called here');
if (layoutTimer) {
clearTimeout(layoutTimer);
layoutTimer = null;
@@ -209,7 +209,7 @@ export const TabsHolder = React.memo(
const onScroll = scrollOffset => {
hideAllTooltips();
if (scrollOffset > offsets[deviceMode].a - 10) {
- animatedOpacity.setValue(0);
+ animatedOpacity.value = 0;
toggleView(false);
} else {
let o = scrollOffset / 300;
@@ -219,13 +219,13 @@ export const TabsHolder = React.memo(
} else {
op = 1 - o;
}
- animatedOpacity.setValue(op);
+ animatedOpacity.value = op;
toggleView(op < 0.1 ? false : true);
}
};
const toggleView = show => {
- animatedTranslateY.setValue(show ? 0 : -9999);
+ animatedTranslateY.value = show ? 0 : -9999;
};
const valueLimiter = (value, min, max) => {
@@ -276,52 +276,16 @@ export const TabsHolder = React.memo(
}
};
- const listItems = [
- <View
- key="1"
- onLayout={() => {
- if (!initialLayoutCalled.current) {
- tabBarRef.current?.goToIndex(1, false);
- initialLayoutCalled.current = true;
+ const animatedStyle = useAnimatedStyle(() => {
+ return {
+ opacity: animatedOpacity.value,
+ transform: [
+ {
+ translateY: animatedTranslateY.value
}
- }}
- style={{
- height: '100%',
- width: fullscreen ? 0 : widths[deviceMode].a
- }}
- >
- <SideMenu />
- </View>,
- <View
- key="2"
- style={{
- height: '100%',
- width: fullscreen ? 0 : widths[deviceMode].b
- }}
- >
- {deviceMode === 'mobile' ? (
- <Animated.View
- style={{
- position: 'absolute',
- width: '100%',
- height: '100%',
- zIndex: 999,
- backgroundColor: 'rgba(0,0,0,0.2)',
- opacity: animatedOpacity,
- transform: [
- {
- translateY: animatedTranslateY
- }
- ]
- }}
- ref={overlayRef}
- />
- ) : null}
-
- <NavigationStack />
- </View>,
- <EditorWrapper key="3" width={widths} dimensions={dimensions} />
- ];
+ ]
+ };
+ });
return (
<View
@@ -337,21 +301,58 @@ export const TabsHolder = React.memo(
<StatusBar animated={true} barStyle={colors.night ? 'light-content' : 'dark-content'} />
<NavigationBar barStyle={colors.night ? 'light-content' : 'dark-content'} />
- {deviceMode ? (
- <Tabs
+ {deviceMode && widths[deviceMode] ? (
+ <NewTabs
ref={tabBarRef}
dimensions={dimensions}
widths={widths[deviceMode]}
- style={{
- zIndex: 1
- }}
- initialIndex={deviceMode === 'smallTablet' || deviceMode === 'tablet' ? 0 : 1}
- toggleOverlay={toggleView}
- offsets={offsets[deviceMode]}
- items={listItems}
+ enabled={deviceMode !== 'tablet'}
onScroll={onScroll}
onChangeTab={onChangeTab}
- />
+ onDrawerStateChange={state => {}}
+ >
+ <View
+ key="1"
+ style={{
+ height: '100%',
+ width: fullscreen ? 0 : widths[deviceMode]?.a
+ }}
+ >
+ <SideMenu />
+ </View>
+
+ <View
+ key="2"
+ style={{
+ height: '100%',
+ width: fullscreen ? 0 : widths[deviceMode]?.b
+ }}
+ >
+ {deviceMode === 'mobile' ? (
+ <Animated.View
+ onTouchEnd={() => {
+ tabBarRef.current?.closeDrawer();
+ animatedOpacity.value = withTiming(0);
+ animatedTranslateY.value = withTiming(-9999);
+ }}
+ style={[
+ {
+ position: 'absolute',
+ width: '100%',
+ height: '100%',
+ zIndex: 999,
+ backgroundColor: 'rgba(0,0,0,0.2)'
+ },
+ animatedStyle
+ ]}
+ ref={overlayRef}
+ />
+ ) : null}
+
+ <NavigationStack />
+ </View>
+ <EditorWrapper key="3" width={widths} dimensions={dimensions} />
+ </NewTabs>
) : null}
</View>
);
diff --git a/apps/mobile/src/screens/editor/EditorHeader.js b/apps/mobile/src/screens/editor/EditorHeader.js
index 254f4706b..18b5dbcdb 100644
--- a/apps/mobile/src/screens/editor/EditorHeader.js
+++ b/apps/mobile/src/screens/editor/EditorHeader.js
@@ -5,8 +5,10 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { notesnook } from '../../../e2e/test.ids';
import { IconButton } from '../../components/ui/icon-button';
import { Properties } from '../../components/properties';
-import { useThemeStore } from '../../stores/theme';
-import { useEditorStore, useSettingStore, useUserStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useUserStore } from '../../stores/use-user-store';
+import { useEditorStore } from '../../stores/use-editor-store';
+import { useSettingStore } from '../../stores/use-setting-store';
import { DDS } from '../../services/device-detection';
import {
eSendEvent,
@@ -180,7 +182,7 @@ const EditorHeader = () => {
// // console.log('NOTE REMOVED', id);
// // await db.notes.remove(id);
// // if (id !== getNote().id) return;
- // // Navigation.setRoutesToUpdate([
+ // // Navigation.queueRoutesForUpdate([
// // Navigation.routeNames.Favorites,
// // Navigation.routeNames.Notes,
// // Navigation.routeNames.NotesPage,
diff --git a/apps/mobile/src/screens/editor/EditorOverlay.js b/apps/mobile/src/screens/editor/EditorOverlay.js
index 354f4bf01..09f935287 100644
--- a/apps/mobile/src/screens/editor/EditorOverlay.js
+++ b/apps/mobile/src/screens/editor/EditorOverlay.js
@@ -5,7 +5,7 @@ import { Button } from '../../components/ui/button';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { editing } from '../../utils';
import { eOnLoadNote } from '../../utils/events';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/screens/editor/EditorSettings.js b/apps/mobile/src/screens/editor/EditorSettings.js
index 0b0208b7f..d39beb942 100644
--- a/apps/mobile/src/screens/editor/EditorSettings.js
+++ b/apps/mobile/src/screens/editor/EditorSettings.js
@@ -12,7 +12,7 @@ import Input from '../../components/ui/input';
import { PressableButton } from '../../components/ui/pressable';
import Seperator from '../../components/ui/seperator';
import Paragraph from '../../components/ui/typography/paragraph';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { SIZE } from '../../utils/size';
import { sleep } from '../../utils/time';
diff --git a/apps/mobile/src/screens/editor/EditorTitle.js b/apps/mobile/src/screens/editor/EditorTitle.js
index 334935295..e6ecfd424 100644
--- a/apps/mobile/src/screens/editor/EditorTitle.js
+++ b/apps/mobile/src/screens/editor/EditorTitle.js
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react';
-import { TextInput } from 'react-native';
+import { TextInput, View } from 'react-native';
import Animated, { FadeInUp, FadeOutUp } from 'react-native-reanimated';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { post, _onMessage } from './Functions';
diff --git a/apps/mobile/src/screens/editor/EditorWrapper.js b/apps/mobile/src/screens/editor/EditorWrapper.js
index b22d41ae5..fd2e576e7 100644
--- a/apps/mobile/src/screens/editor/EditorWrapper.js
+++ b/apps/mobile/src/screens/editor/EditorWrapper.js
@@ -11,8 +11,9 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Editor from '.';
import { PremiumToast } from '../../components/premium/premium-toast';
import { DDS } from '../../services/device-detection';
-import { useNoteStore, useSettingStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { editing } from '../../utils';
import { editorRef } from '../../utils/global-refs';
import useIsFloatingKeyboard from '../../utils/hooks/use-is-floating-keyboard';
@@ -47,36 +48,38 @@ export const EditorWrapper = ({ width }) => {
testID="editor-wrapper"
ref={editorRef}
style={{
- width: width[deviceMode].c,
+ width: width[deviceMode]?.c,
height: '100%',
backgroundColor: colors.bg,
borderLeftWidth: DDS.isTab ? 1 : 0,
borderLeftColor: DDS.isTab ? colors.nav : 'transparent'
}}
>
- <SafeAreaView
- style={{
- flex: 1
- }}
- >
- <KeyboardAvoidingView
- behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
+ {loading ? null : (
+ <SafeAreaView
style={{
flex: 1
}}
- enabled={!floating}
>
- <PremiumToast key="toast" context="editor" offset={50 + insets.top} />
- <TextInput
- key="input"
- ref={textInput}
- style={{ height: 1, padding: 0, width: 1, position: 'absolute' }}
- blurOnSubmit={false}
- />
- {loading ? null : <Editor key="editor" />}
- <EditorOverlay key="overlay" />
- </KeyboardAvoidingView>
- </SafeAreaView>
+ <KeyboardAvoidingView
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
+ style={{
+ flex: 1
+ }}
+ enabled={!floating}
+ >
+ <PremiumToast key="toast" context="editor" offset={50 + insets.top} />
+ <TextInput
+ key="input"
+ ref={textInput}
+ style={{ height: 1, padding: 0, width: 1, position: 'absolute' }}
+ blurOnSubmit={false}
+ />
+ <Editor key="editor" />
+ <EditorOverlay key="overlay" />
+ </KeyboardAvoidingView>
+ </SafeAreaView>
+ )}
</View>
);
};
diff --git a/apps/mobile/src/screens/editor/Functions.js b/apps/mobile/src/screens/editor/Functions.js
index 00cd413a7..4844dc110 100644
--- a/apps/mobile/src/screens/editor/Functions.js
+++ b/apps/mobile/src/screens/editor/Functions.js
@@ -1,7 +1,9 @@
import { createRef } from 'react';
import { Platform } from 'react-native';
import { presentDialog } from '../../components/dialog/functions';
-import { useEditorStore, useMenuStore, useTagStore } from '../../stores/stores';
+import { useMenuStore } from '../../stores/use-menu-store';
+import { useEditorStore } from '../../stores/use-editor-store';
+import { useTagStore } from '../../stores/use-tag-store';
import { DDS } from '../../services/device-detection';
import {
eSendEvent,
@@ -624,7 +626,7 @@ export const _onMessage = async evt => {
console.log(_tag.title);
await db.notes.note(note.id).untag(_tag.title);
useTagStore.getState().setTags();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Tags
@@ -730,9 +732,9 @@ async function addToCollection(id) {
editing.actionAfterFirstSave = {
type: null
};
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notebooks,
- Navigation.routeNames.NotesPage,
+ Navigation.routeNames.TopicNotes,
Navigation.routeNames.Notebook
]);
break;
@@ -742,7 +744,11 @@ async function addToCollection(id) {
editing.actionAfterFirstSave = {
type: null
};
- Navigation.setRoutesToUpdate([Navigation.routeNames.Tags, Navigation.routeNames.NotesPage]);
+ Navigation.queueRoutesForUpdate([
+ Navigation.routeNames.Tags,
+ Navigation.routeNames.TaggedNotes
+ ]);
+ eSendEvent('updateTags');
break;
}
case 'color': {
@@ -751,7 +757,7 @@ async function addToCollection(id) {
editing.actionAfterFirstSave = {
type: null
};
- Navigation.setRoutesToUpdate([Navigation.routeNames.NotesPage]);
+ Navigation.queueRoutesForUpdate([Navigation.routeNames.ColoredNotes]);
useMenuStore.getState().setColorNotes();
break;
}
@@ -815,7 +821,7 @@ export async function saveNote(title, _id, data, type, _sessionId, _historySessi
if (!locked) {
let noteId = await db.notes.add(noteData);
if (!_id || saveCounter < 3) {
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.Favorites,
Navigation.routeNames.NotesPage,
@@ -845,7 +851,7 @@ export async function saveNote(title, _id, data, type, _sessionId, _historySessi
await db.vault.save(noteData);
}
if (sessionId === _sessionId) {
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes
diff --git a/apps/mobile/src/screens/editor/HistoryComponent.js b/apps/mobile/src/screens/editor/HistoryComponent.js
index 3fc217315..51e1d3ced 100644
--- a/apps/mobile/src/screens/editor/HistoryComponent.js
+++ b/apps/mobile/src/screens/editor/HistoryComponent.js
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Platform, View } from 'react-native';
import { IconButton } from '../../components/ui/icon-button';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { editing } from '../../utils';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/screens/editor/ProgressCircle.js b/apps/mobile/src/screens/editor/ProgressCircle.js
index 6ba2c551d..acf54f490 100644
--- a/apps/mobile/src/screens/editor/ProgressCircle.js
+++ b/apps/mobile/src/screens/editor/ProgressCircle.js
@@ -1,8 +1,8 @@
import React, { useEffect, useRef, useState } from 'react';
import { View } from 'react-native';
import * as Progress from 'react-native-progress';
-import { useThemeStore } from '../../stores/theme';
-import { useAttachmentStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
import { SIZE } from '../../utils/size';
export const ProgressCircle = () => {
diff --git a/apps/mobile/src/screens/editor/TableCellProperties.js b/apps/mobile/src/screens/editor/TableCellProperties.js
index 0fc726db9..5cd156f2b 100644
--- a/apps/mobile/src/screens/editor/TableCellProperties.js
+++ b/apps/mobile/src/screens/editor/TableCellProperties.js
@@ -5,7 +5,7 @@ import { IconButton } from '../../components/ui/icon-button';
import { Button } from '../../components/ui/button';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import {
eSendEvent,
eSubscribeEvent,
diff --git a/apps/mobile/src/screens/editor/TableRowProperties.js b/apps/mobile/src/screens/editor/TableRowProperties.js
index 7975fad07..942e2bbd4 100644
--- a/apps/mobile/src/screens/editor/TableRowProperties.js
+++ b/apps/mobile/src/screens/editor/TableRowProperties.js
@@ -3,7 +3,7 @@ import { View } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import { Button } from '../../components/ui/button';
import Heading from '../../components/ui/typography/heading';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import {
eSendEvent,
eSubscribeEvent,
diff --git a/apps/mobile/src/screens/editor/index.js b/apps/mobile/src/screens/editor/index.js
index ea2712c6b..3353d9d9d 100755
--- a/apps/mobile/src/screens/editor/index.js
+++ b/apps/mobile/src/screens/editor/index.js
@@ -2,7 +2,8 @@ import React, { useEffect, useState } from 'react';
import { Platform, View } from 'react-native';
import WebView from 'react-native-webview';
import { notesnook } from '../../../e2e/test.ids';
-import { useEditorStore, useUserStore } from '../../stores/stores';
+import { useUserStore } from '../../stores/use-user-store';
+import { useEditorStore } from '../../stores/use-editor-store';
import { DDS } from '../../services/device-detection';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { getCurrentColors } from '../../utils/color-scheme';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js b/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js
index d721d4a43..8286be063 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/coloritem.js
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { View, TouchableOpacity } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../../../services/event-manager';
import { normalize, SIZE } from '../../../../utils/size';
import { formatSelection, properties, rgbToHex } from './constants';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/commands.js b/apps/mobile/src/screens/editor/tiny/toolbar/commands.js
index f8089aaf5..bb088b3d1 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/commands.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/commands.js
@@ -1,5 +1,5 @@
import { Platform } from 'react-native';
-import { useEditorStore } from '../../../../stores/stores';
+import { useEditorStore } from '../../../../stores/use-editor-store';
import { EditorWebView, textInput } from '../../Functions';
import tiny from '../tiny';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/index.js b/apps/mobile/src/screens/editor/tiny/toolbar/index.js
index 57504cb06..3ec79b78a 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/index.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/index.js
@@ -1,8 +1,8 @@
import React, { useEffect } from 'react';
import { ScrollView, View } from 'react-native';
import { IconButton } from '../../../../components/ui/icon-button';
-import { useEditorStore } from '../../../../stores/stores';
-import { useThemeStore } from '../../../../stores/theme';
+import { useEditorStore } from '../../../../stores/use-editor-store';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { getElevation } from '../../../../utils';
import { db } from '../../../../utils/database';
import { normalize } from '../../../../utils/size';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/item.js b/apps/mobile/src/screens/editor/tiny/toolbar/item.js
index 8c5dcae44..9729d301d 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/item.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/item.js
@@ -4,8 +4,8 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { PressableButton } from '../../../../components/ui/pressable';
import Heading from '../../../../components/ui/typography/heading';
import Paragraph from '../../../../components/ui/typography/paragraph';
-import { useThemeStore } from '../../../../stores/theme';
-import { useUserStore } from '../../../../stores/stores';
+import { useThemeStore } from '../../../../stores/use-theme-store';
+import { useUserStore } from '../../../../stores/use-user-store';
import {
eSendEvent,
eSubscribeEvent,
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/itempin.js b/apps/mobile/src/screens/editor/tiny/toolbar/itempin.js
index 0b2422ed7..389c37e91 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/itempin.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/itempin.js
@@ -6,7 +6,7 @@ import Animated, {
withTiming
} from 'react-native-reanimated';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../../services/event-manager';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { sleep } from '../../../../utils/time';
const ToolbarItemPin = ({ format, color }) => {
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/linkinput.js b/apps/mobile/src/screens/editor/tiny/toolbar/linkinput.js
index 4e71b3ba6..928f06fbd 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/linkinput.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/linkinput.js
@@ -5,7 +5,7 @@ import isMobilePhone from 'validator/lib/isMobilePhone';
import isURL from 'validator/lib/isURL';
import { Button } from '../../../../components/ui/button';
import Input from '../../../../components/ui/input';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { eSendEvent, ToastEvent } from '../../../../services/event-manager';
import { editing, itemSkus } from '../../../../utils';
import { SIZE } from '../../../../utils/size';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/linkpreview.js b/apps/mobile/src/screens/editor/tiny/toolbar/linkpreview.js
index b0bfac413..30886b7c0 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/linkpreview.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/linkpreview.js
@@ -5,7 +5,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { IconButton } from '../../../../components/ui/icon-button';
import Heading from '../../../../components/ui/typography/heading';
import Paragraph from '../../../../components/ui/typography/paragraph';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { openLinkInBrowser } from '../../../../utils/functions';
import { SIZE } from '../../../../utils/size';
import { INPUT_MODE, properties, reFocusEditor } from './constants';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/listformat.js b/apps/mobile/src/screens/editor/tiny/toolbar/listformat.js
index 1b7bbf9c6..08b865d09 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/listformat.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/listformat.js
@@ -1,7 +1,7 @@
import React from 'react';
import { View } from 'react-native';
import Heading from '../../../../components/ui/typography/heading';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import Paragraph from '../../../../components/ui/typography/paragraph';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/searchreplace.js b/apps/mobile/src/screens/editor/tiny/toolbar/searchreplace.js
index 31c27c588..429f8ef74 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/searchreplace.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/searchreplace.js
@@ -2,8 +2,9 @@ import React, { useEffect, useRef, useState } from 'react';
import { View } from 'react-native';
import { Button } from '../../../../components/ui/button';
import Input from '../../../../components/ui/input';
-import { useThemeStore } from '../../../../stores/theme';
-import { useEditorStore, useSettingStore } from '../../../../stores/stores';
+import { useThemeStore } from '../../../../stores/use-theme-store';
+import { useEditorStore } from '../../../../stores/use-editor-store';
+import { useSettingStore } from '../../../../stores/use-setting-store';
import { showTooltip, TOOLTIP_POSITIONS } from '../../../../utils';
import { hideAllTooltips } from '../../../../utils/hooks/use-tooltip';
import layoutmanager from '../../../../utils/layout-manager';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/table.js b/apps/mobile/src/screens/editor/tiny/toolbar/table.js
index f514e3409..ef23a346b 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/table.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/table.js
@@ -3,7 +3,7 @@ import { View } from 'react-native';
import { PressableButton } from '../../../../components/ui/pressable';
import Heading from '../../../../components/ui/typography/heading';
import Paragraph from '../../../../components/ui/typography/paragraph';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { eSendEvent } from '../../../../services/event-manager';
import { eCloseProgressDialog } from '../../../../utils/events';
import { SIZE } from '../../../../utils/size';
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js b/apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js
index 8dd33824d..99025dd38 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/tooltip.js
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { ScrollView, View } from 'react-native';
-import { useThemeStore } from '../../../../stores/theme';
+import { useThemeStore } from '../../../../stores/use-theme-store';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../../../services/event-manager';
import { editing } from '../../../../utils';
import layoutmanager from '../../../../utils/layout-manager';
diff --git a/apps/mobile/src/screens/favorites/index.js b/apps/mobile/src/screens/favorites/index.js
deleted file mode 100644
index 7964d12a5..000000000
--- a/apps/mobile/src/screens/favorites/index.js
+++ /dev/null
@@ -1,113 +0,0 @@
-import React, { useCallback, useEffect } from 'react';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { Header } from '../../components/header';
-import { Placeholder } from '../../components/ui/svg';
-import SelectionHeader from '../../components/selection-header';
-import List from '../../components/list';
-import { useFavoriteStore, useNoteStore } from '../../stores/stores';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-
-export const Favorites = ({ navigation }) => {
- 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', () => {
- setFavorites();
- });
- });
- updateSearch();
- ranAfterInteractions = false;
- };
-
- const onFocus = useCallback(() => {
- if (!pageIsLoaded) {
- pageIsLoaded = true;
- return;
- }
-
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
-
- Navigation.setHeaderState(
- 'Favorites',
- {
- menu: true
- },
- {
- heading: 'Favorites',
- id: 'favorites_navigation'
- }
- );
- }, []);
-
- useEffect(() => {
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
- navigation.addListener('focus', onFocus);
- return () => {
- pageIsLoaded = false;
- ranAfterInteractions = false;
- navigation.removeListener('focus', onFocus);
- };
- }, []);
-
- useEffect(() => {
- if (navigation.isFocused()) {
- updateSearch();
- }
- }, [favorites]);
-
- const updateSearch = () => {
- SearchService.update({
- placeholder: 'Search in favorites',
- data: favorites,
- type: 'notes',
- title: 'Favorites',
- get: () => db.notes.favorites
- });
- };
-
- return (
- <>
- <SelectionHeader screen="Favorites" />
- <ContainerHeader>
- <Header title="Favorites" isBack={false} screen="Favorites" />
- </ContainerHeader>
- <List
- listData={favorites}
- type="notes"
- refreshCallback={() => {
- setFavorites();
- }}
- screen="Favorites"
- loading={loading}
- placeholderData={{
- heading: 'Your favorites',
- paragraph: 'You have not added any notes to favorites yet.',
- button: null,
- loading: 'Loading your favorites'
- }}
- headerProps={{
- heading: 'Favorites'
- }}
- focused={() => navigation.isFocused()}
- placeholderText="Notes you favorite appear here"
- />
- </>
- );
-};
-
-export default Favorites;
diff --git a/apps/mobile/src/screens/favorites/index.tsx b/apps/mobile/src/screens/favorites/index.tsx
new file mode 100644
index 000000000..b12881e37
--- /dev/null
+++ b/apps/mobile/src/screens/favorites/index.tsx
@@ -0,0 +1,64 @@
+import React from 'react';
+import List from '../../components/list';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import SearchService from '../../services/search';
+import SettingsService from '../../services/settings';
+import { useFavoriteStore } from '../../stores/use-favorite-store';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { db } from '../../utils/database';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+
+const prepareSearch = () => {
+ SearchService.update({
+ placeholder: 'Search in favorites',
+ type: 'notes',
+ title: 'Favorites',
+ get: () => db.notes?.favorites
+ });
+};
+
+const PLACEHOLDER_DATA = {
+ heading: 'Your favorites',
+ paragraph: 'You have not added any notes to favorites yet.',
+ button: null,
+ loading: 'Loading your favorites'
+};
+
+export const Favorites = ({ navigation, route }: NavigationProps<'Favorites'>) => {
+ const favorites = useFavoriteStore(state => state.favorites);
+ const setFavorites = useFavoriteStore(state => state.setFavorites);
+ const loading = useNoteStore(state => state.loading);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: prev => {
+ Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+ SearchService.prepareSearch = prepareSearch;
+ return !prev?.current;
+ },
+ onBlur: () => false,
+ delay: SettingsService.get().homepage === route.name ? 1 : -1
+ });
+
+ return (
+ <>
+ <List
+ listData={favorites}
+ type="notes"
+ refreshCallback={() => {
+ setFavorites();
+ }}
+ screen="Favorites"
+ loading={loading || !isFocused}
+ placeholderData={PLACEHOLDER_DATA}
+ headerProps={{
+ heading: 'Favorites'
+ }}
+ />
+ </>
+ );
+};
+
+export default Favorites;
diff --git a/apps/mobile/src/screens/home/index.js b/apps/mobile/src/screens/home/index.js
deleted file mode 100755
index c52b3fd83..000000000
--- a/apps/mobile/src/screens/home/index.js
+++ /dev/null
@@ -1,131 +0,0 @@
-import React, { useCallback, useEffect } from 'react';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { FloatingButton } from '../../components/container/floating-button';
-import { Header } from '../../components/header/index';
-import List from '../../components/list';
-import SelectionHeader from '../../components/selection-header';
-import { DDS } from '../../services/device-detection';
-import { eSendEvent } from '../../services/event-manager';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { useNoteStore } from '../../stores/stores';
-import { editing, InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-import { eOnLoadNote } from '../../utils/events';
-import { tabBarRef } from '../../utils/global-refs';
-import { getNote } from '../editor/Functions';
-
-export const Home = ({ navigation }) => {
- const notes = useNoteStore(state => state.notes);
- const setNotes = useNoteStore(state => state.setNotes);
- const loading = useNoteStore(state => state.loading);
-
- let ranAfterInteractions = false;
-
- const onFocus = useCallback(() => {
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
-
- Navigation.setHeaderState(
- 'Notes',
- {
- menu: true
- },
- {
- heading: 'Notes',
- id: 'notes_navigation'
- }
- );
- }, []);
-
- const onBlur = useCallback(() => {}, []);
-
- const runAfterInteractions = () => {
- updateSearch();
-
- InteractionManager.runAfterInteractions(() => {
- Navigation.routeNeedsUpdate('Notes', () => {
- setNotes();
- });
- });
- ranAfterInteractions = false;
- };
-
- useEffect(() => {
- navigation.addListener('focus', onFocus);
- navigation.addListener('blur', onBlur);
- return () => {
- ranAfterInteractions = false;
- navigation.removeListener('focus', onFocus);
- navigation.removeListener('blur', onBlur);
- };
- }, []);
-
- useEffect(() => {
- if (navigation.isFocused()) {
- updateSearch();
- }
- }, [notes]);
-
- const updateSearch = () => {
- SearchService.update({
- placeholder: 'Type a keyword to search in notes',
- data: db?.notes?.all,
- type: 'notes',
- title: 'Notes',
- get: () => db.notes.all
- });
- };
-
- const _onPressBottomButton = React.useCallback(async () => {
- if (!DDS.isTab) {
- if (getNote()) {
- eSendEvent(eOnLoadNote, { type: 'new' });
- editing.currentlyEditing = true;
- editing.movedAway = false;
- }
- tabBarRef.current?.goToPage(1);
- } else {
- eSendEvent(eOnLoadNote, { type: 'new' });
- }
- }, []);
-
- return (
- <>
- <SelectionHeader screen="Notes" />
- <ContainerHeader>
- <Header title="Notes" isBack={false} screen="Notes" action={_onPressBottomButton} />
- </ContainerHeader>
-
- <List
- listData={notes}
- type="notes"
- isHome={true}
- pinned={true}
- screen="Notes"
- loading={loading}
- sortMenuButton={true}
- headerProps={{
- heading: 'Notes'
- }}
- placeholderText={`Notes you write appear here`}
- jumpToDialog={true}
- placeholderData={{
- heading: 'Notes',
- paragraph: 'You have not added any notes yet.',
- button: 'Add your first note',
- action: _onPressBottomButton,
- loading: 'Loading your notes'
- }}
- />
-
- {!notes || notes.length === 0 ? null : (
- <FloatingButton title="Create a new note" onPress={_onPressBottomButton} />
- )}
- </>
- );
-};
-
-export default Home;
diff --git a/apps/mobile/src/screens/home/index.tsx b/apps/mobile/src/screens/home/index.tsx
new file mode 100755
index 000000000..be972e7f8
--- /dev/null
+++ b/apps/mobile/src/screens/home/index.tsx
@@ -0,0 +1,73 @@
+import React from 'react';
+import { FloatingButton } from '../../components/container/floating-button';
+import { RightMenus } from '../../components/header/right-menus';
+import List from '../../components/list';
+import { DDS } from '../../services/device-detection';
+import { eSendEvent } from '../../services/event-manager';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import SearchService from '../../services/search';
+import SettingsService from '../../services/settings';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { editing } from '../../utils';
+import { db } from '../../utils/database';
+import { eOnLoadNote } from '../../utils/events';
+import { tabBarRef } from '../../utils/global-refs';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+import { getNote } from '../editor/Functions';
+import { openEditor } from '../notes/common';
+
+const prepareSearch = () => {
+ SearchService.update({
+ placeholder: 'Type a keyword to search in notes',
+ type: 'notes',
+ title: 'Notes',
+ get: () => db.notes?.all
+ });
+};
+
+const PLACEHOLDER_DATA = {
+ heading: 'Notes',
+ paragraph: 'You have not added any notes yet.',
+ button: 'Add your first note',
+ action: openEditor,
+ loading: 'Loading your notes'
+};
+
+export const Home = ({ navigation, route }: NavigationProps<'Notes'>) => {
+ const notes = useNoteStore(state => state.notes);
+ const loading = useNoteStore(state => state.loading);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: prev => {
+ Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+ SearchService.prepareSearch = prepareSearch;
+ RightMenus.floatingButtonAction = openEditor;
+ return !prev?.current;
+ },
+ onBlur: () => false,
+ delay: SettingsService.get().homepage === route.name ? 1 : -1
+ });
+
+ return (
+ <>
+ <List
+ listData={notes}
+ type="notes"
+ screen="Notes"
+ loading={loading || !isFocused}
+ headerProps={{
+ heading: 'Notes'
+ }}
+ placeholderData={PLACEHOLDER_DATA}
+ />
+ {!notes || notes.length === 0 || !isFocused ? null : (
+ <FloatingButton title="Create a new note" onPress={openEditor} />
+ )}
+ </>
+ );
+};
+
+export default Home;
diff --git a/apps/mobile/src/screens/notebook/index.js b/apps/mobile/src/screens/notebook/index.js
deleted file mode 100644
index d0f795f25..000000000
--- a/apps/mobile/src/screens/notebook/index.js
+++ /dev/null
@@ -1,135 +0,0 @@
-import { groupArray } from 'notes-core/utils/grouping';
-import React, { useEffect, useRef, useState } from 'react';
-import { FloatingButton } from '../../components/container/floating-button';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { Header } from '../../components/header';
-import SelectionHeader from '../../components/selection-header';
-import List from '../../components/list';
-import { NotebookHeader } from '../../components/list-items/headers/notebook-header';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-import { eOnNewTopicAdded, eOpenAddNotebookDialog, eOpenAddTopicDialog } from '../../utils/events';
-import { qclone } from 'qclone';
-export const Notebook = ({ route, navigation }) => {
- const [topics, setTopics] = useState(
- groupArray(qclone(route?.params.notebook?.topics) || [], db.settings.getGroupOptions('topics'))
- );
- const params = useRef(route?.params);
-
- const onLoad = data => {
- if (data) params.current = data;
- try {
- let notebook = db.notebooks.notebook(params?.current?.notebook?.id)?.data;
- if (notebook) {
- params.current.notebook = notebook;
- setTopics(groupArray(qclone(notebook.topics), db.settings.getGroupOptions('topics')));
- params.current.title = params.current.notebook.title;
- }
- updateSearch();
- } catch (e) {}
- };
-
- useEffect(() => {
- eSubscribeEvent(eOnNewTopicAdded, onLoad);
- return () => {
- eUnSubscribeEvent(eOnNewTopicAdded, onLoad);
- };
- }, [topics]);
-
- const onFocus = async () => {
- InteractionManager.runAfterInteractions(() => {
- Navigation.routeNeedsUpdate(Navigation.routeNames.Notebook, onLoad);
- }, 150);
- Navigation.setHeaderState('Notebook', params, {
- heading: params.current.title,
- id: params.current.notebook.id,
- type: 'notebook'
- });
- };
-
- useEffect(() => {
- navigation.addListener('focus', onFocus);
- return () => {
- navigation.removeListener('focus', onFocus);
- };
- }, []);
-
- useEffect(() => {
- if (navigation.isFocused()) {
- updateSearch();
- }
- }, [topics]);
-
- const updateSearch = () => {
- SearchService.update({
- placeholder: `Search in "${params.current.title}"`,
- data: topics,
- type: 'topics',
- title: params.current.title,
- get: () => {
- let notebook = db.notebooks.notebook(params?.current?.notebook?.id)?.data;
- return notebook.topics;
- }
- });
- };
-
- const _onPressBottomButton = () => {
- let n = params.current.notebook;
- eSendEvent(eOpenAddTopicDialog, { notebookId: n.id });
- };
-
- return (
- <>
- <SelectionHeader screen="Notebook" />
-
- <ContainerHeader>
- <Header
- title={params.current.title}
- isBack={!params.current.menu}
- screen="Notebook"
- action={_onPressBottomButton}
- />
- </ContainerHeader>
- <List
- listData={topics}
- type="topics"
- refreshCallback={() => {
- onLoad();
- }}
- screen="Notebook"
- headerProps={{
- heading: params.current.title,
- paragraph: 'Edit notebook',
- onPress: () => {
- eSendEvent(eOpenAddNotebookDialog, params.current.notebook);
- },
- icon: 'pencil'
- }}
- ListHeader={
- <NotebookHeader
- onEditNotebook={() => {
- eSendEvent(eOpenAddNotebookDialog, params.current.notebook);
- }}
- onPress={_onPressBottomButton}
- notebook={params.current.notebook}
- />
- }
- focused={() => navigation.isFocused()}
- placeholderData={{
- heading: params.current.notebook.title,
- paragraph: 'You have not added any topics yet.',
- button: 'Add first topic',
- action: _onPressBottomButton,
- loading: 'Loading notebook topics'
- }}
- />
-
- <FloatingButton title="Add new topic" onPress={_onPressBottomButton} />
- </>
- );
-};
-
-export default Notebook;
diff --git a/apps/mobile/src/screens/notebook/index.tsx b/apps/mobile/src/screens/notebook/index.tsx
new file mode 100644
index 000000000..31c188edb
--- /dev/null
+++ b/apps/mobile/src/screens/notebook/index.tsx
@@ -0,0 +1,134 @@
+import { groupArray } from 'notes-core/utils/grouping';
+import { qclone } from 'qclone';
+import React, { useEffect, useRef, useState } from 'react';
+import { FloatingButton } from '../../components/container/floating-button';
+import List from '../../components/list';
+import { NotebookHeader } from '../../components/list-items/headers/notebook-header';
+import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import Navigation, { NavigationProps, NotebookScreenParams } from '../../services/navigation';
+import SearchService from '../../services/search';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { db } from '../../utils/database';
+import { eOnNewTopicAdded, eOpenAddNotebookDialog, eOpenAddTopicDialog } from '../../utils/events';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+import { NotebookType } from '../../utils/types';
+
+const Notebook = ({ route, navigation }: NavigationProps<'Notebook'>) => {
+ const [topics, setTopics] = useState(
+ groupArray(qclone(route?.params.item?.topics) || [], db.settings?.getGroupOptions('topics'))
+ );
+ console.log(route.params);
+ const params = useRef<NotebookScreenParams>(route?.params);
+ useNavigationFocus(navigation, {
+ onFocus: () => {
+ Navigation.routeNeedsUpdate(route.name, onRequestUpdate);
+ syncWithNavigation();
+ return false;
+ },
+ onBlur: () => false
+ });
+
+ const syncWithNavigation = () => {
+ useNavigationStore.getState().update(
+ {
+ name: route.name,
+ title: params.current?.title,
+ id: params.current?.item?.id,
+ type: 'notebook'
+ },
+ params.current?.canGoBack
+ );
+ SearchService.prepareSearch = prepareSearch;
+ };
+
+ const onRequestUpdate = (data?: NotebookScreenParams) => {
+ if (data) params.current = data;
+ params.current.title = params.current.item.title;
+ try {
+ let notebook = db.notebooks?.notebook(params?.current?.item?.id)?.data as NotebookType;
+ if (notebook) {
+ params.current.item = notebook;
+ setTopics(groupArray(qclone(notebook.topics), db.settings?.getGroupOptions('topics')));
+ syncWithNavigation();
+ }
+ } catch (e) {}
+ };
+
+ useEffect(() => {
+ eSubscribeEvent(eOnNewTopicAdded, onRequestUpdate);
+ return () => {
+ eUnSubscribeEvent(eOnNewTopicAdded, onRequestUpdate);
+ };
+ }, [topics]);
+
+ const prepareSearch = () => {
+ SearchService.update({
+ placeholder: `Search in "${params.current.title}"`,
+ type: 'topics',
+ title: params.current.title,
+ get: () => {
+ let notebook = db.notebooks?.notebook(params?.current?.item?.id)?.data as NotebookType;
+ return notebook?.topics;
+ }
+ });
+ };
+
+ const onPressFloatingButton = () => {
+ let n = params.current.item;
+ eSendEvent(eOpenAddTopicDialog, { notebookId: n.id });
+ };
+
+ const PLACEHOLDER_DATA = {
+ heading: params.current.item?.title,
+ paragraph: 'You have not added any topics yet.',
+ button: 'Add first topic',
+ action: onPressFloatingButton,
+ loading: 'Loading notebook topics'
+ };
+
+ return (
+ <>
+ <List
+ listData={topics}
+ type="topics"
+ refreshCallback={() => {
+ onRequestUpdate();
+ }}
+ screen="Notebook"
+ headerProps={{
+ heading: params.current.title
+ }}
+ ListHeader={
+ <NotebookHeader
+ onEditNotebook={() => {
+ eSendEvent(eOpenAddNotebookDialog, params.current.item);
+ }}
+ notebook={params.current.item}
+ />
+ }
+ placeholderData={PLACEHOLDER_DATA}
+ />
+
+ <FloatingButton title="Add new topic" onPress={onPressFloatingButton} />
+ </>
+ );
+};
+
+Notebook.navigate = (item: NotebookType, canGoBack: boolean) => {
+ if (!item) return;
+ Navigation.navigate<'Notebook'>(
+ {
+ title: item.title,
+ name: 'Notebook',
+ id: item.id,
+ type: 'notebook'
+ },
+ {
+ title: item.title,
+ item: item,
+ canGoBack
+ }
+ );
+};
+
+export default Notebook;
diff --git a/apps/mobile/src/screens/notebooks/index.js b/apps/mobile/src/screens/notebooks/index.js
deleted file mode 100644
index 838ab428b..000000000
--- a/apps/mobile/src/screens/notebooks/index.js
+++ /dev/null
@@ -1,110 +0,0 @@
-import React, { useCallback, useEffect } from 'react';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { FloatingButton } from '../../components/container/floating-button';
-import { AddNotebookEvent } from '../../components/dialog-provider/recievers';
-import { Header } from '../../components/header';
-import List from '../../components/list';
-import SelectionHeader from '../../components/selection-header';
-import { Walkthrough } from '../../components/walkthroughs';
-import { useNotebookStore } from '../../stores/stores';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-
-export const Notebooks = ({ navigation }) => {
- const notebooks = useNotebookStore(state => state.notebooks);
- const setNotebooks = useNotebookStore(state => state.setNotebooks);
- let ranAfterInteractions = false;
-
- const onFocus = useCallback(() => {
- Navigation.setHeaderState(
- 'Notebooks',
- {
- menu: true
- },
- {
- heading: 'Notebooks',
- id: 'notebooks_navigation'
- }
- );
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
- }, []);
-
- const runAfterInteractions = () => {
- InteractionManager.runAfterInteractions(() => {
- Navigation.routeNeedsUpdate('Notebooks', () => {
- setNotebooks();
- });
- });
- updateSearch();
- ranAfterInteractions = false;
- };
-
- useEffect(() => {
- navigation.addListener('focus', onFocus);
- return () => {
- ranAfterInteractions = false;
- navigation.removeListener('focus', onFocus);
- };
- }, []);
-
- useEffect(() => {
- if (navigation.isFocused()) {
- if (notebooks.length === 0) {
- Walkthrough.present('notebooks');
- } else {
- Walkthrough.update('notebooks');
- }
- updateSearch();
- }
- }, [notebooks]);
-
- const updateSearch = React.useCallback(() => {
- SearchService.update({
- placeholder: 'Type a keyword to search in notebooks',
- data: notebooks,
- type: 'notebooks',
- title: 'Notebooks',
- get: () => db.notebooks.all
- });
- }, []);
-
- const _onPressBottomButton = () => {
- AddNotebookEvent();
- };
-
- return (
- <>
- <SelectionHeader screen="Notebooks" />
- <ContainerHeader>
- <Header title="Notebooks" isBack={false} screen="Notebooks" action={_onPressBottomButton} />
- </ContainerHeader>
- <List
- listData={notebooks}
- type="notebooks"
- screen="Notebooks"
- focused={() => navigation.isFocused()}
- placeholderData={{
- heading: 'Your notebooks',
- paragraph: 'You have not added any notebooks yet.',
- button: 'Add your first notebook',
- action: _onPressBottomButton,
- loading: 'Loading your notebooks'
- }}
- headerProps={{
- heading: 'Notebooks'
- }}
- />
-
- {!notebooks || notebooks.length === 0 ? null : (
- <FloatingButton title="Create a new notebook" onPress={_onPressBottomButton} />
- )}
- </>
- );
-};
-
-export default Notebooks;
diff --git a/apps/mobile/src/screens/notebooks/index.tsx b/apps/mobile/src/screens/notebooks/index.tsx
new file mode 100644
index 000000000..971471d5c
--- /dev/null
+++ b/apps/mobile/src/screens/notebooks/index.tsx
@@ -0,0 +1,85 @@
+import React, { useEffect } from 'react';
+import { ContainerHeader } from '../../components/container/containerheader';
+import { FloatingButton } from '../../components/container/floating-button';
+import { AddNotebookEvent } from '../../components/dialog-provider/recievers';
+import { Header } from '../../components/header';
+import { RightMenus } from '../../components/header/right-menus';
+import List from '../../components/list';
+import SelectionHeader from '../../components/selection-header';
+import { Walkthrough } from '../../components/walkthroughs';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import SearchService from '../../services/search';
+import SettingsService from '../../services/settings';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useNotebookStore } from '../../stores/use-notebook-store';
+import { db } from '../../utils/database';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+
+const onPressFloatingButton = () => {
+ AddNotebookEvent();
+};
+
+const prepareSearch = () => {
+ SearchService.update({
+ placeholder: 'Type a keyword to search in notebooks',
+ type: 'notebooks',
+ title: 'Notebooks',
+ get: () => db.notebooks?.all
+ });
+};
+
+const PLACEHOLDER_DATA = {
+ heading: 'Your notebooks',
+ paragraph: 'You have not added any notebooks yet.',
+ button: 'Add your first notebook',
+ action: onPressFloatingButton,
+ loading: 'Loading your notebooks'
+};
+
+export const Notebooks = ({ navigation, route }: NavigationProps<'Notebooks'>) => {
+ const notebooks = useNotebookStore(state => state.notebooks);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: prev => {
+ Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+ SearchService.prepareSearch = prepareSearch;
+ RightMenus.floatingButtonAction = onPressFloatingButton;
+ return !prev?.current;
+ },
+ onBlur: () => false,
+ delay: SettingsService.get().homepage === route.name ? 1 : -1
+ });
+
+ useEffect(() => {
+ if (navigation.isFocused()) {
+ if (notebooks.length === 0) {
+ Walkthrough.present('notebooks');
+ } else {
+ Walkthrough.update('notebooks');
+ }
+ }
+ }, [notebooks]);
+
+ return (
+ <>
+ <List
+ listData={notebooks}
+ type="notebooks"
+ screen="Notebooks"
+ loading={!isFocused}
+ placeholderData={PLACEHOLDER_DATA}
+ headerProps={{
+ heading: 'Notebooks'
+ }}
+ />
+
+ {!notebooks || notebooks.length === 0 || !isFocused ? null : (
+ <FloatingButton title="Create a new notebook" onPress={onPressFloatingButton} />
+ )}
+ </>
+ );
+};
+
+export default Notebooks;
diff --git a/apps/mobile/src/screens/notes/colored.tsx b/apps/mobile/src/screens/notes/colored.tsx
new file mode 100644
index 000000000..7adda64ef
--- /dev/null
+++ b/apps/mobile/src/screens/notes/colored.tsx
@@ -0,0 +1,46 @@
+import { groupArray } from 'notes-core/utils/grouping';
+import React from 'react';
+import NotesPage, { PLACEHOLDER_DATA } from '.';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import { db } from '../../utils/database';
+import { ColorType, TagType } from '../../utils/types';
+import { getAlias, openEditor, toCamelCase } from './common';
+
+export const ColoredNotes = ({ navigation, route }: NavigationProps<'ColoredNotes'>) => {
+ return (
+ <NotesPage
+ navigation={navigation}
+ route={route}
+ get={ColoredNotes.get}
+ placeholderData={PLACEHOLDER_DATA}
+ onPressFloatingButton={openEditor}
+ canGoBack={route.params.canGoBack}
+ focusControl={true}
+ />
+ );
+};
+
+ColoredNotes.get = (id: string, grouped = true) => {
+ let notes = db.notes?.colored(id) || [];
+ return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;
+};
+
+ColoredNotes.navigate = (item: ColorType, canGoBack: boolean) => {
+ if (!item) return;
+ //@ts-ignore TODO
+ let alias = getAlias({ item: item });
+ Navigation.navigate<'ColoredNotes'>(
+ {
+ name: 'ColoredNotes',
+ alias: toCamelCase(alias),
+ title: item.title,
+ id: item.id,
+ type: 'color'
+ },
+ {
+ item: item,
+ canGoBack,
+ title: toCamelCase(alias)
+ }
+ );
+};
diff --git a/apps/mobile/src/screens/notes/common.ts b/apps/mobile/src/screens/notes/common.ts
new file mode 100644
index 000000000..cf36527ab
--- /dev/null
+++ b/apps/mobile/src/screens/notes/common.ts
@@ -0,0 +1,64 @@
+import { DDS } from '../../services/device-detection';
+import { eSendEvent } from '../../services/event-manager';
+import { NotesScreenParams } from '../../services/navigation';
+import { editing } from '../../utils';
+import { db } from '../../utils/database';
+import { eOnLoadNote } from '../../utils/events';
+import { openLinkInBrowser } from '../../utils/functions';
+import { tabBarRef } from '../../utils/global-refs';
+import { getNote } from '../editor/Functions';
+
+export function toCamelCase(title: string) {
+ return title.slice(0, 1).toUpperCase() + title.slice(1);
+}
+
+export function getAlias(params: NotesScreenParams) {
+ if (!params) return '';
+ const { item } = params;
+ let alias =
+ item.type === 'tag'
+ ? db.tags?.alias(item.id)
+ : item.type === 'color'
+ ? db.colors?.alias(item.id)
+ : params?.title;
+ return alias || '';
+}
+
+export function openMonographsWebpage() {
+ try {
+ openLinkInBrowser('https://docs.notesnook.com/monographs/');
+ } catch (e) {}
+}
+
+export function openEditor() {
+ if (!DDS.isTab) {
+ if (getNote()) {
+ eSendEvent(eOnLoadNote, { type: 'new' });
+ editing.currentlyEditing = true;
+ editing.movedAway = false;
+ }
+ tabBarRef.current?.goToPage(1);
+ } else {
+ eSendEvent(eOnLoadNote, { type: 'new' });
+ }
+}
+
+export const setOnFirstSave = (
+ data: {
+ type: string;
+ id: string;
+ notebook?: string;
+ color?: string;
+ } | null
+) => {
+ //@ts-ignore
+ editing.actionAfterFirstSave = data;
+};
+
+export function isSynced(params: NotesScreenParams) {
+ if (params.item.type === 'topic') {
+ let topic = db.notebooks?.notebook(params.item.notebookId)?.topics.topic(params.item.id);
+ return !topic ? true : topic?.synced();
+ }
+ return true;
+}
diff --git a/apps/mobile/src/screens/notes/index.js b/apps/mobile/src/screens/notes/index.js
deleted file mode 100644
index b067e7994..000000000
--- a/apps/mobile/src/screens/notes/index.js
+++ /dev/null
@@ -1,307 +0,0 @@
-import { groupArray } from 'notes-core/utils/grouping';
-import React, { useCallback, useEffect, useRef, useState } from 'react';
-import { FloatingButton } from '../../components/container/floating-button';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { Header } from '../../components/header';
-import { MoveNotes } from '../../components/sheets/move-notes/movenote';
-import SelectionHeader from '../../components/selection-header';
-import List from '../../components/list';
-import { useThemeStore } from '../../stores/theme';
-import { useNoteStore } from '../../stores/stores';
-import { DDS } from '../../services/device-detection';
-import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { editing, InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-import { eOnLoadNote, eOpenAddTopicDialog, refreshNotesPage } from '../../utils/events';
-import { openLinkInBrowser } from '../../utils/functions';
-import { tabBarRef } from '../../utils/global-refs';
-import { getNote } from '../editor/Functions';
-
-const getNotes = (params, group = true) => {
- if (!params)
- return {
- notes: [],
- synced: true
- };
- let notes = [];
- let isSynced = true;
- if (params.type !== 'topic' && params.get !== 'monographs') {
- notes = db.notes[params.get](params.id);
- } else if (params.get === 'monographs') {
- notes = db.monographs.all;
- } else {
- notes = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id)?.all;
- isSynced = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id)?.synced();
- }
- if (!notes) {
- notes = [];
- }
- return {
- notes: group ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes,
- synced: isSynced
- };
-};
-
-function getAlias(params) {
- if (!params) return '';
- let alias =
- params.current?.type === 'tag'
- ? db.tags.alias(params.current?.id)
- : params.current?.type === 'color'
- ? db.colors.alias(params.current?.id)
- : params.current?.title;
- return alias || '';
-}
-
-function getIsSynced(params) {
- if (params.type === 'topic') {
- let topic = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id);
- return !topic ? true : topic?.synced();
- }
- return true;
-}
-
-export const Notes = ({ route, navigation }) => {
- const colors = useThemeStore(state => state.colors);
- const params = useRef(route?.params);
- const [notes, setNotes] = useState(getNotes(params.current).notes || []);
- const loading = useNoteStore(state => state.loading);
- const alias = getAlias(params);
- const [warning, setWarning] = useState(!getIsSynced(params.current));
-
- const onLoad = () => {
- let data = getNotes(params.current);
- let _notes = data.notes;
- setWarning(!data.synced);
- setNotes(_notes);
- if (!params.current) return;
- if (
- (params.current.type === 'tag' || params.current.type === 'color') &&
- (!_notes || _notes.length === 0)
- ) {
- Navigation.goBack();
- }
- updateSearch();
- };
-
- useEffect(() => {
- eSubscribeEvent(refreshNotesPage, init);
- return () => {
- eUnSubscribeEvent(refreshNotesPage, init);
- editing.actionAfterFirstSave = {
- type: null
- };
- };
- }, []);
-
- const setActionAfterFirstSave = () => {
- if (params.current?.get === 'monographs') return;
- console.log(params.current);
- editing.actionAfterFirstSave = {
- type: params.current?.type,
- id: params.current?.id,
- notebook: params.current?.notebookId,
- color: params.current.title
- };
- };
-
- const init = data => {
- if (data) params.current = data;
-
- onLoad();
- Navigation.setHeaderState('NotesPage', params, {
- heading:
- params.current?.type === 'tag'
- ? '#' + alias
- : alias.slice(0, 1).toUpperCase() + alias.slice(1),
- id: params.current?.id,
- type: params.current?.type
- });
- };
-
- const onFocus = () => {
- setActionAfterFirstSave();
- InteractionManager.runAfterInteractions(() => {
- Navigation.routeNeedsUpdate('NotesPage', init);
- }, 150);
- };
-
- const onBlur = useCallback(() => {
- InteractionManager.runAfterInteractions(() => {
- setNotes([]);
- }, 150);
- editing.actionAfterFirstSave = {
- type: null
- };
- }, []);
-
- useEffect(() => {
- navigation.addListener('focus', onFocus);
- navigation.addListener('blur', onBlur);
- return () => {
- editing.actionAfterFirstSave = {
- type: null
- };
- navigation.removeListener('focus', onFocus);
- navigation.removeListener('blur', onBlur);
- };
- }, []);
-
- useEffect(() => {
- if (navigation?.isFocused()) {
- updateSearch();
- }
- }, [notes]);
-
- const updateSearch = () => {
- SearchService.update({
- placeholder: `Search in ${params.current?.type === 'tag' ? '#' + alias : alias}`,
- data: notes,
- noSearch: false,
- type: 'notes',
- color: params.current?.type === 'color' ? params.current?.title : null,
- title:
- params.current?.type === 'tag'
- ? '#' + alias
- : alias.slice(0, 1).toUpperCase() + alias.slice(1),
-
- get: () => {
- return getNotes(params.current, false).notes;
- }
- });
- };
-
- const _onPressBottomButton = async () => {
- if (params.current?.get === 'monographs') {
- try {
- await openLinkInBrowser('https://docs.notesnook.com/monographs/', colors.accent);
- } catch (e) {}
- return;
- }
- setActionAfterFirstSave();
- if (!DDS.isTab) {
- if (getNote()) {
- eSendEvent(eOnLoadNote, { type: 'new' });
- editing.currentlyEditing = true;
- editing.movedAway = false;
- }
- tabBarRef.current?.goToPage(1);
- } else {
- eSendEvent(eOnLoadNote, { type: 'new' });
- }
- };
-
- const headerProps = {
- heading:
- params.current?.type === 'tag'
- ? '#' + alias
- : alias.slice(0, 1).toUpperCase() + alias.slice(1),
- color: params.current?.type === 'color' ? params.current?.title.toLowerCase() : null,
- paragraph: params.current?.type === 'topic' ? 'Edit topic' : null,
- onPress: () => {
- if (params.current?.type !== 'topic') return;
- eSendEvent(eOpenAddTopicDialog, {
- notebookId: params.current?.notebookId,
- toEdit: params.current
- });
- },
- icon: 'pencil'
- };
-
- const _refreshCallback = () => {
- init();
- };
-
- const placeholderData = {
- heading: params.current?.get === 'monographs' ? 'Your monographs' : 'Your notes',
- paragraph:
- params.current?.get === 'monographs'
- ? 'You have not published any notes as monographs yet.'
- : 'You have not added any notes yet.',
- button:
- params.current?.get === 'monographs' ? 'Learn more about monographs' : 'Add your first Note',
- action: _onPressBottomButton,
- buttonIcon: params.current?.get === 'monographs' ? 'information-outline' : null,
- loading:
- params.current?.get === 'monographs' ? 'Loading published notes' : 'Loading your notes.',
- type: params.current?.get === 'monographs' ? 'monographs' : null
- };
-
- const isFocused = () => navigation.isFocused();
-
- const headerRightButtons = [
- {
- title: 'Edit topic',
- func: () => {
- if (params.current?.type !== 'topic') return;
- eSendEvent(eOpenAddTopicDialog, {
- notebookId: params.current?.notebookId,
- toEdit: params.current
- });
- }
- },
- {
- title: 'Move notes',
- func: () => {
- if (params.current?.type !== 'topic') return;
- MoveNotes.present(db.notebooks.notebook(params.current?.notebookId).data, params.current);
- }
- }
- ];
-
- return (
- <>
- <SelectionHeader
- type={params.current?.type}
- extras={{
- topic: params.current?.id,
- notebook: params.current?.notebookId
- }}
- screen="NotesPage"
- />
- <ContainerHeader>
- <Header
- title={headerProps.heading}
- isBack={!params.current?.menu}
- screen="NotesPage"
- action={_onPressBottomButton}
- notebook={
- params.current?.notebookId && db.notebooks?.notebook(params.current?.notebookId).data
- }
- rightButtons={params.current?.type !== 'topic' ? null : headerRightButtons}
- />
- </ContainerHeader>
- <List
- listData={notes || []}
- type="notes"
- screen="NotesPage"
- warning={
- warning
- ? {
- title: 'Some notes in this topic are not synced'
- }
- : null
- }
- refreshCallback={_refreshCallback}
- headerProps={headerProps}
- loading={loading}
- focused={isFocused}
- placeholderText={`Add some notes to this" ${
- params.current?.type ? params.current?.type : 'topic.'
- }`}
- placeholderData={placeholderData}
- />
- {params.current?.get === 'monographs' ? null : (
- <FloatingButton
- title="Create a new note"
- onPress={_onPressBottomButton}
- color={params.current?.type == 'color' ? params.current?.title : null}
- />
- )}
- </>
- );
-};
-
-export default Notes;
diff --git a/apps/mobile/src/screens/notes/index.tsx b/apps/mobile/src/screens/notes/index.tsx
new file mode 100644
index 000000000..e6b986141
--- /dev/null
+++ b/apps/mobile/src/screens/notes/index.tsx
@@ -0,0 +1,166 @@
+import React, { useEffect, useRef, useState } from 'react';
+import { FloatingButton } from '../../components/container/floating-button';
+import { RightMenus } from '../../components/header/right-menus';
+import List from '../../components/list';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';
+import SearchService from '../../services/search';
+import useNavigationStore, { HeaderRightButton } from '../../stores/use-navigation-store';
+import { useNoteStore } from '../../stores/use-notes-store';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+import { NoteType } from '../../utils/types';
+import {
+ getAlias,
+ isSynced,
+ openEditor,
+ openMonographsWebpage,
+ setOnFirstSave,
+ toCamelCase
+} from './common';
+
+export const WARNING_DATA = {
+ title: 'Some notes in this topic are not synced'
+};
+
+export const PLACEHOLDER_DATA = {
+ heading: 'Your notes',
+ paragraph: 'You have not added any notes yet.',
+ button: 'Add your first Note',
+ action: openEditor,
+ loading: 'Loading your notes.'
+};
+
+export const MONOGRAPH_PLACEHOLDER_DATA = {
+ heading: 'Your monographs',
+ paragraph: 'You have not published any notes as monographs yet.',
+ button: 'Learn more about monographs',
+ action: openMonographsWebpage,
+ loading: 'Loading published notes.',
+ type: 'monographs',
+ buttonIcon: 'information-outline'
+};
+
+export interface RouteProps<T extends string> extends NavigationProps<T> {
+ get: (id: string, grouped?: boolean) => NoteType[];
+ placeholderData: any;
+ onPressFloatingButton: () => void;
+ focusControl?: boolean;
+ canGoBack?: boolean;
+ rightButtons?: (params: NotesScreenParams) => HeaderRightButton[];
+}
+
+const NotesPage = ({
+ route,
+ navigation,
+ get,
+ placeholderData,
+ onPressFloatingButton,
+ focusControl,
+ canGoBack,
+ rightButtons
+}: RouteProps<'NotesPage' | 'TaggedNotes' | 'Monographs' | 'ColoredNotes' | 'TopicNotes'>) => {
+ const [notes, setNotes] = useState<NoteType[]>(get(route.params?.item?.id));
+ const params = useRef<NotesScreenParams>(route?.params);
+ const [warning, setWarning] = useState(!isSynced(params.current));
+ const loading = useNoteStore(state => state.loading);
+ const alias = getAlias(params.current);
+ const isMonograph = route.name === 'Monographs';
+
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: prev => {
+ Navigation.routeNeedsUpdate(route.name, onRequestUpdate);
+ syncWithNavigation();
+ if (focusControl) return !prev;
+ return false;
+ },
+ onBlur: () => {
+ setOnFirstSave(null);
+ return false;
+ },
+ focusOnInit: !focusControl
+ });
+
+ const syncWithNavigation = () => {
+ const { item, title } = params.current;
+ useNavigationStore.getState().update(
+ {
+ name: route.name,
+ title: title,
+ id: item?.id,
+ type: 'notes'
+ },
+ params.current.canGoBack,
+ rightButtons && rightButtons(params.current)
+ );
+ SearchService.prepareSearch = prepareSearch;
+ RightMenus.floatingButtonAction = onPressFloatingButton;
+
+ !isMonograph &&
+ setOnFirstSave({
+ type: item.type,
+ id: item.id,
+ color: item.title,
+ //@ts-ignore
+ notebook: item.notebookId
+ });
+ };
+
+ const onRequestUpdate = (data?: NotesScreenParams) => {
+ if (data) params.current = data;
+ params.current.title = params.current.title || params.current.item.title;
+ const { item } = params.current;
+ try {
+ let notes = get(item.id) as NoteType[];
+ if ((item.type === 'tag' || item.type === 'color') && (!notes || notes.length === 0)) {
+ return Navigation.goBack();
+ }
+ if (item.type === 'topic') setWarning(isSynced(params.current));
+ setNotes(notes);
+ syncWithNavigation();
+ } catch (e) {}
+ };
+
+ useEffect(() => {
+ eSubscribeEvent(route.name, onRequestUpdate);
+ return () => {
+ eUnSubscribeEvent(route.name, onRequestUpdate);
+ };
+ }, []);
+
+ const prepareSearch = () => {
+ const { item } = params.current;
+ SearchService.update({
+ placeholder: `Search in ${alias}`,
+ type: 'notes',
+ title: item.type === 'tag' ? '#' + alias : toCamelCase(item.title),
+ get: () => {
+ return get(item.id, false);
+ }
+ });
+ };
+
+ return (
+ <>
+ <List
+ listData={notes}
+ warning={warning ? WARNING_DATA : null}
+ type="notes"
+ refreshCallback={onRequestUpdate}
+ loading={loading || !isFocused}
+ screen="Notes"
+ headerProps={{
+ heading: params.current.title,
+ color:
+ params.current?.item?.type === 'color' ? params.current?.item.title.toLowerCase() : null
+ }}
+ placeholderData={placeholderData}
+ />
+
+ {notes?.length > 0 || isFocused ? (
+ <FloatingButton title="Create a note" onPress={onPressFloatingButton} />
+ ) : null}
+ </>
+ );
+};
+
+export default NotesPage;
diff --git a/apps/mobile/src/screens/notes/monographs.tsx b/apps/mobile/src/screens/notes/monographs.tsx
new file mode 100644
index 000000000..2d7a88fcc
--- /dev/null
+++ b/apps/mobile/src/screens/notes/monographs.tsx
@@ -0,0 +1,41 @@
+import { groupArray } from 'notes-core/utils/grouping';
+import React from 'react';
+import NotesPage, { PLACEHOLDER_DATA } from '.';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import { db } from '../../utils/database';
+import { MonographType } from '../../utils/types';
+import { openMonographsWebpage } from './common';
+
+export const Monographs = ({ navigation, route }: NavigationProps<'Monographs'>) => {
+ return (
+ <NotesPage
+ navigation={navigation}
+ route={route}
+ get={Monographs.get}
+ placeholderData={PLACEHOLDER_DATA}
+ onPressFloatingButton={openMonographsWebpage}
+ canGoBack={route.params.canGoBack}
+ focusControl={true}
+ />
+ );
+};
+
+Monographs.get = (id: string, grouped = true) => {
+ let notes = db.monographs?.all || [];
+ return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;
+};
+
+Monographs.navigate = (item: MonographType, canGoBack: boolean) => {
+ Navigation.navigate<'Monographs'>(
+ {
+ name: 'Monographs',
+ type: 'monograph'
+ },
+ {
+ //@ts-ignore
+ item: { type: 'monograph' },
+ canGoBack,
+ title: 'Monographs'
+ }
+ );
+};
diff --git a/apps/mobile/src/screens/notes/tagged.tsx b/apps/mobile/src/screens/notes/tagged.tsx
new file mode 100644
index 000000000..68f382fc7
--- /dev/null
+++ b/apps/mobile/src/screens/notes/tagged.tsx
@@ -0,0 +1,46 @@
+import { groupArray } from 'notes-core/utils/grouping';
+import React from 'react';
+import NotesPage, { PLACEHOLDER_DATA } from '.';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import { db } from '../../utils/database';
+import { TagType } from '../../utils/types';
+import { getAlias, openEditor } from './common';
+
+export const TaggedNotes = ({ navigation, route }: NavigationProps<'TaggedNotes'>) => {
+ return (
+ <NotesPage
+ navigation={navigation}
+ route={route}
+ get={TaggedNotes.get}
+ placeholderData={PLACEHOLDER_DATA}
+ onPressFloatingButton={openEditor}
+ canGoBack={route.params.canGoBack}
+ focusControl={true}
+ />
+ );
+};
+
+TaggedNotes.get = (id: string, grouped = true) => {
+ let notes = db.notes?.tagged(id) || [];
+ return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;
+};
+
+TaggedNotes.navigate = (item: TagType, canGoBack: boolean) => {
+ if (!item) return;
+ //@ts-ignore TODO
+ let alias = getAlias({ item: item });
+ Navigation.navigate<'TaggedNotes'>(
+ {
+ name: 'TaggedNotes',
+ alias: '#' + alias,
+ title: item.title,
+ id: item.id,
+ type: 'tag'
+ },
+ {
+ item: item,
+ canGoBack,
+ title: '#' + alias
+ }
+ );
+};
diff --git a/apps/mobile/src/screens/notes/topicnotes.tsx b/apps/mobile/src/screens/notes/topicnotes.tsx
new file mode 100644
index 000000000..c060409d8
--- /dev/null
+++ b/apps/mobile/src/screens/notes/topicnotes.tsx
@@ -0,0 +1,70 @@
+import { groupArray } from 'notes-core/utils/grouping';
+import React from 'react';
+import NotesPage, { PLACEHOLDER_DATA } from '.';
+import { MoveNotes } from '../../components/sheets/move-notes/movenote';
+import { eSendEvent } from '../../services/event-manager';
+import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';
+import { db } from '../../utils/database';
+import { eOpenAddTopicDialog } from '../../utils/events';
+import { TopicType } from '../../utils/types';
+import { openEditor } from './common';
+
+const headerRightButtons = (params: NotesScreenParams) => [
+ {
+ title: 'Edit topic',
+ onPress: () => {
+ const { item } = params;
+ if (item.type !== 'topic') return;
+ eSendEvent(eOpenAddTopicDialog, {
+ notebookId: item.notebookId,
+ toEdit: item
+ });
+ }
+ },
+ {
+ title: 'Move notes',
+ onPress: () => {
+ const { item } = params;
+ if (item?.type !== 'topic') return;
+ MoveNotes.present(db.notebooks?.notebook(item.notebookId).data, item);
+ }
+ }
+];
+
+export const TopicNotes = ({ navigation, route }: NavigationProps<'TopicNotes'>) => {
+ return (
+ <NotesPage
+ navigation={navigation}
+ route={route}
+ get={TopicNotes.get}
+ placeholderData={PLACEHOLDER_DATA}
+ onPressFloatingButton={openEditor}
+ rightButtons={headerRightButtons}
+ canGoBack={route.params.canGoBack}
+ focusControl={true}
+ />
+ );
+};
+
+TopicNotes.get = (id: string, grouped = true) => {
+ let notes = db.notes?.tagged(id) || [];
+ return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;
+};
+
+TopicNotes.navigate = (item: TopicType, canGoBack: boolean) => {
+ if (!item) return;
+ Navigation.navigate<'TopicNotes'>(
+ {
+ name: 'TopicNotes',
+ title: item.title,
+ id: item.id,
+ type: 'topic',
+ notebookId: item.notebookId
+ },
+ {
+ item: item,
+ canGoBack,
+ title: item.title
+ }
+ );
+};
diff --git a/apps/mobile/src/screens/search/index.js b/apps/mobile/src/screens/search/index.js
index 313b079fc..65bbddc56 100644
--- a/apps/mobile/src/screens/search/index.js
+++ b/apps/mobile/src/screens/search/index.js
@@ -1,36 +1,41 @@
-import React, { useCallback, useEffect } from 'react';
+import React, { useEffect } from 'react';
import { ContainerHeader } from '../../components/container/containerheader';
-import SelectionHeader from '../../components/selection-header';
import List from '../../components/list';
-import { useSearchStore } from '../../stores/stores';
import SearchService from '../../services/search';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useSearchStore } from '../../stores/use-search-store';
import { inputRef } from '../../utils/global-refs';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
import { sleep } from '../../utils/time';
import { SearchBar } from './search-bar';
-export const Search = ({ navigation }) => {
+export const Search = ({ navigation, route }) => {
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());
- }, []);
+ useNavigationFocus(navigation, {
+ onFocus: () => {
+ sleep(300).then(() => inputRef.current?.focus());
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+ return false;
+ },
+ onBlur: () => false
+ });
useEffect(() => {
- navigation.addListener('focus', onFocus);
return () => {
setSearchResults([]);
setSearchStatus(false, null);
- navigation.removeListener('focus', onFocus);
};
}, []);
return (
<>
- <SelectionHeader screen="Search" />
<ContainerHeader>
<SearchBar />
</ContainerHeader>
diff --git a/apps/mobile/src/screens/search/searchbar.js b/apps/mobile/src/screens/search/searchbar.js
index 3c2616b50..810597eb6 100644
--- a/apps/mobile/src/screens/search/searchbar.js
+++ b/apps/mobile/src/screens/search/searchbar.js
@@ -3,8 +3,8 @@ import { Platform, View } from 'react-native';
import { TextInput } from 'react-native-gesture-handler';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { IconButton } from '../../components/ui/icon-button';
-import { useThemeStore } from '../../stores/theme';
-import { useSearchStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useSearchStore } from '../../stores/use-search-store';
import { eSubscribeEvent, eUnSubscribeEvent, ToastEvent } from '../../services/event-manager';
import Navigation from '../../services/navigation';
import SearchService from '../../services/search';
diff --git a/apps/mobile/src/screens/settings/2fa.tsx b/apps/mobile/src/screens/settings/2fa.tsx
index 9310ba5e5..17aaf0db3 100644
--- a/apps/mobile/src/screens/settings/2fa.tsx
+++ b/apps/mobile/src/screens/settings/2fa.tsx
@@ -14,8 +14,8 @@ import { SvgView } from '../../components/ui/svg';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
-import { useUserStore } from '../../stores/stores';
-import { ThemeStore, useThemeStore } from '../../stores/theme';
+import { useUserStore } from '../../stores/use-user-store';
+import { ThemeStore, useThemeStore } from '../../stores/use-theme-store';
import { db } from '../../utils/database';
import Storage from '../../utils/database/storage';
import { eCloseProgressDialog } from '../../utils/events';
diff --git a/apps/mobile/src/screens/settings/appearance.js b/apps/mobile/src/screens/settings/appearance.js
index b9eb9a1a9..b40615e22 100644
--- a/apps/mobile/src/screens/settings/appearance.js
+++ b/apps/mobile/src/screens/settings/appearance.js
@@ -9,8 +9,8 @@ import { DDS } from '../../services/device-detection';
import { ToastEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
-import { useSettingStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { hexToRGBA, RGB_Linear_Shade, switchAccentColor } from '../../utils/color-scheme/utils';
import { MenuItemsList } from '../../utils/constants';
import { tabBarRef } from '../../utils/global-refs';
diff --git a/apps/mobile/src/screens/settings/applock.js b/apps/mobile/src/screens/settings/applock.js
index 9b585ad47..fbe0478e2 100644
--- a/apps/mobile/src/screens/settings/applock.js
+++ b/apps/mobile/src/screens/settings/applock.js
@@ -6,8 +6,8 @@ import { PressableButton } from '../../components/ui/pressable';
import Seperator from '../../components/ui/seperator';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
-import { useThemeStore } from '../../stores/theme';
-import { useSettingStore } from '../../stores/stores';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useSettingStore } from '../../stores/use-setting-store';
import { presentSheet } from '../../services/event-manager';
import SettingsService from '../../services/settings';
import { SIZE } from '../../utils/size';
diff --git a/apps/mobile/src/screens/settings/backuprestore.js b/apps/mobile/src/screens/settings/backuprestore.js
index 94dc4b0d3..4b75799b3 100644
--- a/apps/mobile/src/screens/settings/backuprestore.js
+++ b/apps/mobile/src/screens/settings/backuprestore.js
@@ -4,8 +4,9 @@ import Paragraph from '../../components/ui/typography/paragraph';
import Backup from '../../services/backup';
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
-import { useSettingStore, useUserStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useUserStore } from '../../stores/use-user-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
export const AutomaticBackupsSelector = () => {
diff --git a/apps/mobile/src/screens/settings/group.tsx b/apps/mobile/src/screens/settings/group.tsx
index ca8e8467b..cfbaa37b4 100644
--- a/apps/mobile/src/screens/settings/group.tsx
+++ b/apps/mobile/src/screens/settings/group.tsx
@@ -1,12 +1,25 @@
import { NativeStackScreenProps } from '@react-navigation/native-stack';
-import React from 'react';
+import React, { useEffect } from 'react';
import { FlatList, View } from 'react-native';
import { ContainerHeader } from '../../components/container/containerheader';
import { Header } from '../../components/header';
+import { tabBarRef } from '../../utils/global-refs';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
import { SectionItem } from './section-item';
import { RouteParams, SettingSection } from './types';
const Group = ({ navigation, route }: NativeStackScreenProps<RouteParams, 'SettingsGroup'>) => {
+ useNavigationFocus(navigation, {
+ onFocus: () => {
+ tabBarRef.current?.lock();
+ return false;
+ }
+ });
+ useEffect(() => {
+ return () => {
+ tabBarRef.current?.unlock();
+ };
+ }, []);
const renderItem = ({ item, index }: { item: SettingSection; index: number }) => (
<SectionItem item={item} />
);
diff --git a/apps/mobile/src/screens/settings/home.tsx b/apps/mobile/src/screens/settings/home.tsx
index 485fc7825..c28ec8be9 100644
--- a/apps/mobile/src/screens/settings/home.tsx
+++ b/apps/mobile/src/screens/settings/home.tsx
@@ -1,819 +1,47 @@
import { NativeStackScreenProps } from '@react-navigation/native-stack';
-import React, { useEffect, useState } from 'react';
-import { FlatList, Linking, Platform, View } from 'react-native';
-import { enabled } from 'react-native-privacy-snapshot';
-import { APP_VERSION } from '../../../version';
-import { ChangePassword } from '../../components/auth/change-password';
+import React, { useEffect, useRef, useState } from 'react';
+import { FlatList, View } from 'react-native';
+import { Bar } from 'react-native-progress';
import { ContainerHeader } from '../../components/container/containerheader';
-import { Header } from '../../components/header';
-import { Issue } from '../../components/sheets/github/issue';
-import { Progress } from '../../components/sheets/progress';
-import BackupService from '../../services/backup';
-import {
- eSendEvent,
- eSubscribeEvent,
- eUnSubscribeEvent,
- openVault,
- presentSheet,
- ToastEvent
-} from '../../services/event-manager';
-import Notifications from '../../services/notifications';
-import PremiumService from '../../services/premium';
-import SettingsService from '../../services/settings';
-import { useSettingStore, useUserStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
-import { AndroidModule } from '../../utils';
-import { toggleDarkMode } from '../../utils/color-scheme/utils';
-
-import AnimatedProgress from 'react-native-reanimated-progress-bar';
-import * as RNIap from 'react-native-iap';
-import {
- eCloseProgressDialog,
- eCloseSimpleDialog,
- eOpenAttachmentsDialog,
- eOpenLoginDialog,
- eOpenRecoveryKeyDialog,
- eOpenRestoreDialog
-} from '../../utils/events';
-import { openLinkInBrowser } from '../../utils/functions';
-import { useVaultStatus } from '../../utils/hooks/use-vault-status';
-import { sleep } from '../../utils/time';
-import AppLock from './app-lock';
-import { verifyUser } from './functions';
-import { SectionGroup } from './section-group';
-import { RouteParams, SettingSection } from './types';
-import SettingsUserSection, { getTimeLeft } from './user-section';
-import Sync from '../../services/sync';
-import { MFARecoveryCodes, MFASheet } from './2fa';
-import { db } from '../../utils/database';
-import { SUBSCRIPTION_STATUS } from '../../utils/constants';
-import dayjs from 'dayjs';
-import BiometicService from '../../services/biometrics';
-import { presentDialog } from '../../components/dialog/functions';
-import { checkVersion } from 'react-native-check-version';
-import { Update } from '../../components/sheets/update';
import BaseDialog from '../../components/dialog/base-dialog';
+import { Header } from '../../components/header';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useThemeStore } from '../../stores/use-theme-store';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
import { SIZE } from '../../utils/size';
-import { tabBarRef } from '../../utils/global-refs';
-const format = (ver: number) => {
- let parts = ver.toString().split('');
- return `v${parts[0]}.${parts[1]}.${parts[2]?.startsWith('0') ? '' : parts[2]}${
- !parts[3] ? '' : parts[3]
- } `;
-};
-
-const groups: SettingSection[] = [
- {
- name: 'account',
- sections: [
- {
- useHook: () => useUserStore(state => state.user),
- hidden: current => !current,
- name: current => {
- const user = current;
- const isBasic = user.subscription?.type === SUBSCRIPTION_STATUS.BASIC;
- const isTrial = user.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;
- return isBasic
- ? 'Subscribe to Pro'
- : isTrial
- ? 'Your free trial has started'
- : 'Subscription details';
- },
- type: 'component',
- component: 'subscription',
- icon: 'crown',
- description: current => {
- const user = current;
- const subscriptionDaysLeft = user && getTimeLeft(parseInt(user.subscription?.expiry));
- const expiryDate = dayjs(user?.subscription?.expiry).format('MMMM D, YYYY');
- const startDate = dayjs(user?.subscription?.start).format('MMMM D, YYYY');
-
- return user.subscription?.type === 2
- ? 'You signed up on ' + startDate
- : user.subscription?.type === 1
- ? 'Your free trial will end on ' + expiryDate
- : user.subscription?.type === 6
- ? subscriptionDaysLeft.time < -3
- ? 'Your subscription has ended'
- : 'Your account will be downgraded to Basic in 3 days'
- : user.subscription?.type === 7
- ? `Your subscription will end on ${expiryDate}.`
- : user.subscription?.type === 5
- ? `Your subscription will renew on ${expiryDate}.`
- : 'Never hesitate to choose privacy';
- }
- },
- {
- type: 'screen',
- name: 'Account Settings',
- icon: 'account-cog',
- description: 'Manage account',
- sections: [
- {
- name: 'Save data recovery key',
- modifer: async () => {
- verifyUser(null, async () => {
- await sleep(300);
- eSendEvent(eOpenRecoveryKeyDialog);
- });
- },
- description: 'Recover your data using the recovery key if your password is lost.'
- },
- {
- name: 'Manage attachments',
- icon: 'attachment',
- modifer: () => {
- eSendEvent(eOpenAttachmentsDialog);
- },
- description: 'Manage all attachments in one place.'
- },
- {
- name: 'Change password',
- modifer: async () => {
- ChangePassword.present();
- },
- description: 'Setup a new password for your account.'
- },
- {
- type: 'screen',
- name: 'Two factor authentication',
- description: 'Manage 2FA settings',
- icon: 'two-factor-authentication',
- sections: [
- {
- name: 'Enable two-factor authentication',
- modifer: () => {
- verifyUser('global', async () => {
- MFASheet.present();
- });
- },
- hidden: () => {
- let user = useUserStore.getState().user;
- return !!user?.mfa?.isEnabled;
- },
- description: 'Increased security for your account'
- },
- {
- name: 'Add fallback 2FA method',
- hidden: () => {
- let user = useUserStore.getState().user;
-
- return !!user?.mfa?.secondaryMethod || !user?.mfa?.isEnabled;
- },
- modifer: () => {
- verifyUser('global', async () => {
- MFASheet.present(true);
- });
- },
- description:
- 'You can use fallback 2FA method incase you are unable to login via primary method'
- },
- {
- name: 'Reconfigure fallback 2FA method',
- hidden: () => {
- let user = useUserStore.getState().user;
- return !user?.mfa?.secondaryMethod || !user?.mfa?.isEnabled;
- },
- modifer: () => {
- verifyUser('global', async () => {
- MFASheet.present(true);
- });
- },
- description:
- 'You can use fallback 2FA method incase you are unable to login via primary method'
- },
- {
- name: 'View recovery codes',
- modifer: () => {
- verifyUser('global', async () => {
- MFARecoveryCodes.present('sms');
- });
- },
- hidden: () => {
- let user = useUserStore.getState().user;
- return !user?.mfa?.isEnabled;
- },
- description: 'View and save recovery codes for to recover your account'
- },
- {
- name: 'Disable two-factor authentication',
- modifer: () => {
- verifyUser('global', async () => {
- await db.mfa?.disable();
- let user = await db.user?.fetchUser();
- useUserStore.getState().setUser(user);
- });
- },
- hidden: () => {
- let user = useUserStore.getState().user;
- return !user?.mfa?.isEnabled;
- },
- description: 'Decreased security for your account'
- }
- ]
- },
- {
- name: 'Subscription not activated?',
- hidden: () => Platform.OS !== 'ios',
- modifer: async () => {
- if (Platform.OS === 'android') return;
- presentSheet({
- title: 'Loading subscriptions',
- paragraph: `Please wait while we fetch your subscriptions.`
- });
- let subscriptions = await RNIap.getPurchaseHistory();
- subscriptions.sort((a, b) => b.transactionDate - a.transactionDate);
- let currentSubscription = subscriptions[0];
- presentSheet({
- title: 'Notesnook Pro',
- paragraph: `You subscribed to Notesnook Pro on ${new Date(
- currentSubscription.transactionDate
- ).toLocaleString()}. Verify this subscription?`,
- action: async () => {
- presentSheet({
- title: 'Verifying subscription',
- paragraph: `Please wait while we verify your subscription.`
- });
- await PremiumService.subscriptions.verify(currentSubscription);
- eSendEvent(eCloseProgressDialog);
- },
- icon: 'information-outline',
- actionText: 'Verify'
- });
- },
- description: 'Verify your subscription to Notesnook Pro'
- },
- {
- name: 'Log out',
- description: 'Clear all your data and reset the app.',
- icon: 'logout',
- modifer: () => {
- presentDialog({
- title: 'Logout',
- paragraph: 'Clear all your data and reset the app.',
- positiveText: 'Logout',
- positivePress: async () => {
- try {
- eSendEvent(eCloseSimpleDialog);
- await sleep(100);
- eSendEvent('settings-loading', true);
- await db.user?.logout();
- await BiometicService.resetCredentials();
- await SettingsService.set({
- introCompleted: true
- });
- eSendEvent('settings-loading', false);
- } catch (e) {
- eSendEvent('settings-loading', false);
- }
- }
- });
- }
- },
- {
- type: 'danger',
- name: 'Delete account',
- icon: 'alert',
- description: `All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.`,
- modifer: () => {
- presentDialog({
- title: 'Delete account',
- paragraphColor: 'red',
- paragraph:
- 'All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.',
- positiveType: 'errorShade',
- input: true,
- inputPlaceholder: 'Enter account password',
- positiveText: 'Delete',
- positivePress: async value => {
- try {
- let verified = await db.user?.verifyPassword(value);
- if (verified) {
- eSendEvent('settings-loading', true);
- await db.user?.deleteUser(value);
- await BiometicService.resetCredentials();
- SettingsService.set({
- introCompleted: true
- });
- } else {
- ToastEvent.show({
- heading: 'Incorrect password',
- message: 'The account password you entered is incorrect',
- type: 'error',
- context: 'global'
- });
- }
-
- eSendEvent('settings-loading', false);
- } catch (e) {
- eSendEvent('settings-loading', false);
- console.log(e);
- ToastEvent.show({
- heading: 'Failed to delete account',
- message: e?.message,
- type: 'error',
- context: 'global'
- });
- }
- }
- });
- }
- }
- ]
- },
- {
- name: 'Having problems with sync',
- description: 'Try force sync to resolve issues with syncing',
- icon: 'sync-alert',
- modifer: async () => {
- Progress.present();
- await Sync.run('global', true);
- eSendEvent(eCloseProgressDialog);
- }
- }
- ]
- },
- {
- name: 'Customize',
- sections: [
- {
- type: 'screen',
- name: 'Theme',
- description: 'Change app look and feel',
- icon: 'shape',
- sections: [
- {
- type: 'component',
- name: 'Accent color',
- description: 'Pick the color that matches your mood',
- component: 'colorpicker'
- },
- {
- type: 'switch',
- name: 'Use system theme',
- description: 'Automatically switch to dark mode when system theme changes',
- property: 'useSystemTheme',
- icon: 'circle-half'
- },
- {
- type: 'switch',
- name: 'Dark mode',
- description: 'Strain your eyes no more at night',
- property: 'theme',
- icon: 'brightness-6',
- modifer: () => {
- toggleDarkMode();
- },
- getter: () => useSettingStore.getState().settings.theme.dark
- },
- {
- type: 'switch',
- name: 'Pitch black',
- description: 'Save battery on device with amoled screen at night.',
- property: 'pitchBlack',
- icon: 'brightness-1'
- }
- ]
- },
- {
- type: 'screen',
- name: 'Behaviour',
- description: 'Change app homepage',
- sections: [
- {
- type: 'component',
- name: 'Homepage',
- description: 'Default screen to open on app startup',
- component: 'homeselector'
- }
- ]
- }
- ]
- },
- {
- name: 'Privacy and security',
- sections: [
- {
- type: 'switch',
- name: 'Telemetry',
- icon: 'radar',
- description:
- 'Contribute towards a better Notesnook. All tracking information is anonymous.',
- property: 'telemetry'
- },
- {
- type: 'screen',
- name: 'Vault',
- description: 'Multi-layer encryption to most important notes',
- icon: 'key',
- sections: [
- {
- name: 'Create vault',
- description: 'Set a password to create vault and lock notes.',
- icon: 'key',
- useHook: useVaultStatus,
- hidden: current => current?.exists,
- modifer: () => {
- PremiumService.verify(() => {
- openVault({
- item: {},
- novault: false,
- title: 'Create vault',
- description: 'Set a password to create vault and lock notes.'
- });
- });
- }
- },
- {
- useHook: useVaultStatus,
- name: 'Change vault password',
- description: 'Setup a new password for your vault.',
- hidden: current => !current?.exists,
- modifer: () =>
- openVault({
- item: {},
- changePassword: true,
- novault: true,
- title: 'Change vault password',
- description: 'Set a new password for your vault.'
- })
- },
- {
- useHook: useVaultStatus,
- name: 'Clear vault',
- description: 'Unlock all locked notes',
- hidden: current => !current?.exists,
- modifer: () => {
- openVault({
- item: {},
- clearVault: true,
- novault: true,
- title: 'Clear vault',
- description: 'Enter vault password to unlock and remove all notes from the vault.'
- });
- }
- },
- {
- name: 'Delete vault',
- description: 'Delete vault (and optionally remove all notes).',
- useHook: useVaultStatus,
- hidden: current => !current?.exists,
- modifer: () => {
- openVault({
- item: {},
- deleteVault: true,
- novault: true,
- title: 'Delete vault',
- description: 'Enter your account password to delete your vault.'
- });
- }
- },
- {
- type: 'switch',
- name: 'Biometric unlocking',
- icon: 'fingerprint',
- useHook: useVaultStatus,
- description: 'Access notes in vault using biometrics',
- hidden: current => !current?.exists || !current?.isBiometryAvailable,
- getter: current => current?.biometryEnrolled,
- modifer: current => {
- openVault({
- item: {},
- fingerprintAccess: !current.biometryEnrolled,
- revokeFingerprintAccess: current.biometryEnrolled,
- novault: true,
- title: current.biometryEnrolled
- ? 'Revoke biometric unlocking'
- : 'Enable biometery unlock',
- description: current.biometryEnrolled
- ? 'Disable biometric unlocking for notes in vault'
- : 'Enable biometric unlocking for notes in vault'
- });
- }
- }
- ]
- },
- {
- type: 'switch',
- icon: 'eye-off-outline',
- name: 'Privacy mode',
- description: `Hide app contents when you switch to other apps. This will also disable screenshot taking in the app.`,
- modifer: () => {
- const settings = SettingsService.get();
- Platform.OS === 'android'
- ? AndroidModule.setSecureMode(!settings.privacyScreen)
- : enabled(true);
-
- SettingsService.set({ privacyScreen: !settings.privacyScreen });
- },
- property: 'privacyScreen'
- },
- {
- name: 'App lock',
- description: 'Change app lock mode to suit your needs',
- icon: 'fingerprint',
- modifer: () => {
- AppLock.present();
- }
- }
- ]
- },
- {
- name: 'Backup and restore',
- sections: [
- {
- type: 'screen',
- name: 'Backups',
- icon: 'backup-restore',
- description: 'Create a backup or change backup settings',
- sections: [
- {
- name: 'Backup now',
- description: 'Create a backup of your data',
- modifer: async () => {
- const user = useUserStore.getState().user;
- if (!user) {
- await BackupService.run(true);
- return;
- }
- verifyUser(null, () => BackupService.run(true));
- }
- },
- {
- type: 'component',
- name: 'Automatic backups',
- description: 'Backup your data once every week or daily automatically.',
- component: 'autobackups'
- },
- {
- name: 'Select backup directory',
- description: 'Select directory to store backups',
- icon: 'folder',
- hidden: () =>
- !!SettingsService.get().backupDirectoryAndroid || Platform.OS !== 'android',
- property: 'backupDirectoryAndroid',
- modifer: async () => {
- let dir;
- try {
- let dir = await BackupService.checkBackupDirExists(true);
- } catch (e) {
- } finally {
- if (!dir) {
- ToastEvent.show({
- heading: 'No directory selected',
- type: 'error'
- });
- }
- }
- }
- },
- {
- name: 'Change backup directory',
- description: () => SettingsService.get().backupDirectoryAndroid?.name || '',
- icon: 'folder',
- hidden: () =>
- !SettingsService.get().backupDirectoryAndroid || Platform.OS !== 'android',
- property: 'backupDirectoryAndroid',
- modifer: async () => {
- let dir;
- try {
- dir = await BackupService.checkBackupDirExists(true);
- } catch (e) {
- } finally {
- if (!dir) {
- ToastEvent.show({
- heading: 'No directory selected',
- type: 'error'
- });
- }
- }
- }
- },
- {
- type: 'switch',
- name: 'Backup encryption',
- description: 'Encrypt all your backups.',
- icon: 'lock',
- property: 'encryptedBackup',
- modifer: async () => {
- const user = useUserStore.getState().user;
- const settings = SettingsService.get();
- if (!user) {
- ToastEvent.show({
- heading: 'Login required to enable encryption',
- type: 'error',
- func: () => {
- eSendEvent(eOpenLoginDialog);
- },
- actionText: 'Login'
- });
- return;
- }
- await SettingsService.set({ encryptedBackup: !settings.encryptedBackup });
- }
- }
- ]
- },
- {
- name: 'Restore backup',
- description: `Restore backup from phone storage.`,
- modifer: () => {
- const user = useUserStore.getState().user;
- if (!user || !user?.email) {
- ToastEvent.show({
- heading: 'Login required',
- message: 'Please log in to your account to restore backup',
- type: 'error',
- context: 'global'
- });
- return;
- }
- eSendEvent(eOpenRestoreDialog);
- }
- }
- ]
- },
- {
- name: 'Productivity',
- hidden: () => Platform.OS !== 'android',
- sections: [
- {
- type: 'switch',
- name: 'Notes in notifications',
- description: `Add quick notes from notifications without opening the app.`,
- property: 'notifNotes',
- icon: 'form-textbox',
- modifer: () => {
- const settings = SettingsService.get();
- if (settings.notifNotes) {
- Notifications.unpinQuickNote();
- } else {
- Notifications.pinQuickNote(false);
- }
- SettingsService.toggle('notifNotes');
- }
- }
- ]
- },
- {
- name: 'Help and support',
- sections: [
- {
- name: 'Report an issue',
- icon: 'bug',
- modifer: () => {
- presentSheet({
- component: <Issue />
- });
- },
- description: 'Faced an issue or have a suggestion? Click here to create a bug report'
- },
- {
- name: 'Documentation',
- modifer: async () => {
- Linking.openURL('https://docs.notesnook.com');
- },
- description: 'Learn about every feature and how it works.',
- icon: 'file-document'
- },
- {
- type: 'switch',
- name: 'Debug mode',
- description: 'Show debug options on items',
- property: 'devMode'
- }
- ]
- },
- {
- name: 'community',
- sections: [
- {
- name: 'Join our Telegram group',
- description: "We are on telegram, let's talk",
- icon: 'telegram',
- modifer: () => {
- Linking.openURL('https://t.me/notesnook').catch(console.log);
- }
- },
- {
- name: 'Join our Discord community',
- icon: 'discord',
- modifer: async () => {
- presentSheet({
- title: 'Join our Discord Community',
- iconColor: 'discord',
- paragraph: 'We are not ghosts, chat with us and share your experience.',
- valueArray: [
- 'Talk with us anytime.',
- 'Follow the development process',
- 'Give suggestions and report issues.',
- 'Get early access to new features',
- 'Meet other people using Notesnook'
- ],
- icon: 'discord',
- action: async () => {
- try {
- Linking.openURL('https://discord.gg/zQBK97EE22').catch(console.log);
- } catch (e) {}
- },
- actionText: 'Join Now'
- });
- },
- description: 'We are not ghosts, chat with us and share your experience.'
- }
- ]
- },
- {
- name: 'legal',
- sections: [
- {
- name: 'Terms of service',
- modifer: async () => {
- try {
- await Linking.openURL('https://notesnook.com/tos');
- } catch (e) {}
- },
- description: 'Read our terms of service'
- },
- {
- name: 'Privacy policy',
- modifer: async () => {
- try {
- await Linking.openURL('https://notesnook.com/privacy');
- } catch (e) {}
- },
- description: 'Read our privacy policy'
- }
- ]
- },
- {
- name: 'about',
- sections: [
- {
- name: 'Download on desktop',
- icon: 'monitor',
- modifer: async () => {
- try {
- await Linking.openURL('https://notesnook.com');
- } catch (e) {}
- },
- description: 'Get Notesnook app on your desktop and access all notes'
- },
- {
- name: 'Roadmap',
- icon: 'chart-timeline',
- modifer: async () => {
- try {
- await Linking.openURL('https://docs.notesnook.com/roadmap/');
- } catch (e) {}
- },
- description: 'See what the future of Notesnook is going to be like.'
- },
- {
- name: 'Check for updates',
- icon: 'cellphone-arrow-down',
- description: 'Check for new version of Notesnook',
- modifer: async () => {
- const version = await checkVersion();
- if (!version.needsUpdate) {
- ToastEvent.show({
- heading: 'You are on latest version',
- type: 'success',
- context: 'global'
- });
- return false;
- }
- presentSheet({
- component: ref => <Update version={version} fwdRef={ref} />
- });
- }
- },
- {
- name: 'App version',
- icon: 'alpha-v',
- modifer: async () => {
- try {
- await Linking.openURL('https://notesnook.com');
- } catch (e) {}
- },
- description: format(APP_VERSION)
- }
- ]
- }
-];
+import { SectionGroup } from './section-group';
+import { settingsGroups } from './settings-data';
+import { RouteParams, SettingSection } from './types';
+import SettingsUserSection from './user-section';
-const Home = ({ navigation }: NativeStackScreenProps<RouteParams, 'SettingsHome'>) => {
+const Home = ({ navigation, route }: NativeStackScreenProps<RouteParams, 'SettingsHome'>) => {
const colors = useThemeStore(state => state.colors);
const [loading, setLoading] = useState(false);
+ const flatlistRef = useRef<FlatList<SettingSection>>(null);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: () => {
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+ return true;
+ },
+ onBlur: () => {
+ flatlistRef.current?.scrollToOffset({
+ offset: 0,
+ animated: false
+ });
+ return navigation.getState().index === 0;
+ }
+ });
const renderItem = ({ item, index }: { item: SettingSection; index: number }) =>
item.name === 'account' ? <SettingsUserSection item={item} /> : <SectionGroup item={item} />;
useEffect(() => {
eSubscribeEvent('settings-loading', setLoading);
-
return () => {
eUnSubscribeEvent('settings-loading', setLoading);
};
@@ -826,7 +54,7 @@ const Home = ({ navigation }: NativeStackScreenProps<RouteParams, 'SettingsHome'
</ContainerHeader>
{loading && (
- <BaseDialog bounce={false} visible={true}>
+ <BaseDialog animated={false} bounce={false} visible={true}>
<View
style={{
width: '100%',
@@ -845,19 +73,29 @@ const Home = ({ navigation }: NativeStackScreenProps<RouteParams, 'SettingsHome'
<View
style={{
flexDirection: 'row',
- height: 10,
width: 100,
marginTop: 15
}}
>
- <AnimatedProgress fill={colors.accent} total={8} current={8} />
+ <Bar
+ height={5}
+ width={100}
+ animated={true}
+ useNativeDriver
+ indeterminate
+ indeterminateAnimationDuration={2000}
+ unfilledColor={colors.nav}
+ color={colors.accent}
+ borderWidth={0}
+ />
</View>
</View>
</BaseDialog>
)}
<FlatList
- data={groups}
+ data={isFocused ? settingsGroups : settingsGroups.slice(0, 3)}
+ ref={flatlistRef}
keyExtractor={(item, index) =>
typeof item.name === 'function'
? item.name({}) || index.toString()
diff --git a/apps/mobile/src/screens/settings/index.js b/apps/mobile/src/screens/settings/index.js
deleted file mode 100644
index 129c3fce4..000000000
--- a/apps/mobile/src/screens/settings/index.js
+++ /dev/null
@@ -1,55 +0,0 @@
-import { createNativeStackNavigator } from '@react-navigation/native-stack';
-import React from 'react';
-import { useThemeStore } from '../../stores/theme';
-import Group from './group';
-import Home from './home';
-
-const SettingsStack = createNativeStackNavigator();
-
-export const Settings = () => {
- const colors = useThemeStore(state => state.colors);
- return (
- <SettingsStack.Navigator
- initialRouteName="SettingsHome"
- screenOptions={{
- animation: 'none',
- headerShown: false,
- contentStyle: {
- backgroundColor: colors.bg
- }
- }}
- >
- <SettingsStack.Screen name="SettingsHome" component={Home} />
- <SettingsStack.Screen name="SettingsGroup" component={Group} />
- </SettingsStack.Navigator>
- );
-};
-
-export default Settings;
-
-/**
- *
- *
- *
-
- <View
- style={{
- height: '100%',
- backgroundColor: colors.bg
- }}
- >
- <ScrollView
- onScroll={e =>
- eSendEvent(eScrollEvent, {
- y: e.nativeEvent.contentOffset.y,
- screen: 'Settings'
- })
- }
- testID="scrollview"
- scrollEventThrottle={1}
- style={{
- paddingHorizontal: 0
- }}
- ></ScrollView>
- </View>
- */
diff --git a/apps/mobile/src/screens/settings/index.tsx b/apps/mobile/src/screens/settings/index.tsx
new file mode 100644
index 000000000..6d1024b9a
--- /dev/null
+++ b/apps/mobile/src/screens/settings/index.tsx
@@ -0,0 +1,34 @@
+import { createNativeStackNavigator } from '@react-navigation/native-stack';
+import React from 'react';
+import { useThemeStore } from '../../stores/use-theme-store';
+import Group from './group';
+import Home from './home';
+
+const SettingsStack = createNativeStackNavigator();
+
+export const Settings = () => {
+ const colors = useThemeStore(state => state.colors);
+ return (
+ <SettingsStack.Navigator
+ initialRouteName="SettingsHome"
+ screenOptions={{
+ animation: 'none',
+ headerShown: false,
+ contentStyle: {
+ backgroundColor: colors.bg
+ }
+ }}
+ >
+ <SettingsStack.Screen name="SettingsHome" component={Home} />
+ <SettingsStack.Screen
+ options={{
+ animation: 'default'
+ }}
+ name="SettingsGroup"
+ component={Group}
+ />
+ </SettingsStack.Navigator>
+ );
+};
+
+export default Settings;
diff --git a/apps/mobile/src/screens/settings/sectiongroup.tsx b/apps/mobile/src/screens/settings/sectiongroup.tsx
index bb8a626d0..041d708c5 100644
--- a/apps/mobile/src/screens/settings/sectiongroup.tsx
+++ b/apps/mobile/src/screens/settings/sectiongroup.tsx
@@ -1,14 +1,15 @@
import React from 'react';
import { View } from 'react-native';
import Heading from '../../components/ui/typography/heading';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { SectionItem } from './section-item';
import { SettingSection } from './types';
export const SectionGroup = ({ item }: { item: SettingSection }) => {
const colors = useThemeStore(state => state.colors);
- const isHidden = item.hidden && item.hidden(null);
+ const current = item.useHook && item.useHook();
+ const isHidden = item.hidden && item.hidden(current);
return isHidden ? null : (
<View
style={{
diff --git a/apps/mobile/src/screens/settings/sectionitem.tsx b/apps/mobile/src/screens/settings/sectionitem.tsx
index f777851ee..ed21839d3 100644
--- a/apps/mobile/src/screens/settings/sectionitem.tsx
+++ b/apps/mobile/src/screens/settings/sectionitem.tsx
@@ -7,8 +7,8 @@ import { PressableButton } from '../../components/ui/pressable';
import Seperator from '../../components/ui/seperator';
import Paragraph from '../../components/ui/typography/paragraph';
import SettingsService from '../../services/settings';
-import { useSettingStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SIZE } from '../../utils/size';
import { AccentColorPicker, HomagePageSelector } from './appearance';
import { AutomaticBackupsSelector } from './backup-restore';
@@ -22,125 +22,127 @@ const components: { [name: string]: ReactElement } = {
subscription: <Subscription />
};
-export const SectionItem = ({ item }: { item: SettingSection }) => {
- const colors = useThemeStore(state => state.colors);
- const settings = useSettingStore(state => state.settings);
- const navigation = useNavigation<NavigationProp<RouteParams>>();
- const current = item.useHook && item.useHook(item);
- const isHidden = item.hidden && item.hidden(item.property || current);
+export const SectionItem = React.memo(
+ ({ item }: { item: SettingSection }) => {
+ const colors = useThemeStore(state => state.colors);
+ const settings = useSettingStore(state => state.settings);
+ const navigation = useNavigation<NavigationProp<RouteParams>>();
+ const current = item.useHook && item.useHook(item);
+ const isHidden = item.hidden && item.hidden(item.property || current);
+ const onChangeSettings = () => {
+ if (item.modifer) {
+ item.modifer(item.property || current);
+ return;
+ }
+ if (!item.property) return;
+ SettingsService.set({
+ [item.property]: !settings[item.property]
+ });
+ };
- const onChangeSettings = () => {
- if (item.modifer) {
- item.modifer(item.property || current);
- return;
- }
- if (!item.property) return;
- SettingsService.set({
- [item.property]: !settings[item.property]
- });
- };
+ const styles =
+ item.type === 'danger'
+ ? {
+ backgroundColor: colors.errorBg
+ }
+ : {};
- const styles =
- item.type === 'danger'
- ? {
- backgroundColor: colors.errorBg
- }
- : {};
-
- return isHidden ? null : (
- <PressableButton
- disabled={item.type === 'component'}
- customStyle={{
- width: '100%',
- alignItems: 'center',
- padding: 12,
- flexDirection: 'row',
- justifyContent: 'space-between',
- paddingVertical: 20,
- ...styles
- }}
- onPress={() => {
- switch (item.type) {
- case 'screen':
- navigation.dispatch(StackActions.push('SettingsGroup', item));
- break;
- case 'switch':
- onChangeSettings();
- break;
- default:
- item.modifer && item.modifer(current);
- break;
- }
- }}
- >
- <View
- style={{
+ return isHidden ? null : (
+ <PressableButton
+ disabled={item.type === 'component'}
+ customStyle={{
+ width: '100%',
+ alignItems: 'center',
+ padding: 12,
flexDirection: 'row',
- flexShrink: 1
+ justifyContent: 'space-between',
+ paddingVertical: 20,
+ ...styles
+ }}
+ onPress={() => {
+ switch (item.type) {
+ case 'screen':
+ navigation.dispatch(StackActions.push('SettingsGroup', item));
+ break;
+ case 'switch':
+ onChangeSettings();
+ break;
+ default:
+ item.modifer && item.modifer(current);
+ break;
+ }
}}
>
<View
style={{
- width: 40,
- height: 40,
- justifyContent: 'center',
- alignItems: 'center',
- marginRight: 12,
- backgroundColor: item.component === 'colorpicker' ? colors.accent : undefined,
- borderRadius: 100
+ flexDirection: 'row',
+ flexShrink: 1
}}
>
- {!!item.icon && (
- <Icon
- color={item.type === 'danger' ? colors.errorText : colors.icon}
- name={item.icon}
- size={30}
- />
- )}
- </View>
+ <View
+ style={{
+ width: 40,
+ height: 40,
+ justifyContent: 'center',
+ alignItems: 'center',
+ marginRight: 12,
+ backgroundColor: item.component === 'colorpicker' ? colors.accent : undefined,
+ borderRadius: 100
+ }}
+ >
+ {!!item.icon && (
+ <Icon
+ color={item.type === 'danger' ? colors.errorText : colors.icon}
+ name={item.icon}
+ size={30}
+ />
+ )}
+ </View>
- <View
- style={{
- flexShrink: 1,
- paddingRight: item.type === 'switch' ? 10 : 0
- }}
- >
- <Paragraph
- color={item.type === 'danger' ? colors.errorText : colors.heading}
- size={SIZE.md + 1}
+ <View
+ style={{
+ flexShrink: 1,
+ paddingRight: item.type === 'switch' ? 10 : 0
+ }}
>
- {typeof item.name === 'function' ? item.name(current) : item.name}
- </Paragraph>
- {!!item.description && (
<Paragraph
- color={item.type === 'danger' ? colors.errorText : colors.pri}
- size={SIZE.sm}
+ color={item.type === 'danger' ? colors.errorText : colors.heading}
+ size={SIZE.md + 1}
>
- {typeof item.description === 'function'
- ? item.description(current)
- : item.description}
+ {typeof item.name === 'function' ? item.name(current) : item.name}
</Paragraph>
- )}
+ {!!item.description && (
+ <Paragraph
+ color={item.type === 'danger' ? colors.errorText : colors.pri}
+ size={SIZE.sm}
+ >
+ {typeof item.description === 'function'
+ ? item.description(current)
+ : item.description}
+ </Paragraph>
+ )}
- {!!item.component && (
- <>
- <Seperator half />
- {components[item.component]}
- </>
- )}
+ {!!item.component && (
+ <>
+ <Seperator half />
+ {components[item.component]}
+ </>
+ )}
+ </View>
</View>
- </View>
- {item.type === 'switch' && item.property && (
- <ToggleSwitch
- isOn={item.getter ? item.getter(item.property || current) : settings[item.property]}
- onColor={colors.accent}
- offColor={colors.icon}
- size="small"
- animationSpeed={150}
- onToggle={onChangeSettings}
- />
- )}
- </PressableButton>
- );
-};
+ {item.type === 'switch' && item.property && (
+ <ToggleSwitch
+ isOn={item.getter ? item.getter(item.property || current) : settings[item.property]}
+ onColor={colors.accent}
+ offColor={colors.icon}
+ size="small"
+ animationSpeed={150}
+ onToggle={onChangeSettings}
+ />
+ )}
+ </PressableButton>
+ );
+ },
+ () => true
+);
diff --git a/apps/mobile/src/screens/settings/settingsdata.tsx b/apps/mobile/src/screens/settings/settingsdata.tsx
new file mode 100644
index 000000000..5d879141d
--- /dev/null
+++ b/apps/mobile/src/screens/settings/settingsdata.tsx
@@ -0,0 +1,800 @@
+import dayjs from 'dayjs';
+import React from 'react';
+import { Linking, Platform } from 'react-native';
+import { checkVersion } from 'react-native-check-version';
+import * as RNIap from 'react-native-iap';
+import { enabled } from 'react-native-privacy-snapshot';
+import { APP_VERSION } from '../../../version';
+import { ChangePassword } from '../../components/auth/change-password';
+import { presentDialog } from '../../components/dialog/functions';
+import { Issue } from '../../components/sheets/github/issue';
+import { Progress } from '../../components/sheets/progress';
+import { Update } from '../../components/sheets/update';
+import BackupService from '../../services/backup';
+import BiometicService from '../../services/biometrics';
+import { eSendEvent, openVault, presentSheet, ToastEvent } from '../../services/event-manager';
+import { setLoginMessage } from '../../services/message';
+import Navigation from '../../services/navigation';
+import Notifications from '../../services/notifications';
+import PremiumService from '../../services/premium';
+import SettingsService from '../../services/settings';
+import Sync from '../../services/sync';
+import { clearAllStores } from '../../stores';
+import { useUserStore } from '../../stores/use-user-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { AndroidModule } from '../../utils';
+import { toggleDarkMode } from '../../utils/color-scheme/utils';
+import { SUBSCRIPTION_STATUS } from '../../utils/constants';
+import { db } from '../../utils/database';
+import { MMKV } from '../../utils/database/mmkv';
+import {
+ eCloseProgressDialog,
+ eCloseSimpleDialog,
+ eOpenAttachmentsDialog,
+ eOpenLoginDialog,
+ eOpenRecoveryKeyDialog,
+ eOpenRestoreDialog
+} from '../../utils/events';
+import { useVaultStatus } from '../../utils/hooks/use-vault-status';
+import { sleep } from '../../utils/time';
+import { MFARecoveryCodes, MFASheet } from './2fa';
+import AppLock from './app-lock';
+import { verifyUser } from './functions';
+import { SettingSection } from './types';
+import { getTimeLeft } from './user-section';
+const format = (ver: number) => {
+ let parts = ver.toString().split('');
+ return `v${parts[0]}.${parts[1]}.${parts[2]?.startsWith('0') ? '' : parts[2]}${
+ !parts[3] ? '' : parts[3]
+ } `;
+};
+
+export const settingsGroups: SettingSection[] = [
+ {
+ name: 'account',
+ useHook: () => useUserStore(state => state.user),
+ hidden: current => !current,
+ sections: [
+ {
+ useHook: () => useUserStore(state => state.user),
+ hidden: current => !current,
+ name: current => {
+ const user = current;
+ const isBasic = user.subscription?.type === SUBSCRIPTION_STATUS.BASIC;
+ const isTrial = user.subscription?.type === SUBSCRIPTION_STATUS.TRIAL;
+ return isBasic
+ ? 'Subscribe to Pro'
+ : isTrial
+ ? 'Your free trial has started'
+ : 'Subscription details';
+ },
+ type: 'component',
+ component: 'subscription',
+ icon: 'crown',
+ description: current => {
+ const user = current;
+ const subscriptionDaysLeft = user && getTimeLeft(parseInt(user.subscription?.expiry));
+ const expiryDate = dayjs(user?.subscription?.expiry).format('MMMM D, YYYY');
+ const startDate = dayjs(user?.subscription?.start).format('MMMM D, YYYY');
+
+ return user.subscription?.type === 2
+ ? 'You signed up on ' + startDate
+ : user.subscription?.type === 1
+ ? 'Your free trial will end on ' + expiryDate
+ : user.subscription?.type === 6
+ ? subscriptionDaysLeft.time < -3
+ ? 'Your subscription has ended'
+ : 'Your account will be downgraded to Basic in 3 days'
+ : user.subscription?.type === 7
+ ? `Your subscription will end on ${expiryDate}.`
+ : user.subscription?.type === 5
+ ? `Your subscription will renew on ${expiryDate}.`
+ : 'Never hesitate to choose privacy';
+ }
+ },
+ {
+ type: 'screen',
+ name: 'Account Settings',
+ icon: 'account-cog',
+ description: 'Manage account',
+ sections: [
+ {
+ name: 'Save data recovery key',
+ modifer: async () => {
+ verifyUser(null, async () => {
+ await sleep(300);
+ eSendEvent(eOpenRecoveryKeyDialog);
+ });
+ },
+ description: 'Recover your data using the recovery key if your password is lost.'
+ },
+ {
+ name: 'Manage attachments',
+ icon: 'attachment',
+ modifer: () => {
+ eSendEvent(eOpenAttachmentsDialog);
+ },
+ description: 'Manage all attachments in one place.'
+ },
+ {
+ name: 'Change password',
+ modifer: async () => {
+ ChangePassword.present();
+ },
+ description: 'Setup a new password for your account.'
+ },
+ {
+ type: 'screen',
+ name: 'Two factor authentication',
+ description: 'Manage 2FA settings',
+ icon: 'two-factor-authentication',
+ sections: [
+ {
+ name: 'Enable two-factor authentication',
+ modifer: () => {
+ verifyUser('global', async () => {
+ MFASheet.present();
+ });
+ },
+ useHook: () => useUserStore(state => state.user),
+ hidden: user => {
+ return !!user?.mfa?.isEnabled;
+ },
+ description: 'Increased security for your account'
+ },
+ {
+ name: 'Add fallback 2FA method',
+ useHook: () => useUserStore(state => state.user),
+ hidden: user => {
+ return !!user?.mfa?.secondaryMethod || !user?.mfa?.isEnabled;
+ },
+ modifer: () => {
+ verifyUser('global', async () => {
+ MFASheet.present(true);
+ });
+ },
+ description:
+ 'You can use fallback 2FA method incase you are unable to login via primary method'
+ },
+ {
+ name: 'Reconfigure fallback 2FA method',
+ useHook: () => useUserStore(state => state.user),
+ hidden: user => {
+ return !user?.mfa?.secondaryMethod || !user?.mfa?.isEnabled;
+ },
+ modifer: () => {
+ verifyUser('global', async () => {
+ MFASheet.present(true);
+ });
+ },
+ description:
+ 'You can use fallback 2FA method incase you are unable to login via primary method'
+ },
+ {
+ name: 'View recovery codes',
+ modifer: () => {
+ verifyUser('global', async () => {
+ MFARecoveryCodes.present('sms');
+ });
+ },
+ useHook: () => useUserStore(state => state.user),
+ hidden: user => {
+ return !user?.mfa?.isEnabled;
+ },
+ description: 'View and save recovery codes for to recover your account'
+ },
+ {
+ name: 'Disable two-factor authentication',
+ modifer: () => {
+ verifyUser('global', async () => {
+ await db.mfa?.disable();
+ let user = await db.user?.fetchUser();
+ useUserStore.getState().setUser(user);
+ });
+ },
+
+ useHook: () => useUserStore(state => state.user),
+ hidden: user => {
+ return !user?.mfa?.isEnabled;
+ },
+ description: 'Decreased security for your account'
+ }
+ ]
+ },
+ {
+ name: 'Subscription not activated?',
+ hidden: () => Platform.OS !== 'ios',
+ modifer: async () => {
+ if (Platform.OS === 'android') return;
+ presentSheet({
+ title: 'Loading subscriptions',
+ paragraph: `Please wait while we fetch your subscriptions.`
+ });
+ let subscriptions = await RNIap.getPurchaseHistory();
+ subscriptions.sort((a, b) => b.transactionDate - a.transactionDate);
+ let currentSubscription = subscriptions[0];
+ presentSheet({
+ title: 'Notesnook Pro',
+ paragraph: `You subscribed to Notesnook Pro on ${new Date(
+ currentSubscription.transactionDate
+ ).toLocaleString()}. Verify this subscription?`,
+ action: async () => {
+ presentSheet({
+ title: 'Verifying subscription',
+ paragraph: `Please wait while we verify your subscription.`
+ });
+ await PremiumService.subscriptions.verify(currentSubscription);
+ eSendEvent(eCloseProgressDialog);
+ },
+ icon: 'information-outline',
+ actionText: 'Verify'
+ });
+ },
+ description: 'Verify your subscription to Notesnook Pro'
+ },
+ {
+ name: 'Log out',
+ description: 'Clear all your data and reset the app.',
+ icon: 'logout',
+ modifer: () => {
+ presentDialog({
+ title: 'Logout',
+ paragraph: 'Clear all your data and reset the app.',
+ positiveText: 'Logout',
+ positivePress: async () => {
+ try {
+ eSendEvent('settings-loading', true);
+ setImmediate(async () => {
+ eSendEvent(eCloseSimpleDialog);
+ db.user?.logout();
+ setLoginMessage();
+ await PremiumService.setPremiumStatus();
+ await BiometicService.resetCredentials();
+ MMKV.clearStore();
+ await db.init();
+ await clearAllStores();
+ SettingsService.init();
+ SettingsService.set({
+ introCompleted: true
+ });
+ useUserStore.getState().setUser(null);
+ useUserStore.getState().setSyncing(false);
+ console.log('HIDING');
+ Navigation.goBack();
+ Navigation.goBack();
+ eSendEvent('settings-loading', false);
+ });
+ } catch (e) {
+ ToastEvent.error(e as Error, 'Error logging out');
+ eSendEvent('settings-loading', false);
+ }
+ }
+ });
+ }
+ },
+ {
+ type: 'danger',
+ name: 'Delete account',
+ icon: 'alert',
+ description: `All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.`,
+ modifer: () => {
+ presentDialog({
+ title: 'Delete account',
+ paragraphColor: 'red',
+ paragraph:
+ 'All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.',
+ positiveType: 'errorShade',
+ input: true,
+ inputPlaceholder: 'Enter account password',
+ positiveText: 'Delete',
+ positivePress: async value => {
+ try {
+ let verified = await db.user?.verifyPassword(value);
+ if (verified) {
+ eSendEvent('settings-loading', true);
+ await db.user?.deleteUser(value);
+ await BiometicService.resetCredentials();
+ SettingsService.set({
+ introCompleted: true
+ });
+ } else {
+ ToastEvent.show({
+ heading: 'Incorrect password',
+ message: 'The account password you entered is incorrect',
+ type: 'error',
+ context: 'global'
+ });
+ }
+
+ eSendEvent('settings-loading', false);
+ } catch (e) {
+ eSendEvent('settings-loading', false);
+ console.log(e);
+ ToastEvent.error(e as Error, 'Failed to delete account', 'global');
+ }
+ }
+ });
+ }
+ }
+ ]
+ },
+ {
+ name: 'Having problems with sync',
+ description: 'Try force sync to resolve issues with syncing',
+ icon: 'sync-alert',
+ modifer: async () => {
+ Progress.present();
+ await Sync.run('global', true);
+ eSendEvent(eCloseProgressDialog);
+ }
+ }
+ ]
+ },
+ {
+ name: 'Customize',
+ sections: [
+ {
+ type: 'screen',
+ name: 'Theme',
+ description: 'Change app look and feel',
+ icon: 'shape',
+ sections: [
+ {
+ type: 'component',
+ name: 'Accent color',
+ description: 'Pick the color that matches your mood',
+ component: 'colorpicker'
+ },
+ {
+ type: 'switch',
+ name: 'Use system theme',
+ description: 'Automatically switch to dark mode when system theme changes',
+ property: 'useSystemTheme',
+ icon: 'circle-half'
+ },
+ {
+ type: 'switch',
+ name: 'Dark mode',
+ description: 'Strain your eyes no more at night',
+ property: 'theme',
+ icon: 'brightness-6',
+ modifer: () => {
+ toggleDarkMode();
+ },
+ getter: () => useSettingStore.getState().settings.theme.dark
+ },
+ {
+ type: 'switch',
+ name: 'Pitch black',
+ description: 'Save battery on device with amoled screen at night.',
+ property: 'pitchBlack',
+ icon: 'brightness-1'
+ }
+ ]
+ },
+ {
+ type: 'screen',
+ name: 'Behaviour',
+ description: 'Change app homepage',
+ sections: [
+ {
+ type: 'component',
+ name: 'Homepage',
+ description: 'Default screen to open on app startup',
+ component: 'homeselector'
+ }
+ ]
+ }
+ ]
+ },
+ {
+ name: 'Privacy and security',
+ sections: [
+ {
+ type: 'switch',
+ name: 'Telemetry',
+ icon: 'radar',
+ description:
+ 'Contribute towards a better Notesnook. All tracking information is anonymous.',
+ property: 'telemetry'
+ },
+ {
+ type: 'screen',
+ name: 'Vault',
+ description: 'Multi-layer encryption to most important notes',
+ icon: 'key',
+ sections: [
+ {
+ name: 'Create vault',
+ description: 'Set a password to create vault and lock notes.',
+ icon: 'key',
+ useHook: useVaultStatus,
+ hidden: current => current?.exists,
+ modifer: () => {
+ PremiumService.verify(() => {
+ openVault({
+ item: {},
+ novault: false,
+ title: 'Create vault',
+ description: 'Set a password to create vault and lock notes.'
+ });
+ });
+ }
+ },
+ {
+ useHook: useVaultStatus,
+ name: 'Change vault password',
+ description: 'Setup a new password for your vault.',
+ hidden: current => !current?.exists,
+ modifer: () =>
+ openVault({
+ item: {},
+ changePassword: true,
+ novault: true,
+ title: 'Change vault password',
+ description: 'Set a new password for your vault.'
+ })
+ },
+ {
+ useHook: useVaultStatus,
+ name: 'Clear vault',
+ description: 'Unlock all locked notes',
+ hidden: current => !current?.exists,
+ modifer: () => {
+ openVault({
+ item: {},
+ clearVault: true,
+ novault: true,
+ title: 'Clear vault',
+ description: 'Enter vault password to unlock and remove all notes from the vault.'
+ });
+ }
+ },
+ {
+ name: 'Delete vault',
+ description: 'Delete vault (and optionally remove all notes).',
+ useHook: useVaultStatus,
+ hidden: current => !current?.exists,
+ modifer: () => {
+ openVault({
+ item: {},
+ deleteVault: true,
+ novault: true,
+ title: 'Delete vault',
+ description: 'Enter your account password to delete your vault.'
+ });
+ }
+ },
+ {
+ type: 'switch',
+ name: 'Biometric unlocking',
+ icon: 'fingerprint',
+ useHook: useVaultStatus,
+ description: 'Access notes in vault using biometrics',
+ hidden: current => !current?.exists || !current?.isBiometryAvailable,
+ getter: current => current?.biometryEnrolled,
+ modifer: current => {
+ openVault({
+ item: {},
+ fingerprintAccess: !current.biometryEnrolled,
+ revokeFingerprintAccess: current.biometryEnrolled,
+ novault: true,
+ title: current.biometryEnrolled
+ ? 'Revoke biometric unlocking'
+ : 'Enable biometery unlock',
+ description: current.biometryEnrolled
+ ? 'Disable biometric unlocking for notes in vault'
+ : 'Enable biometric unlocking for notes in vault'
+ });
+ }
+ }
+ ]
+ },
+ {
+ type: 'switch',
+ icon: 'eye-off-outline',
+ name: 'Privacy mode',
+ description: `Hide app contents when you switch to other apps. This will also disable screenshot taking in the app.`,
+ modifer: () => {
+ const settings = SettingsService.get();
+ Platform.OS === 'android'
+ ? AndroidModule.setSecureMode(!settings.privacyScreen)
+ : enabled(true);
+
+ SettingsService.set({ privacyScreen: !settings.privacyScreen });
+ },
+ property: 'privacyScreen'
+ },
+ {
+ name: 'App lock',
+ description: 'Change app lock mode to suit your needs',
+ icon: 'fingerprint',
+ modifer: () => {
+ AppLock.present();
+ }
+ }
+ ]
+ },
+ {
+ name: 'Backup and restore',
+ sections: [
+ {
+ type: 'screen',
+ name: 'Backups',
+ icon: 'backup-restore',
+ description: 'Create a backup or change backup settings',
+ sections: [
+ {
+ name: 'Backup now',
+ description: 'Create a backup of your data',
+ modifer: async () => {
+ const user = useUserStore.getState().user;
+ if (!user) {
+ await BackupService.run(true);
+ return;
+ }
+ verifyUser(null, () => BackupService.run(true));
+ }
+ },
+ {
+ type: 'component',
+ name: 'Automatic backups',
+ description: 'Backup your data once every week or daily automatically.',
+ component: 'autobackups'
+ },
+ {
+ name: 'Select backup directory',
+ description: 'Select directory to store backups',
+ icon: 'folder',
+ hidden: () =>
+ !!SettingsService.get().backupDirectoryAndroid || Platform.OS !== 'android',
+ property: 'backupDirectoryAndroid',
+ modifer: async () => {
+ let dir;
+ try {
+ dir = await BackupService.checkBackupDirExists(true);
+ } catch (e) {
+ } finally {
+ if (!dir) {
+ ToastEvent.show({
+ heading: 'No directory selected',
+ type: 'error'
+ });
+ }
+ }
+ }
+ },
+ {
+ name: 'Change backup directory',
+ description: () => SettingsService.get().backupDirectoryAndroid?.name || '',
+ icon: 'folder',
+ hidden: () =>
+ !SettingsService.get().backupDirectoryAndroid || Platform.OS !== 'android',
+ property: 'backupDirectoryAndroid',
+ modifer: async () => {
+ let dir;
+ try {
+ dir = await BackupService.checkBackupDirExists(true);
+ } catch (e) {
+ } finally {
+ if (!dir) {
+ ToastEvent.show({
+ heading: 'No directory selected',
+ type: 'error'
+ });
+ }
+ }
+ }
+ },
+ {
+ type: 'switch',
+ name: 'Backup encryption',
+ description: 'Encrypt all your backups.',
+ icon: 'lock',
+ property: 'encryptedBackup',
+ modifer: async () => {
+ const user = useUserStore.getState().user;
+ const settings = SettingsService.get();
+ if (!user) {
+ ToastEvent.show({
+ heading: 'Login required to enable encryption',
+ type: 'error',
+ func: () => {
+ eSendEvent(eOpenLoginDialog);
+ },
+ actionText: 'Login'
+ });
+ return;
+ }
+ SettingsService.set({ encryptedBackup: !settings.encryptedBackup });
+ }
+ }
+ ]
+ },
+ {
+ name: 'Restore backup',
+ description: `Restore backup from phone storage.`,
+ modifer: () => {
+ const user = useUserStore.getState().user;
+ if (!user || !user?.email) {
+ ToastEvent.show({
+ heading: 'Login required',
+ message: 'Please log in to your account to restore backup',
+ type: 'error',
+ context: 'global'
+ });
+ return;
+ }
+ eSendEvent(eOpenRestoreDialog);
+ }
+ }
+ ]
+ },
+ {
+ name: 'Productivity',
+ hidden: () => Platform.OS !== 'android',
+ sections: [
+ {
+ type: 'switch',
+ name: 'Notes in notifications',
+ description: `Add quick notes from notifications without opening the app.`,
+ property: 'notifNotes',
+ icon: 'form-textbox',
+ modifer: () => {
+ const settings = SettingsService.get();
+ if (settings.notifNotes) {
+ Notifications.unpinQuickNote();
+ } else {
+ Notifications.pinQuickNote(false);
+ }
+ SettingsService.toggle('notifNotes');
+ }
+ }
+ ]
+ },
+ {
+ name: 'Help and support',
+ sections: [
+ {
+ name: 'Report an issue',
+ icon: 'bug',
+ modifer: () => {
+ presentSheet({
+ component: <Issue />
+ });
+ },
+ description: 'Faced an issue or have a suggestion? Click here to create a bug report'
+ },
+ {
+ name: 'Documentation',
+ modifer: async () => {
+ Linking.openURL('https://docs.notesnook.com');
+ },
+ description: 'Learn about every feature and how it works.',
+ icon: 'file-document'
+ },
+ {
+ type: 'switch',
+ name: 'Debug mode',
+ description: 'Show debug options on items',
+ property: 'devMode'
+ }
+ ]
+ },
+ {
+ name: 'community',
+ sections: [
+ {
+ name: 'Join our Telegram group',
+ description: "We are on telegram, let's talk",
+ icon: 'telegram',
+ modifer: () => {
+ Linking.openURL('https://t.me/notesnook').catch(console.log);
+ }
+ },
+ {
+ name: 'Join our Discord community',
+ icon: 'discord',
+ modifer: async () => {
+ presentSheet({
+ title: 'Join our Discord Community',
+ iconColor: 'discord',
+ paragraph: 'We are not ghosts, chat with us and share your experience.',
+ valueArray: [
+ 'Talk with us anytime.',
+ 'Follow the development process',
+ 'Give suggestions and report issues.',
+ 'Get early access to new features',
+ 'Meet other people using Notesnook'
+ ],
+ icon: 'discord',
+ action: async () => {
+ try {
+ Linking.openURL('https://discord.gg/zQBK97EE22').catch(console.log);
+ } catch (e) {}
+ },
+ actionText: 'Join Now'
+ });
+ },
+ description: 'We are not ghosts, chat with us and share your experience.'
+ }
+ ]
+ },
+ {
+ name: 'legal',
+ sections: [
+ {
+ name: 'Terms of service',
+ modifer: async () => {
+ try {
+ await Linking.openURL('https://notesnook.com/tos');
+ } catch (e) {}
+ },
+ description: 'Read our terms of service'
+ },
+ {
+ name: 'Privacy policy',
+ modifer: async () => {
+ try {
+ await Linking.openURL('https://notesnook.com/privacy');
+ } catch (e) {}
+ },
+ description: 'Read our privacy policy'
+ }
+ ]
+ },
+ {
+ name: 'about',
+ sections: [
+ {
+ name: 'Download on desktop',
+ icon: 'monitor',
+ modifer: async () => {
+ try {
+ await Linking.openURL('https://notesnook.com');
+ } catch (e) {}
+ },
+ description: 'Get Notesnook app on your desktop and access all notes'
+ },
+ {
+ name: 'Roadmap',
+ icon: 'chart-timeline',
+ modifer: async () => {
+ try {
+ await Linking.openURL('https://notesnook.com/roadmap/');
+ } catch (e) {}
+ },
+ description: 'See what the future of Notesnook is going to be like.'
+ },
+ {
+ name: 'Check for updates',
+ icon: 'cellphone-arrow-down',
+ description: 'Check for new version of Notesnook',
+ modifer: async () => {
+ const version = await checkVersion();
+ if (!version.needsUpdate) {
+ ToastEvent.show({
+ heading: 'You are on latest version',
+ type: 'success',
+ context: 'global'
+ });
+ return false;
+ }
+ presentSheet({
+ component: ref => <Update version={version} fwdRef={ref} />
+ });
+ }
+ },
+ {
+ name: 'App version',
+ icon: 'alpha-v',
+ modifer: async () => {
+ try {
+ await Linking.openURL('https://notesnook.com');
+ } catch (e) {}
+ },
+ description: format(APP_VERSION)
+ }
+ ]
+ }
+];
diff --git a/apps/mobile/src/screens/settings/subscription.js b/apps/mobile/src/screens/settings/subscription.js
index 5ba872b2a..f14ed1192 100644
--- a/apps/mobile/src/screens/settings/subscription.js
+++ b/apps/mobile/src/screens/settings/subscription.js
@@ -3,7 +3,7 @@ import { Linking, Platform, View } from 'react-native';
import { Button } from '../../components/ui/button';
import { eSendEvent, presentSheet, ToastEvent } from '../../services/event-manager';
import PremiumService from '../../services/premium';
-import { useUserStore } from '../../stores/stores';
+import { useUserStore } from '../../stores/use-user-store';
import { SUBSCRIPTION_PROVIDER, SUBSCRIPTION_STATUS } from '../../utils/constants';
import { eOpenPremiumDialog } from '../../utils/events';
import { usePricing } from '../../utils/hooks/use-pricing';
@@ -13,8 +13,8 @@ export const Subscription = () => {
const user = useUserStore(state => state.user);
const monthlyPlan = usePricing('monthly');
const isNotPro =
- user.subscription?.type !== SUBSCRIPTION_STATUS.PREMIUM &&
- user.subscription?.type !== SUBSCRIPTION_STATUS.BETA;
+ user?.subscription?.type !== SUBSCRIPTION_STATUS.PREMIUM &&
+ user?.subscription?.type !== SUBSCRIPTION_STATUS.BETA;
const subscriptionProviderInfo = SUBSCRIPTION_PROVIDER[user?.subscription?.provider];
@@ -24,7 +24,7 @@ export const Subscription = () => {
return;
}
if (
- user.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED &&
+ user?.subscription?.type === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED &&
Platform.OS === 'android'
) {
if (user.subscription?.provider === 3) {
diff --git a/apps/mobile/src/screens/settings/types.ts b/apps/mobile/src/screens/settings/types.ts
index e1d503a2d..dda2da80b 100644
--- a/apps/mobile/src/screens/settings/types.ts
+++ b/apps/mobile/src/screens/settings/types.ts
@@ -20,6 +20,6 @@ export type SettingsGroup = {
};
export type RouteParams = {
- SettingsHome: undefined;
+ SettingsHome: { [name: string]: string };
SettingsGroup: SettingSection;
};
diff --git a/apps/mobile/src/screens/settings/usersection.js b/apps/mobile/src/screens/settings/usersection.js
index 04e16fbec..365321497 100644
--- a/apps/mobile/src/screens/settings/usersection.js
+++ b/apps/mobile/src/screens/settings/usersection.js
@@ -5,8 +5,8 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { TimeSince } from '../../components/ui/time-since';
import Heading from '../../components/ui/typography/heading';
import Paragraph from '../../components/ui/typography/paragraph';
-import { useUserStore } from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useUserStore } from '../../stores/use-user-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { SUBSCRIPTION_STATUS_STRINGS } from '../../utils/constants';
import { SIZE } from '../../utils/size';
import { SectionItem } from './section-item';
@@ -90,7 +90,7 @@ const SettingsUserSection = ({ item }) => {
justifyContent: 'center'
}}
>
- <Icon size={SIZE.xl} color={colors.accent} name="camera-outline" />
+ <Icon size={SIZE.xl} color={colors.accent} name="account-outline" />
</View>
</View>
diff --git a/apps/mobile/src/screens/tags/index.js b/apps/mobile/src/screens/tags/index.js
deleted file mode 100644
index 03cf9a41b..000000000
--- a/apps/mobile/src/screens/tags/index.js
+++ /dev/null
@@ -1,94 +0,0 @@
-import React, { useCallback, useEffect } from 'react';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { Header } from '../../components/header';
-import List from '../../components/list';
-import SelectionHeader from '../../components/selection-header';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { useTagStore } from '../../stores/stores';
-import { InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-
-export const Tags = ({ navigation }) => {
- const tags = useTagStore(state => state.tags);
- const setTags = useTagStore(state => state.setTags);
- let ranAfterInteractions = false;
-
- const runAfterInteractions = () => {
- InteractionManager.runAfterInteractions(() => {
- Navigation.routeNeedsUpdate('Tags', () => {
- setTags();
- });
- });
- updateSearch();
- ranAfterInteractions = false;
- };
-
- const onFocus = useCallback(() => {
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
- Navigation.setHeaderState(
- 'Tags',
- {
- menu: true
- },
- {
- heading: 'Tags',
- id: 'tags_navigation'
- }
- );
- }, []);
-
- useEffect(() => {
- navigation.addListener('focus', onFocus);
- return () => {
- ranAfterInteractions = false;
- navigation.removeListener('focus', onFocus);
- };
- }, []);
-
- useEffect(() => {
- if (navigation.isFocused()) {
- updateSearch();
- }
- }, [tags]);
-
- const updateSearch = () => {
- SearchService.update({
- placeholder: 'Search in tags',
- data: tags,
- type: 'tags',
- title: 'Tags',
- get: () => db.tags.all
- });
- };
-
- return (
- <>
- <SelectionHeader screen="Tags" />
- <ContainerHeader>
- <Header title="Tags" isBack={false} screen="Tags" />
- </ContainerHeader>
- <List
- listData={tags}
- type="tags"
- headerProps={{
- heading: 'Tags'
- }}
- screen="Tags"
- focused={() => navigation.isFocused()}
- placeholderData={{
- heading: 'Your tags',
- paragraph: 'You have not created any tags for your notes yet.',
- button: null,
- loading: 'Loading your tags.'
- }}
- placeholderText="Tags added to notes appear here"
- />
- </>
- );
-};
-
-export default Tags;
diff --git a/apps/mobile/src/screens/tags/index.tsx b/apps/mobile/src/screens/tags/index.tsx
new file mode 100644
index 000000000..eb93fe039
--- /dev/null
+++ b/apps/mobile/src/screens/tags/index.tsx
@@ -0,0 +1,59 @@
+import React from 'react';
+import List from '../../components/list';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import SearchService from '../../services/search';
+import SettingsService from '../../services/settings';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useTagStore } from '../../stores/use-tag-store';
+import { db } from '../../utils/database';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+
+const prepareSearch = () => {
+ SearchService.update({
+ placeholder: 'Search in tags',
+ type: 'tags',
+ title: 'Tags',
+ get: () => db.tags?.all
+ });
+};
+
+const PLACEHOLDER_DATA = {
+ heading: 'Your tags',
+ paragraph: 'You have not created any tags for your notes yet.',
+ button: null,
+ loading: 'Loading your tags.'
+};
+
+export const Tags = ({ navigation, route }: NavigationProps<'Tags'>) => {
+ const tags = useTagStore(state => state.tags);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: prev => {
+ Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+
+ SearchService.prepareSearch = prepareSearch;
+ return !prev?.current;
+ },
+ onBlur: () => false,
+ delay: SettingsService.get().homepage === route.name ? 1 : -1
+ });
+
+ return (
+ <>
+ <List
+ listData={tags}
+ type="tags"
+ headerProps={{
+ heading: 'Tags'
+ }}
+ loading={!isFocused}
+ screen="Tags"
+ placeholderData={PLACEHOLDER_DATA}
+ />
+ </>
+ );
+};
+
+export default Tags;
diff --git a/apps/mobile/src/screens/trash/index.js b/apps/mobile/src/screens/trash/index.js
deleted file mode 100644
index c08c32a70..000000000
--- a/apps/mobile/src/screens/trash/index.js
+++ /dev/null
@@ -1,137 +0,0 @@
-import React, { useCallback, useEffect } from 'react';
-import { FloatingButton } from '../../components/container/floating-button';
-import { ContainerHeader } from '../../components/container/containerheader';
-import { presentDialog } from '../../components/dialog/functions';
-import { Header } from '../../components/header';
-import { Placeholder } from '../../components/ui/svg';
-import SelectionHeader from '../../components/selection-header';
-import List from '../../components/list';
-import { useSelectionStore, useTrashStore } from '../../stores/stores';
-import { ToastEvent } from '../../services/event-manager';
-import Navigation from '../../services/navigation';
-import SearchService from '../../services/search';
-import { InteractionManager } from '../../utils';
-import { db } from '../../utils/database';
-
-export const Trash = ({ navigation }) => {
- 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', () => {
- setTrash();
- });
- });
-
- console.log(trash);
- if (trash.length === 0) setTrash();
-
- updateSearch();
- ranAfterInteractions = false;
- };
-
- const onFocus = useCallback(() => {
- if (!pageIsLoaded) {
- pageIsLoaded = true;
- return;
- }
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
- Navigation.setHeaderState(
- 'Trash',
- {
- menu: true
- },
- {
- heading: 'Trash',
- id: 'trash_navigation'
- }
- );
- }, []);
-
- useEffect(() => {
- if (!ranAfterInteractions) {
- ranAfterInteractions = true;
- runAfterInteractions();
- }
- navigation.addListener('focus', onFocus);
- return () => {
- pageIsLoaded = false;
- ranAfterInteractions = false;
- navigation.removeListener('focus', onFocus);
- };
- }, []);
-
- useEffect(() => {
- if (navigation.isFocused()) {
- updateSearch();
- }
- }, [trash]);
-
- const updateSearch = () => {
- SearchService.update({
- placeholder: 'Search in trash',
- data: trash,
- type: 'trash',
- title: 'Trash',
- get: () => db.trash.all
- });
- };
-
- const _onPressBottomButton = () => {
- presentDialog({
- title: 'Clear trash',
- paragraph: 'Are you sure you want to clear the trash?',
- positiveText: 'Clear',
- negativeText: 'Cancel',
- positivePress: async () => {
- await db.trash.clear();
- useTrashStore.getState().setTrash();
- useSelectionStore.getState().clearSelection(true);
- ToastEvent.show({
- heading: 'Trash cleared',
- message: 'All notes and notebooks in the trash have been removed permanantly.',
- type: 'success',
- context: 'local'
- });
- },
- positiveType: 'errorShade'
- });
- };
-
- return (
- <>
- <SelectionHeader screen="Trash" />
- <ContainerHeader>
- <Header title="Trash" isBack={false} screen="Trash" action={_onPressBottomButton} />
- </ContainerHeader>
- <List
- listData={trash}
- type="trash"
- screen="Trash"
- focused={() => navigation.isFocused()}
- placeholderData={{
- heading: 'Trash',
- paragraph: 'Items in the trash will be permanently deleted after 7 days.',
- button: null,
- loading: 'Loading trash items'
- }}
- headerProps={{
- heading: 'Trash'
- }}
- placeholderText="Deleted notes & notebooks appear here."
- />
-
- {trash && trash.length !== 0 ? (
- <FloatingButton title="Clear all trash" onPress={_onPressBottomButton} shouldShow={true} />
- ) : null}
- </>
- );
-};
-
-export default Trash;
diff --git a/apps/mobile/src/screens/trash/index.tsx b/apps/mobile/src/screens/trash/index.tsx
new file mode 100644
index 000000000..be0965b19
--- /dev/null
+++ b/apps/mobile/src/screens/trash/index.tsx
@@ -0,0 +1,87 @@
+import React from 'react';
+import { FloatingButton } from '../../components/container/floating-button';
+import { presentDialog } from '../../components/dialog/functions';
+import List from '../../components/list';
+import { ToastEvent } from '../../services/event-manager';
+import Navigation, { NavigationProps } from '../../services/navigation';
+import SearchService from '../../services/search';
+import SettingsService from '../../services/settings';
+import useNavigationStore from '../../stores/use-navigation-store';
+import { useSelectionStore } from '../../stores/use-selection-store';
+import { useTrashStore } from '../../stores/use-trash-store';
+import { db } from '../../utils/database';
+import { useNavigationFocus } from '../../utils/hooks/use-navigation-focus';
+
+const prepareSearch = () => {
+ SearchService.update({
+ placeholder: 'Search in trash',
+ type: 'trash',
+ title: 'Trash',
+ get: () => db.trash?.all
+ });
+};
+
+const onPressFloatingButton = () => {
+ presentDialog({
+ title: 'Clear trash',
+ paragraph: 'Are you sure you want to clear the trash?',
+ positiveText: 'Clear',
+ negativeText: 'Cancel',
+ positivePress: async () => {
+ await db.trash?.clear();
+ useTrashStore.getState().setTrash();
+ useSelectionStore.getState().clearSelection(true);
+ ToastEvent.show({
+ heading: 'Trash cleared',
+ message: 'All notes and notebooks in the trash have been removed permanantly.',
+ type: 'success',
+ context: 'local'
+ });
+ },
+ positiveType: 'errorShade'
+ });
+};
+
+const PLACEHOLDER_DATA = {
+ heading: 'Trash',
+ paragraph: 'Items in the trash will be permanently deleted after 7 days.',
+ button: null,
+ loading: 'Loading trash items'
+};
+
+export const Trash = ({ navigation, route }: NavigationProps<'Trash'>) => {
+ const trash = useTrashStore(state => state.trash);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: prev => {
+ Navigation.routeNeedsUpdate(route.name, Navigation.routeUpdateFunctions[route.name]);
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+ SearchService.prepareSearch = prepareSearch;
+ return !prev?.current;
+ },
+ onBlur: () => false,
+ delay: SettingsService.get().homepage === route.name ? 1 : -1
+ });
+
+ return (
+ <>
+ <List
+ listData={trash}
+ type="trash"
+ screen="Trash"
+ loading={!isFocused}
+ placeholderData={PLACEHOLDER_DATA}
+ headerProps={{
+ heading: 'Trash'
+ }}
+ />
+
+ {trash && trash.length !== 0 ? (
+ <FloatingButton title="Clear all trash" onPress={onPressFloatingButton} shouldShow={true} />
+ ) : null}
+ </>
+ );
+};
+
+export default Trash;
diff --git a/apps/mobile/src/services/biometrics.ts b/apps/mobile/src/services/biometrics.ts
index acc467489..b4512172d 100644
--- a/apps/mobile/src/services/biometrics.ts
+++ b/apps/mobile/src/services/biometrics.ts
@@ -1,7 +1,7 @@
import { Platform } from 'react-native';
import FingerprintScanner from 'react-native-fingerprint-scanner';
import * as Keychain from 'react-native-keychain';
-import { useSettingStore } from '../stores/stores';
+import { useSettingStore } from '../stores/use-setting-store';
import { MMKV } from '../utils/database/mmkv';
import Storage from '../utils/database/storage';
import { ShowToastEvent, ToastEvent } from './event-manager';
diff --git a/apps/mobile/src/services/eventmanager.ts b/apps/mobile/src/services/eventmanager.ts
index 1a9c46086..a2a3fca5c 100644
--- a/apps/mobile/src/services/eventmanager.ts
+++ b/apps/mobile/src/services/eventmanager.ts
@@ -1,5 +1,7 @@
import Clipboard from '@react-native-clipboard/clipboard';
import EventManager from 'notes-core/utils/event-manager';
+import { RefObject } from 'react';
+import ActionSheet from 'react-native-actions-sheet';
import {
eHideToast,
eOnNoteEdited,
@@ -56,7 +58,33 @@ export function sendNoteEditedEvent(data: any) {
eSendEvent(eOnNoteEdited, data);
}
-export function presentSheet(data: any) {
+type SheetAction = {
+ action: () => void;
+ actionText: string;
+ iconColor?: string;
+ icon?: string;
+ type?: string;
+};
+
+export type PresentSheetOptions = {
+ context: string;
+ component: JSX.Element | ((ref: RefObject<ActionSheet>, close?: () => void) => JSX.Element);
+ disableClosing: boolean;
+ onClose: () => void;
+ progress: boolean;
+ icon: string;
+ title: string;
+ paragraph: string;
+ valueArray?: string[];
+ action: () => void;
+ actionText: string;
+ iconColor?: string;
+ actionsArray: SheetAction[];
+ learnMore: string;
+ learnMorePress: () => void;
+};
+
+export function presentSheet(data: Partial<PresentSheetOptions>) {
eSendEvent(eOpenProgressDialog, data);
}
diff --git a/apps/mobile/src/services/message.js b/apps/mobile/src/services/message.js
index f16bb011a..9158d2407 100644
--- a/apps/mobile/src/services/message.js
+++ b/apps/mobile/src/services/message.js
@@ -1,4 +1,4 @@
-import { useMessageStore } from '../stores/stores';
+import { useMessageStore } from '../stores/use-message-store';
import { eOpenLoginDialog, eOpenRateDialog, eOpenRecoveryKeyDialog } from '../utils/events';
import { eSendEvent } from './event-manager';
import PremiumService from './premium';
diff --git a/apps/mobile/src/services/navigation.js b/apps/mobile/src/services/navigation.js
deleted file mode 100755
index 8fa8bde29..000000000
--- a/apps/mobile/src/services/navigation.js
+++ /dev/null
@@ -1,188 +0,0 @@
-import { StackActions } from '@react-navigation/native';
-import {
- useFavoriteStore,
- useNotebookStore,
- useNoteStore,
- useTagStore,
- useTrashStore
-} from '../stores/stores';
-import { eOnNewTopicAdded, refreshNotesPage } from '../utils/events';
-import { rootNavigatorRef, tabBarRef } from '../utils/global-refs';
-import { eSendEvent } from './event-manager';
-import SettingsService from './settings';
-
-let currentScreen = 'Notes';
-let homeLoaded = false;
-
-function getHomeLoaded() {
- return homeLoaded;
-}
-
-function setHomeLoaded() {
- homeLoaded(true);
-}
-
-let headerState = {
- heading: 'Notes',
- color: null,
- verticalMenu: true,
- currentScreen: 'Notes'
-};
-
-const routeNames = {
- Notes: 'Notes',
- Notebooks: 'Notebooks',
- Notebook: 'Notebook',
- NotesPage: 'NotesPage',
- Tags: 'Tags',
- Favorites: 'Favorites',
- Trash: 'Trash'
-};
-
-let routesToUpdate = [];
-
-function getCurrentScreen() {
- return currentScreen;
-}
-
-function getHeaderState() {
- return headerState;
-}
-
-function clearRouteFromUpdates(routeName) {
- if (routesToUpdate.indexOf(routeName) !== -1) {
- routesToUpdate = [...new Set(routesToUpdate)];
- routesToUpdate.splice(routesToUpdate.indexOf(routeName), 1);
- }
-}
-
-function routeNeedsUpdate(routeName, callback) {
- if (routesToUpdate.indexOf(routeName) > -1) {
- clearRouteFromUpdates(routeName);
- callback();
- }
-}
-
-/**
- *
- * @param {array} routes
- */
-function setRoutesToUpdate(routes) {
- if (routes.indexOf(currentScreen) > -1) {
- if (currentScreen === routeNames.NotesPage || currentScreen === routeNames.Notebook) {
- eSendEvent(currentScreen === routeNames.NotesPage ? refreshNotesPage : eOnNewTopicAdded);
- } else {
- 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);
- }
-
- routesToUpdate = routesToUpdate.concat(routes);
- routesToUpdate = [...new Set(routesToUpdate)];
-}
-
-/**
- * @typedef {Object} screenParams
- * @property {string} heading
- * @property {string} id
- * @property {string} type
- *
- * @param {string} name
- * @param {Object} params
- * @param {screenParams} item
- */
-
-function navigate(name, params, item) {
- currentScreen = name;
- setHeaderState(name, params, item);
- rootNavigatorRef.current?.navigate(name, params);
-}
-
-/**
- * @typedef {Object} screenParams
- * @property {string} heading
- * @property {string} id
- * @property {string} type
- *
- * @param {string} name
- * @param {Object} params
- * @param {screenParams} item
- */
-function setHeaderState(name, params, item) {
- if (item) {
- headerState = item;
- }
- currentScreen = name;
- headerState.currentScreen = name;
- headerState.verticalMenu = params.menu;
- if (headerState) {
- eSendEvent('onHeaderStateChange', { id: headerState.id });
- }
-}
-
-function goBack() {
- rootNavigatorRef.current?.goBack();
-}
-
-function push(name, params, item) {
- setHeaderState(name, params, item);
- rootNavigatorRef.current?.dispatch(StackActions.push(name, params));
-}
-
-function replace(name, params, item) {
- setHeaderState(name, params, item);
- rootNavigatorRef.current?.dispatch(StackActions.replace(name, params));
-}
-
-function popToTop() {
- rootNavigatorRef.current?.dispatch(StackActions.popToTop());
- SettingsService.get().homepage;
- setHeaderState(
- SettingsService.get().homepage,
- {
- menu: true
- },
- {
- heading: SettingsService.get().homepage,
- id: SettingsService.get().homepage.toLocaleLowerCase() + '_navigation'
- }
- );
-}
-
-function openDrawer() {
- tabBarRef.current?.openDrawer();
-}
-function closeDrawer() {
- tabBarRef.current?.closeDrawer();
-}
-
-const Navigation = {
- navigate,
- goBack,
- push,
- openDrawer,
- closeDrawer,
- getCurrentScreen,
- setHeaderState,
- replace,
- popToTop,
- getHeaderState,
- setRoutesToUpdate,
- routeNeedsUpdate,
- routeNames,
- getHomeLoaded,
- setHomeLoaded
-};
-
-export default Navigation;
diff --git a/apps/mobile/src/services/navigation.ts b/apps/mobile/src/services/navigation.ts
new file mode 100755
index 000000000..67c02b9e5
--- /dev/null
+++ b/apps/mobile/src/services/navigation.ts
@@ -0,0 +1,176 @@
+import { BottomTabScreenProps } from '@react-navigation/bottom-tabs';
+import { StackActions } from '@react-navigation/native';
+import { useFavoriteStore } from '../stores/use-favorite-store';
+import useNavigationStore, { CurrentScreen, Route, RouteName } from '../stores/use-navigation-store';
+import { useNotebookStore } from '../stores/use-notebook-store';
+import { useNoteStore } from '../stores/use-notes-store';
+import { useTagStore } from '../stores/use-tag-store';
+import { useTrashStore } from '../stores/use-trash-store';
+import { eOnNewTopicAdded, refreshNotesPage } from '../utils/events';
+import { rootNavigatorRef, tabBarRef } from '../utils/global-refs';
+import { ColorType, NotebookType, TagType, TopicType } from '../utils/types';
+import { eSendEvent } from './event-manager';
+import SettingsService from './settings';
+
+/**
+ * Routes that should be updated on focus
+ */
+let routesUpdateQueue: Route[] = [];
+
+const routeNames = {
+ Notes: 'Notes',
+ Notebooks: 'Notebooks',
+ Notebook: 'Notebook',
+ NotesPage: 'NotesPage',
+ Tags: 'Tags',
+ Favorites: 'Favorites',
+ Trash: 'Trash',
+ Search: 'Search',
+ Settings: 'Settings',
+ TaggedNotes: 'TaggedNotes',
+ ColoredNotes: 'ColoredNotes',
+ TopicNotes: 'TopicNotes',
+ Monographs: 'Monographs'
+};
+
+type GenericRouteParam = { [name: string]: never };
+
+export type NotebookScreenParams = {
+ item: NotebookType;
+ title: string;
+ canGoBack: boolean;
+};
+
+export type NotesScreenParams = {
+ item: TopicType | TagType | ColorType;
+ title: string;
+ canGoBack: boolean;
+};
+
+export type RouteParams = {
+ Notes: GenericRouteParam;
+ Notebooks: GenericRouteParam;
+ Notebook: NotebookScreenParams;
+ NotesPage: NotesScreenParams;
+ Tags: GenericRouteParam;
+ Favorites: GenericRouteParam;
+ Trash: GenericRouteParam;
+ Search: GenericRouteParam;
+ Settings: GenericRouteParam;
+ TaggedNotes: NotesScreenParams;
+ ColoredNotes: NotesScreenParams;
+ TopicNotes: NotesScreenParams;
+ Monographs: NotesScreenParams;
+};
+
+export type NavigationProps<T extends RouteName> = BottomTabScreenProps<RouteParams, T>;
+
+/**
+ * Functions to update each route when required.
+ */
+const routeUpdateFunctions: { [name: string]: (...args: any[]) => void } = {
+ Notes: useNoteStore.getState().setNotes,
+ Notebooks: useNotebookStore.getState().setNotebooks,
+ Tags: useTagStore.getState().setTags,
+ Favorites: useFavoriteStore.getState().setFavorites,
+ Trash: useTrashStore.getState().setTrash,
+ Notebook: (params: NotebookScreenParams) => eSendEvent(eOnNewTopicAdded, params),
+ NotesPage: (params: NotesScreenParams) => eSendEvent(refreshNotesPage, params),
+ TaggedNotes: (params: NotesScreenParams) => eSendEvent('TaggedNotes', params),
+ ColoredNotes: (params: NotesScreenParams) => eSendEvent('ColoredNotes', params),
+ TopicNotes: (params: NotesScreenParams) => eSendEvent('TopicNotes', params),
+ Monographs: (params: NotesScreenParams) => eSendEvent('Monographs', params)
+};
+
+function clearRouteFromQueue(routeName: Route) {
+ if (routesUpdateQueue.indexOf(routeName) !== -1) {
+ routesUpdateQueue = [...new Set(routesUpdateQueue)];
+ routesUpdateQueue.splice(routesUpdateQueue.indexOf(routeName), 1);
+ }
+}
+
+/**
+ * Check if a route needs update
+ */
+function routeNeedsUpdate(routeName: Route, callback: () => void) {
+ if (routesUpdateQueue.indexOf(routeName) > -1) {
+ clearRouteFromQueue(routeName);
+ callback();
+ }
+}
+
+function queueRoutesForUpdate(...routes: Route[]) {
+ const currentScreen = useNavigationStore.getState().currentScreen;
+ const routeHistory = rootNavigatorRef.getState().routes;
+
+ // filter out routes that are not rendered to prevent unnecessary updates
+ routes = routes.filter(
+ //@ts-ignore
+ routeName => routeHistory?.findIndex(route => route.name === routeName) > -1
+ );
+
+ if (routes.indexOf(currentScreen.name) > -1) {
+ routeUpdateFunctions[currentScreen.name]();
+ clearRouteFromQueue(currentScreen.name);
+ // Remove focused screen from queue
+ routes.splice(routes.indexOf(currentScreen.name), 1);
+ routesUpdateQueue.splice(routesUpdateQueue.indexOf(currentScreen.name), 1);
+ }
+
+ routesUpdateQueue = routesUpdateQueue.concat(routes);
+ routesUpdateQueue = [...new Set(routesUpdateQueue)];
+}
+
+function navigate<T extends RouteName>(screen: CurrentScreen, params: RouteParams[T]) {
+ useNavigationStore.getState().update(screen, params.canGoBack);
+ if (screen.name === 'Notebook') routeUpdateFunctions['Notebook'](params);
+ if (screen.name.endsWith('Notes')) routeUpdateFunctions[screen.name](params);
+ //@ts-ignore
+ rootNavigatorRef.current?.navigate(screen.name, params);
+}
+
+function goBack() {
+ rootNavigatorRef.current?.goBack();
+}
+
+function push(screen: CurrentScreen, params: { [name: string]: any }) {
+ useNavigationStore.getState().update(screen, !params.menu);
+ //@ts-ignore
+ rootNavigatorRef.current?.dispatch(StackActions.push(name, params));
+}
+
+function replace(screen: CurrentScreen, params: { [name: string]: any }) {
+ useNavigationStore.getState().update(screen, !params.menu);
+ //@ts-ignore
+ rootNavigatorRef.current?.dispatch(StackActions.replace(name, params));
+}
+
+function popToTop() {
+ rootNavigatorRef.current?.dispatch(StackActions.popToTop());
+ useNavigationStore.getState().update({
+ name: SettingsService.get().homepage || 'Notes'
+ });
+}
+
+function openDrawer() {
+ tabBarRef.current?.openDrawer();
+}
+function closeDrawer() {
+ tabBarRef.current?.closeDrawer();
+}
+
+const Navigation = {
+ navigate,
+ goBack,
+ push,
+ openDrawer,
+ closeDrawer,
+ replace,
+ popToTop,
+ queueRoutesForUpdate,
+ routeNeedsUpdate,
+ routeNames,
+ routeUpdateFunctions
+};
+
+export default Navigation;
diff --git a/apps/mobile/src/services/notifications.ts b/apps/mobile/src/services/notifications.ts
index 7251411a9..c9d349a56 100644
--- a/apps/mobile/src/services/notifications.ts
+++ b/apps/mobile/src/services/notifications.ts
@@ -8,7 +8,7 @@ import { db } from '../utils/database';
import { MMKV } from '../utils/database/mmkv';
import { eOnLoadNote } from '../utils/events';
import { tabBarRef } from '../utils/global-refs';
-import { useNoteStore } from '../stores/stores';
+import { useNoteStore } from '../stores/use-notes-store';
import { DDS } from './device-detection';
import { eSendEvent } from './event-manager';
import SettingsService from './settings';
diff --git a/apps/mobile/src/services/premium.js b/apps/mobile/src/services/premium.js
index 5a71e732b..5d23c0561 100644
--- a/apps/mobile/src/services/premium.js
+++ b/apps/mobile/src/services/premium.js
@@ -6,7 +6,7 @@ import DialogHeader from '../components/dialog/dialog-header';
import { CompactFeatures } from '../components/premium/compact-features';
import { PricingPlans } from '../components/premium/pricing-plans';
import Seperator from '../components/ui/seperator';
-import { useUserStore } from '../stores/stores';
+import { useUserStore } from '../stores/use-user-store';
import { itemSkus, SUBSCRIPTION_STATUS } from '../utils/constants';
import { db } from '../utils/database';
import { eOpenPremiumDialog, eOpenTrialEndingDialog, eShowGetPremium } from '../utils/events';
@@ -95,6 +95,7 @@ const onUserStatusCheck = async type => {
if (userstore?.premium !== get()) {
userstore.setPremium(get());
}
+ console.log('status check: ', type, get());
let status = get();
let message = null;
diff --git a/apps/mobile/src/services/search.js b/apps/mobile/src/services/search.js
index edc036cff..6ce90ebae 100644
--- a/apps/mobile/src/services/search.js
+++ b/apps/mobile/src/services/search.js
@@ -1,11 +1,13 @@
-import { useSearchStore } from '../stores/stores';
+import { useSearchStore } from '../stores/use-search-store';
import { db } from '../utils/database';
+let prepareSearch = () => {};
+
let searchInformation = {
placeholder: 'Search in all notes',
data: [],
type: 'notes',
- get: null
+ get: () => null
};
let keyword = null;
@@ -32,8 +34,8 @@ async function search(silent) {
let results;
if (!searchInformation.type) return;
-
- results = await db.lookup[searchInformation.type](searchInformation.data, term);
+ let searchableData = searchInformation.get ? searchInformation.get() : [];
+ results = await db.lookup[searchInformation.type](searchableData, term);
if (!results || results.length === 0) {
searchstore.setSearchStatus(
@@ -53,7 +55,6 @@ function getSearchInformation() {
function updateAndSearch() {
if (!keyword || keyword === '') return;
- searchInformation.data = searchInformation.get() || [];
search(true);
}
@@ -62,7 +63,8 @@ const SearchService = {
getSearchInformation,
search,
setTerm,
- updateAndSearch
+ updateAndSearch,
+ prepareSearch
};
export default SearchService;
diff --git a/apps/mobile/src/services/settings.ts b/apps/mobile/src/services/settings.ts
index 53db27902..2f4aaa7cd 100644
--- a/apps/mobile/src/services/settings.ts
+++ b/apps/mobile/src/services/settings.ts
@@ -1,7 +1,7 @@
import { Platform } from 'react-native';
import { enabled } from 'react-native-privacy-snapshot';
import { SettingStore } from '../stores/interfaces';
-import { useSettingStore } from '../stores/stores';
+import { useSettingStore } from '../stores/use-setting-store';
import { AndroidModule } from '../utils';
import { getColorScheme } from '../utils/color-scheme/utils';
import { MMKV } from '../utils/database/mmkv';
@@ -99,10 +99,7 @@ function migrate(settings: SettingStore['settings']) {
function init() {
scale.fontScale = 1;
- let now = performance.now();
let settingsJson = MMKV.getString('appSettings');
-
- console.log('fetch data done', performance.now() - now);
let settings = get();
if (!settingsJson) {
MMKV.setString('appSettings', JSON.stringify(settings));
@@ -170,7 +167,7 @@ function get() {
return { ...useSettingStore.getState().settings };
}
-async function onFirstLaunch() {
+function onFirstLaunch() {
let introCompleted = get().introCompleted;
if (!introCompleted) {
set({
diff --git a/apps/mobile/src/services/sync.js b/apps/mobile/src/services/sync.js
index b329508ce..90be0e216 100644
--- a/apps/mobile/src/services/sync.js
+++ b/apps/mobile/src/services/sync.js
@@ -1,7 +1,8 @@
import NetInfo from '@react-native-community/netinfo';
import { EVENTS } from 'notes-core/common';
import { getNote, updateNoteInEditor } from '../screens/editor/Functions';
-import { initialize, useUserStore } from '../stores/stores';
+import { initialize } from '../stores';
+import { useUserStore } from '../stores/use-user-store';
import { doInBackground } from '../utils';
import { db } from '../utils/database';
import { ToastEvent } from './event-manager';
@@ -11,7 +12,8 @@ export const ignoredMessages = ['Sync already running', 'Not allowed to start se
const run = async (context = 'global', forced = false, full = true) => {
let result = false;
const userstore = useUserStore.getState();
- if (!userstore.user) {
+ const user = db.user.getUser();
+ if (!user) {
initialize();
return true;
}
@@ -19,8 +21,10 @@ const run = async (context = 'global', forced = false, full = true) => {
let error = null;
console.log('Sync.run started');
try {
+ console.log('DO IN BACKGROUND START');
let res = await doInBackground(async () => {
try {
+ console.log('DO IN BACKGROUND');
await db.sync(full, forced);
return true;
} catch (e) {
diff --git a/apps/mobile/src/services/tipmanager.ts b/apps/mobile/src/services/tipmanager.ts
index f49cb464a..f5b13b7c8 100644
--- a/apps/mobile/src/services/tipmanager.ts
+++ b/apps/mobile/src/services/tipmanager.ts
@@ -62,7 +62,6 @@ export class TipManager {
//@ts-ignore
popState = {};
}
- console.log('tipState:', tipState, 'popupState:', popState);
}
static tip(context: Context) {
diff --git a/apps/mobile/src/stores/index.ts b/apps/mobile/src/stores/index.ts
new file mode 100644
index 000000000..0494db3a2
--- /dev/null
+++ b/apps/mobile/src/stores/index.ts
@@ -0,0 +1,31 @@
+//@ts-ignore
+import { db } from '../utils/database';
+import { useNoteStore } from './use-notes-store';
+import { useFavoriteStore } from './use-favorite-store';
+import { useMenuStore } from './use-menu-store';
+import { useNotebookStore } from './use-notebook-store';
+import { useTagStore } from './use-tag-store';
+import { useTrashStore } from './use-trash-store';
+
+export function initialize() {
+ if (!db) return;
+ setImmediate(() => {
+ useMenuStore.getState().setColorNotes();
+ useMenuStore.getState().setMenuPins();
+ useNotebookStore.getState().setNotebooks();
+ useTrashStore.getState().setTrash();
+ useTagStore.getState().setTags();
+ useFavoriteStore.getState().setFavorites();
+ useNoteStore.getState().setNotes();
+ });
+}
+
+export function clearAllStores() {
+ useNotebookStore.getState().clearNotebooks();
+ useTagStore.getState().clearTags();
+ useFavoriteStore.getState().clearFavorites();
+ useMenuStore.getState().clearAll();
+ useNoteStore.getState().clearNotes();
+ useMenuStore.getState().clearAll();
+ useTrashStore.getState().clearTrash();
+}
diff --git a/apps/mobile/src/stores/interfaces.ts b/apps/mobile/src/stores/interfaces.ts
deleted file mode 100644
index 07920e2ab..000000000
--- a/apps/mobile/src/stores/interfaces.ts
+++ /dev/null
@@ -1,212 +0,0 @@
-import { FileType } from 'react-native-scoped-storage';
-import { State } from 'zustand';
-import 'notes-core/types';
-
-export type Item = {
- id: string;
-};
-
-export interface NoteStore extends State {
- notes: Item[];
- loading: boolean;
- setLoading: (loading: boolean) => void;
- setNotes: (items?: Item[]) => void;
- clearNotes: () => void;
-}
-
-export interface NotebookStore extends State {
- notebooks: Item[];
- setNotebooks: (items?: Item[]) => void;
- clearNotebooks: () => void;
-}
-
-export interface FavoriteStore extends State {
- favorites: Item[];
- setFavorites: (items?: Item[]) => void;
- clearFavorites: () => void;
-}
-
-export interface TagStore extends State {
- tags: Item[];
- setTags: (items?: Item[]) => void;
- clearTags: () => void;
-}
-
-export interface TrashStore extends State {
- trash: Item[];
- setTrash: (items?: Item[]) => void;
- clearTrash: () => void;
-}
-
-export interface UserStore extends State {
- user: User | null | undefined;
- premium: boolean;
- lastSynced: string;
- syncing: boolean;
- setUser: (user: User | null | undefined) => void;
- setPremium: (premium: boolean) => void;
- setSyncing: (syncing: boolean) => void;
- setLastSynced: (lastSynced: string) => void;
- verifyUser: boolean;
- setVerifyUser: (verified: boolean) => void;
-}
-
-export type Settings = {
- showToolbarOnTop?: boolean;
- showKeyboardOnOpen?: boolean;
- fontScale?: number;
- forcePortraitOnTablet?: boolean;
- useSystemTheme?: boolean;
- reminder?: string;
- encryptedBackup?: boolean;
- homepage?: string;
- sort?: string;
- sortOrder?: string;
- screenshotMode?: boolean;
- privacyScreen?: boolean;
- appLockMode?: string;
- telemetry?: boolean;
- notebooksListMode?: 'normal' | 'compact';
- notesListMode?: 'normal' | 'compact';
- devMode?: boolean;
- notifNotes?: boolean;
- pitchBlack?: boolean;
- reduceAnimations?: boolean;
- rateApp?: boolean | number;
- migrated?: boolean;
- introCompleted?: boolean;
- nextBackupRequestTime?: number | undefined;
- lastBackupDate?: number | undefined;
- userEmailConfirmed?: boolean;
- recoveryKeySaved?: boolean;
- theme: {
- accent: string;
- dark: boolean;
- };
- backupDirectoryAndroid?: FileType | null;
- showBackupCompleteSheet: boolean;
- lastRecoveryEmailTime?: number;
- lastVerificationEmailTime?: number;
- sessionExpired: boolean;
- version: number | null;
-};
-
-type Dimensions = {
- width: number;
- height: number;
-};
-
-export interface SettingStore extends State {
- settings: Settings;
- fullscreen: boolean;
- deviceMode: string | null;
- dimensions: Dimensions;
- setSettings: (settings: Settings) => void;
- setFullscreen: (fullscreen: boolean) => void;
- setDeviceMode: (mode: string) => void;
- setDimensions: (dimensions: Dimensions) => void;
- appLoading: boolean;
- setAppLoading: (appLoading: boolean) => void;
- setSheetKeyboardHandler: (sheetKeyboardHandler: boolean) => void;
- sheetKeyboardHandler: boolean;
- requestBiometrics: boolean;
- setRequestBiometrics: (requestBiometrics: boolean) => void;
-}
-
-export interface MenuStore extends State {
- menuPins: object[];
- colorNotes: object[];
- setMenuPins: () => void;
- setColorNotes: () => void;
- clearAll: () => void;
-}
-
-export interface EditorStore extends State {
- currentEditingNote: string | null;
- setCurrentlyEditingNote: (note: string | null) => void;
- sessionId: string | null;
- setSessionId: (sessionId: string | null) => void;
- searchReplace: boolean;
- setSearchReplace: (searchReplace: boolean) => void;
- searchSelection: string | null;
- readonly: boolean;
- setReadonly: (readonly: boolean) => void;
-}
-
-export interface SearchStore extends State {
- searchResults: object[];
- searching: boolean;
- searchStatus: string | null;
- setSearchResults: (results: object[]) => void;
- setSearchStatus: (searching: boolean, status: string | null) => void;
-}
-
-export interface SelectionStore extends State {
- selectedItemsList: Array<Object>;
- selectionMode: boolean;
- setAll: (all: Array<Object>) => void;
- setSelectionMode: (mode: boolean) => void;
- setSelectedItem: (item: Item) => void;
- clearSelection: (noanimation: boolean) => void;
-}
-
-export type Message = {
- visible: boolean;
- message: string | null;
- actionText: string | null;
- onPress: () => void;
- data: object;
- icon: string;
-};
-
-export type Action = {
- type: string;
- platforms: string[];
- title: string;
- data: string;
-};
-export type Style = {
- marginTop?: number;
- marginBottom?: number;
- textAlign?: 'center' | 'left' | 'right';
-};
-export type BodyItem = {
- type:
- | 'image'
- | 'title'
- | 'description'
- | 'body'
- | 'list'
- | 'features'
- | 'poll'
- | 'subheading'
- | 'shapes';
- src?: string;
- caption?: string;
- text?: string;
- style?: Style;
- items?: Array<{
- text?: string;
- }>;
-};
-
-export type Announcement = {
- type: 'dialog' | 'inline';
- body: BodyItem[];
- id: string;
- callToActions: Action[];
- timestamp: number;
- platforms: string[];
- isActive: boolean;
- userTypes: string[];
- appVersion: number;
-};
-
-export interface MessageStore extends State {
- message: Message;
- setMessage: (message: Message) => void;
- announcements: Announcement[];
- setAnnouncement: () => Promise<void>;
- dialogs: Announcement[];
- remove: (id: string) => void;
-}
diff --git a/apps/mobile/src/stores/stores.ts b/apps/mobile/src/stores/stores.ts
deleted file mode 100644
index 5d29d216c..000000000
--- a/apps/mobile/src/stores/stores.ts
+++ /dev/null
@@ -1,525 +0,0 @@
-//@ts-ignore
-import { groupArray } from 'notes-core/utils/grouping';
-import { Dimensions, Platform } from 'react-native';
-import create from 'zustand';
-import { APP_VERSION } from '../../version';
-import { eSubscribeEvent, eUnSubscribeEvent } from '../services/event-manager';
-import PremiumService from '../services/premium';
-import { history } from '../utils';
-import { SUBSCRIPTION_STATUS } from '../utils/constants';
-import { db } from '../utils/database';
-import { MMKV } from '../utils/database/mmkv';
-import layoutmanager from '../utils/layout-manager';
-import { EditorWebView } from '../screens/editor/Functions';
-import tiny from '../screens/editor/tiny/tiny';
-import { endSearch } from '../screens/editor/tiny/toolbar/commands';
-import {
- Announcement,
- EditorStore,
- FavoriteStore,
- MenuStore,
- MessageStore,
- NotebookStore,
- NoteStore,
- SearchStore,
- SelectionStore,
- SettingStore,
- TagStore,
- TrashStore,
- UserStore
-} from './interfaces';
-import { ACCENT } from '../utils/color-scheme';
-
-export const useNoteStore = create<NoteStore>((set, get) => ({
- notes: [],
- loading: true,
- setLoading: loading => set({ loading: loading }),
- setNotes: items => {
- if (!items) {
- set({
- notes: groupArray(db.notes.all, db.settings?.getGroupOptions('home'))
- });
- return;
- }
- let prev = get().notes;
- for (let 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<NotebookStore>((set, get) => ({
- notebooks: [],
- setNotebooks: items => {
- if (!items) {
- set({
- notebooks: groupArray(db.notebooks.all, db.settings?.getGroupOptions('notebooks'))
- });
- return;
- }
- let prev = get().notebooks;
- for (let 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<FavoriteStore>((set, get) => ({
- favorites: [],
- setFavorites: items => {
- if (!items) {
- set({
- favorites: groupArray(db.notes.favorites, db.settings?.getGroupOptions('favorites'))
- });
- return;
- }
- let prev = get().favorites;
- for (let 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<TagStore>((set, get) => ({
- tags: [],
- setTags: items => {
- if (!items) {
- set({
- tags: groupArray(db.tags.all, db.settings?.getGroupOptions('tags'))
- });
- return;
- }
- let prev = get().tags;
- for (let 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<TrashStore>((set, get) => ({
- trash: [],
- setTrash: items => {
- if (!items) {
- set({
- trash: groupArray(db.trash.all, db.settings?.getGroupOptions('trash'))
- });
- return;
- }
- let prev = get().trash;
- for (let 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<UserStore>((set, get) => ({
- user: null,
- premium: false,
- lastSynced: 'Never',
- syncing: false,
- verifyUser: false,
- setUser: user => set({ user: user }),
- setPremium: premium => set({ premium: premium }),
- setSyncing: syncing => set({ syncing: syncing }),
- setLastSynced: lastSynced => set({ lastSynced: lastSynced }),
- setVerifyUser: verified => set({ verifyUser: verified })
-}));
-
-interface AttachmentStore {
- progress?: {
- [name: string]: {
- sent: number;
- total: number;
- hash: string;
- recieved: number;
- type: 'upload' | 'download';
- } | null;
- };
- encryptionProgress: number;
- setEncryptionProgress: (encryptionProgress: number) => void;
- remove: (hash: string) => void;
- setProgress: (
- sent: number,
- total: number,
- hash: string,
- recieved: number,
- type: 'upload' | 'download'
- ) => void;
- loading: { total: number; current: number };
- setLoading: (data: { total: number; current: number }) => void;
-}
-
-export const useAttachmentStore = create<AttachmentStore>((set, get) => ({
- progress: {},
- remove: hash => {
- let _p = get().progress;
- if (!_p) return;
- _p[hash] = null;
- tiny.call(
- EditorWebView,
- `
- (function() {
- let progress = ${JSON.stringify({
- loaded: 1,
- total: 1,
- hash
- })}
- tinymce.activeEditor._updateAttachmentProgress(progress);
- })()`
- );
- set({ progress: { ..._p } });
- },
- setProgress: (sent, total, hash, recieved, type) => {
- let _p = get().progress;
- if (!_p) return;
- _p[hash] = { sent, total, hash, recieved, type };
- let progress = { total, hash, loaded: type === 'download' ? recieved : sent };
- tiny.call(
- EditorWebView,
- `
- (function() {
- let progress = ${JSON.stringify(progress)}
- tinymce.activeEditor._updateAttachmentProgress(progress);
- })()`
- );
- set({ progress: { ..._p } });
- },
- encryptionProgress: 0,
- setEncryptionProgress: encryptionProgress => set({ encryptionProgress: encryptionProgress }),
- loading: { total: 0, current: 0 },
- setLoading: data => set({ loading: data })
-}));
-
-let { width, height } = Dimensions.get('window');
-
-export const useSettingStore = create<SettingStore>((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',
- telemetry: true,
- notebooksListMode: 'normal',
- notesListMode: 'normal',
- devMode: false,
- notifNotes: false,
- pitchBlack: false,
- reduceAnimations: false,
- rateApp: false,
- migrated: false,
- introCompleted: false,
- nextBackupRequestTime: undefined,
- lastBackupDate: undefined,
- userEmailConfirmed: false,
- recoveryKeySaved: false,
- theme: {
- accent: ACCENT.color,
- dark: false
- },
- showBackupCompleteSheet: true,
- sessionExpired: false,
- version: null
- },
- sheetKeyboardHandler: true,
- fullscreen: false,
- deviceMode: 'mobile',
- dimensions: { width, height },
- appLoading: true,
- setSettings: settings => set({ settings }),
- setFullscreen: fullscreen => set({ fullscreen }),
- setDeviceMode: mode => set({ deviceMode: mode }),
- setDimensions: dimensions => set({ dimensions: dimensions }),
- setAppLoading: appLoading => set({ appLoading }),
- setSheetKeyboardHandler: sheetKeyboardHandler => set({ sheetKeyboardHandler }),
- requestBiometrics: false,
- setRequestBiometrics: requestBiometrics => set({ requestBiometrics })
-}));
-
-export const useMenuStore = create<MenuStore>((set, get) => ({
- menuPins: [],
- colorNotes: [],
- setMenuPins: () => {
- try {
- set({ menuPins: db.settings?.pins || [] });
- } catch (e) {
- setTimeout(() => {
- try {
- set({ menuPins: db.settings?.pins || [] });
- } catch (e) {}
- }, 1000);
- }
- },
- //@ts-ignore
- setColorNotes: () => set({ colorNotes: db.colors?.all || [] }),
- clearAll: () => set({ menuPins: [], colorNotes: [] })
-}));
-
-export const useEditorStore = create<EditorStore>((set, get) => ({
- currentEditingNote: null,
- setCurrentlyEditingNote: note => set({ currentEditingNote: note }),
- sessionId: null,
- setSessionId: sessionId => {
- console.log(sessionId, 'session id');
- tiny.call(EditorWebView, `sessionId="${sessionId}";`);
- set({ sessionId });
- },
- searchReplace: false,
- searchSelection: null,
- readonly: false,
- setReadonly: readonly => {
- set({ readonly: readonly });
- },
- setSearchReplace: searchReplace => {
- if (!searchReplace) {
- set({ searchSelection: null, searchReplace: false });
- return;
- }
- let func = (value: string) => {
- eUnSubscribeEvent('selectionvalue', func);
- console.log('setSearchReplace:', value, value.length);
- if (!value && get().searchReplace) {
- endSearch();
- return;
- }
- set({ searchSelection: value, searchReplace: true });
- };
- eSubscribeEvent('selectionvalue', func);
- tiny.call(
- EditorWebView,
- `(function() {
- if (editor) {
- reactNativeEventHandler('selectionvalue',editor.selection.getContent());
- }
- })();`
- );
- }
-}));
-
-export const useSearchStore = create<SearchStore>((set, get) => ({
- searchResults: [],
- searching: false,
- searchStatus: null,
- setSearchResults: results => set({ searchResults: results }),
- setSearchStatus: (searching, status) => set({ searching, searchStatus: status })
-}));
-
-export const useSelectionStore = create<SelectionStore>((set, get) => ({
- selectedItemsList: [],
- selectionMode: false,
- setAll: all => {
- //@ts-ignore
- history.selectedItemsList = all;
- set({ selectedItemsList: all });
- },
- setSelectionMode: mode => {
- if (!mode) {
- history.selectedItemsList = [];
- history.selectionMode = false;
- } else {
- history.selectionMode = true;
- }
- set({
- selectionMode: mode,
- selectedItemsList: mode ? get().selectedItemsList : []
- });
- },
- setSelectedItem: item => {
- let selectedItems = get().selectedItemsList;
- let index = selectedItems.findIndex((i: any) => i.id === item.id);
- if (index !== -1) {
- selectedItems.splice(index, 1);
- } else {
- selectedItems.push(item);
- }
- selectedItems = [...new Set(selectedItems)];
- //@ts-ignore
- history.selectedItemsList = selectedItems;
- history.selectionMode = selectedItems.length > 0 ? get().selectionMode : false;
- set({
- selectedItemsList: selectedItems,
- selectionMode: history.selectionMode
- });
- },
- clearSelection: noanimation => {
- history.selectedItemsList = [];
- history.selectionMode = false;
- set({ selectionMode: false, selectedItemsList: [] });
- }
-}));
-
-export const useMessageStore = create<MessageStore>((set, get) => ({
- message: {
- visible: false,
- message: null,
- actionText: null,
- onPress: () => {},
- data: {},
- icon: 'account-outline'
- },
- setMessage: message => {
- console.log('setting message');
- setTimeout(() => {
- if (get().message.visible || message.visible) {
- layoutmanager.withAnimation();
- }
-
- set({ message: { ...message } });
- }, 1);
- },
- announcements: [],
- remove: async id => {
- MMKV.setItem(id, 'removed');
-
- const inlineCopy = get().announcements.slice();
- const dialogsCopy = get().dialogs.slice();
- const index = inlineCopy.findIndex(announcement => announcement.id === id);
- const dialogIndex = dialogsCopy.findIndex(dialog => dialog.id === id);
-
- if (index >= -1) {
- dialogsCopy.splice(dialogIndex, 1);
- inlineCopy.splice(index, 1);
- }
- set({ announcements: inlineCopy, dialogs: dialogsCopy });
- },
- dialogs: [],
- setAnnouncement: async function () {
- let announcements: Announcement[] = [];
- try {
- announcements = await db.announcements();
- if (!announcements) {
- announcements = [];
- }
- } catch (e) {
- console.log('ERROR', e);
- set({ announcements: [] });
- } finally {
- let all = await getFiltered(announcements);
-
- setTimeout(() => {
- if (all.filter(a => a.type === 'inline').length !== 0) {
- console.log('with setAnnouncement ');
- layoutmanager.withAnimation();
- }
- set({
- announcements: all.filter(a => a.type === 'inline'),
- dialogs: all.filter(a => a.type === 'dialog')
- });
- }, 1);
- }
- }
-}));
-
-const getFiltered = async (announcements: Announcement[]) => {
- if (!announcements) return [];
- let filtered: Announcement[] = [];
- for (let announcement of announcements) {
- if (await shouldShowAnnouncement(announcement)) {
- filtered.push(announcement);
- }
- }
- return filtered;
-};
-
-export function initialize() {
- if (!db) return;
- useMenuStore.getState().setColorNotes();
- useMenuStore.getState().setMenuPins();
- useNotebookStore.getState().setNotebooks();
- useTrashStore.getState().setTrash();
- useTagStore.getState().setTags();
- useFavoriteStore.getState().setFavorites();
- useNoteStore.getState().setNotes();
-}
-
-export function clearAllStores() {
- useNotebookStore.getState().clearNotebooks();
- useTagStore.getState().clearTags();
- useFavoriteStore.getState().clearFavorites();
- useMenuStore.getState().clearAll();
- useNoteStore.getState().clearNotes();
- useMenuStore.getState().clearAll();
- useTrashStore.getState().clearTrash();
-}
-
-export const allowedPlatforms = ['all', 'mobile', Platform.OS];
-
-async function shouldShowAnnouncement(announcement: Announcement) {
- if (!announcement) return false;
- let removed = (await MMKV.getStringAsync(announcement.id)) === 'removed';
- if (removed) return false;
- let show = announcement.platforms.some(platform => allowedPlatforms.indexOf(platform) > -1);
-
- if (announcement.appVersion) {
- return announcement.appVersion === APP_VERSION;
- }
-
- if (!show) return false;
- const subStatus = PremiumService.getUser()?.subscription?.type;
- show = announcement.userTypes.some(userType => {
- switch (userType) {
- case 'pro':
- return PremiumService.get();
- case 'trial':
- return subStatus === SUBSCRIPTION_STATUS.TRIAL;
- case 'trialExpired':
- return subStatus === SUBSCRIPTION_STATUS.BASIC;
- case 'loggedOut':
- return !PremiumService.getUser();
- case 'verified':
- return PremiumService.getUser()?.isEmailVerified;
- case 'loggedIn':
- return !!PremiumService.getUser();
- case 'unverified':
- return !PremiumService.getUser()?.isEmailVerified;
- case 'proExpired':
- return (
- subStatus === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED ||
- subStatus === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED
- );
- case 'any':
- default:
- return true;
- }
- });
-
- return show;
-}
diff --git a/apps/mobile/src/stores/useAttachmentStore.ts b/apps/mobile/src/stores/useAttachmentStore.ts
new file mode 100644
index 000000000..e38f3b4d9
--- /dev/null
+++ b/apps/mobile/src/stores/useAttachmentStore.ts
@@ -0,0 +1,69 @@
+//@ts-ignore
+import create from 'zustand';
+import { EditorWebView } from '../screens/editor/Functions';
+import tiny from '../screens/editor/tiny/tiny';
+
+interface AttachmentStore {
+ progress?: {
+ [name: string]: {
+ sent: number;
+ total: number;
+ hash: string;
+ recieved: number;
+ type: 'upload' | 'download';
+ } | null;
+ };
+ encryptionProgress: number;
+ setEncryptionProgress: (encryptionProgress: number) => void;
+ remove: (hash: string) => void;
+ setProgress: (
+ sent: number,
+ total: number,
+ hash: string,
+ recieved: number,
+ type: 'upload' | 'download'
+ ) => void;
+ loading: { total: number; current: number };
+ setLoading: (data: { total: number; current: number }) => void;
+}
+
+export const useAttachmentStore = create<AttachmentStore>((set, get) => ({
+ progress: {},
+ remove: hash => {
+ let _p = get().progress;
+ if (!_p) return;
+ _p[hash] = null;
+ tiny.call(
+ EditorWebView,
+ `
+ (function() {
+ let progress = ${JSON.stringify({
+ loaded: 1,
+ total: 1,
+ hash
+ })}
+ tinymce.activeEditor._updateAttachmentProgress(progress);
+ })()`
+ );
+ set({ progress: { ..._p } });
+ },
+ setProgress: (sent, total, hash, recieved, type) => {
+ let _p = get().progress;
+ if (!_p) return;
+ _p[hash] = { sent, total, hash, recieved, type };
+ let progress = { total, hash, loaded: type === 'download' ? recieved : sent };
+ tiny.call(
+ EditorWebView,
+ `
+ (function() {
+ let progress = ${JSON.stringify(progress)}
+ tinymce.activeEditor._updateAttachmentProgress(progress);
+ })()`
+ );
+ set({ progress: { ..._p } });
+ },
+ encryptionProgress: 0,
+ setEncryptionProgress: encryptionProgress => set({ encryptionProgress: encryptionProgress }),
+ loading: { total: 0, current: 0 },
+ setLoading: data => set({ loading: data })
+}));
diff --git a/apps/mobile/src/stores/useEditorStore.ts b/apps/mobile/src/stores/useEditorStore.ts
new file mode 100644
index 000000000..3ee5deb3b
--- /dev/null
+++ b/apps/mobile/src/stores/useEditorStore.ts
@@ -0,0 +1,59 @@
+//@ts-ignore
+import create, { State } from 'zustand';
+import { EditorWebView } from '../screens/editor/Functions';
+import tiny from '../screens/editor/tiny/tiny';
+import { endSearch } from '../screens/editor/tiny/toolbar/commands';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../services/event-manager';
+
+export interface EditorStore extends State {
+ currentEditingNote: string | null;
+ setCurrentlyEditingNote: (note: string | null) => void;
+ sessionId: string | null;
+ setSessionId: (sessionId: string | null) => void;
+ searchReplace: boolean;
+ setSearchReplace: (searchReplace: boolean) => void;
+ searchSelection: string | null;
+ readonly: boolean;
+ setReadonly: (readonly: boolean) => void;
+}
+
+export const useEditorStore = create<EditorStore>((set, get) => ({
+ currentEditingNote: null,
+ setCurrentlyEditingNote: note => set({ currentEditingNote: note }),
+ sessionId: null,
+ setSessionId: sessionId => {
+ console.log(sessionId, 'session id');
+ tiny.call(EditorWebView, `sessionId="${sessionId}";`);
+ set({ sessionId });
+ },
+ searchReplace: false,
+ searchSelection: null,
+ readonly: false,
+ setReadonly: readonly => {
+ set({ readonly: readonly });
+ },
+ setSearchReplace: searchReplace => {
+ if (!searchReplace) {
+ set({ searchSelection: null, searchReplace: false });
+ return;
+ }
+ let func = (value: string) => {
+ eUnSubscribeEvent('selectionvalue', func);
+ console.log('setSearchReplace:', value, value.length);
+ if (!value && get().searchReplace) {
+ endSearch();
+ return;
+ }
+ set({ searchSelection: value, searchReplace: true });
+ };
+ eSubscribeEvent('selectionvalue', func);
+ tiny.call(
+ EditorWebView,
+ `(function() {
+ if (editor) {
+ reactNativeEventHandler('selectionvalue',editor.selection.getContent());
+ }
+ })();`
+ );
+ }
+}));
diff --git a/apps/mobile/src/stores/useFavoriteStore.ts b/apps/mobile/src/stores/useFavoriteStore.ts
new file mode 100644
index 000000000..ec3477482
--- /dev/null
+++ b/apps/mobile/src/stores/useFavoriteStore.ts
@@ -0,0 +1,33 @@
+//@ts-ignore
+import { groupArray } from 'notes-core/utils/grouping';
+import create, { State } from 'zustand';
+import { db } from '../utils/database';
+import { NoteType } from '../utils/types';
+
+export interface FavoriteStore extends State {
+ favorites: NoteType[];
+ setFavorites: (items?: NoteType[]) => void;
+ clearFavorites: () => void;
+}
+
+export const useFavoriteStore = create<FavoriteStore>((set, get) => ({
+ favorites: [],
+ setFavorites: items => {
+ if (!items) {
+ set({
+ favorites: groupArray(db?.notes?.favorites || [], db.settings?.getGroupOptions('favorites'))
+ });
+ return;
+ }
+ let prev = get().favorites;
+ for (let 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: [] })
+}));
diff --git a/apps/mobile/src/stores/useMenuStore.ts b/apps/mobile/src/stores/useMenuStore.ts
new file mode 100644
index 000000000..57bc3b3bf
--- /dev/null
+++ b/apps/mobile/src/stores/useMenuStore.ts
@@ -0,0 +1,30 @@
+//@ts-ignore
+import create, { State } from 'zustand';
+import { db } from '../utils/database';
+
+export interface MenuStore extends State {
+ menuPins: object[];
+ colorNotes: object[];
+ setMenuPins: () => void;
+ setColorNotes: () => void;
+ clearAll: () => void;
+}
+
+export const useMenuStore = create<MenuStore>((set, get) => ({
+ menuPins: [],
+ colorNotes: [],
+ setMenuPins: () => {
+ try {
+ set({ menuPins: db.settings?.pins || [] });
+ } catch (e) {
+ setTimeout(() => {
+ try {
+ set({ menuPins: db.settings?.pins || [] });
+ } catch (e) {}
+ }, 1000);
+ }
+ },
+ //@ts-ignore
+ setColorNotes: () => set({ colorNotes: db.colors?.all || [] }),
+ clearAll: () => set({ menuPins: [], colorNotes: [] })
+}));
diff --git a/apps/mobile/src/stores/useMessageStore.ts b/apps/mobile/src/stores/useMessageStore.ts
new file mode 100644
index 000000000..a21d6bf5e
--- /dev/null
+++ b/apps/mobile/src/stores/useMessageStore.ts
@@ -0,0 +1,186 @@
+//@ts-ignore
+import { Platform } from 'react-native';
+import create, { State } from 'zustand';
+import { APP_VERSION } from '../../version';
+import PremiumService from '../services/premium';
+import { SUBSCRIPTION_STATUS } from '../utils/constants';
+import { db } from '../utils/database';
+import { MMKV } from '../utils/database/mmkv';
+import layoutmanager from '../utils/layout-manager';
+export interface MessageStore extends State {
+ message: Message;
+ setMessage: (message: Message) => void;
+ announcements: Announcement[];
+ setAnnouncement: () => Promise<void>;
+ dialogs: Announcement[];
+ remove: (id: string) => void;
+}
+
+export type Message = {
+ visible: boolean;
+ message: string | null;
+ actionText: string | null;
+ onPress: () => void;
+ data: object;
+ icon: string;
+};
+
+export type Action = {
+ type: string;
+ platforms: string[];
+ title: string;
+ data: string;
+};
+export type Style = {
+ marginTop?: number;
+ marginBottom?: number;
+ textAlign?: 'center' | 'left' | 'right';
+};
+export type BodyItem = {
+ type:
+ | 'image'
+ | 'title'
+ | 'description'
+ | 'body'
+ | 'list'
+ | 'features'
+ | 'poll'
+ | 'subheading'
+ | 'shapes';
+ src?: string;
+ caption?: string;
+ text?: string;
+ style?: Style;
+ items?: Array<{
+ text?: string;
+ }>;
+};
+
+export type Announcement = {
+ type: 'dialog' | 'inline';
+ body: BodyItem[];
+ id: string;
+ callToActions: Action[];
+ timestamp: number;
+ platforms: string[];
+ isActive: boolean;
+ userTypes: string[];
+ appVersion: number;
+};
+
+export const useMessageStore = create<MessageStore>((set, get) => ({
+ message: {
+ visible: false,
+ message: null,
+ actionText: null,
+ onPress: () => {},
+ data: {},
+ icon: 'account-outline'
+ },
+ setMessage: message => {
+ console.log('setting message');
+ setTimeout(() => {
+ if (get().message.visible || message.visible) {
+ layoutmanager.withAnimation();
+ }
+
+ set({ message: { ...message } });
+ }, 1);
+ },
+ announcements: [],
+ remove: async id => {
+ MMKV.setItem(id, 'removed');
+
+ const inlineCopy = get().announcements.slice();
+ const dialogsCopy = get().dialogs.slice();
+ const index = inlineCopy.findIndex(announcement => announcement.id === id);
+ const dialogIndex = dialogsCopy.findIndex(dialog => dialog.id === id);
+
+ if (index >= -1) {
+ dialogsCopy.splice(dialogIndex, 1);
+ inlineCopy.splice(index, 1);
+ }
+ set({ announcements: inlineCopy, dialogs: dialogsCopy });
+ },
+ dialogs: [],
+ setAnnouncement: async function () {
+ let announcements: Announcement[] = [];
+ try {
+ announcements = await db.announcements();
+ if (!announcements) {
+ announcements = [];
+ }
+ } catch (e) {
+ console.log('ERROR', e);
+ set({ announcements: [] });
+ } finally {
+ let all = await getFiltered(announcements);
+
+ setTimeout(() => {
+ if (all.filter(a => a.type === 'inline').length !== 0) {
+ console.log('with setAnnouncement ');
+ layoutmanager.withAnimation();
+ }
+ set({
+ announcements: all.filter(a => a.type === 'inline'),
+ dialogs: all.filter(a => a.type === 'dialog')
+ });
+ }, 1);
+ }
+ }
+}));
+
+const getFiltered = async (announcements: Announcement[]) => {
+ if (!announcements) return [];
+ let filtered: Announcement[] = [];
+ for (let announcement of announcements) {
+ if (await shouldShowAnnouncement(announcement)) {
+ filtered.push(announcement);
+ }
+ }
+ return filtered;
+};
+
+export const allowedPlatforms = ['all', 'mobile', Platform.OS];
+
+async function shouldShowAnnouncement(announcement: Announcement) {
+ if (!announcement) return false;
+ let removed = (await MMKV.getStringAsync(announcement.id)) === 'removed';
+ if (removed) return false;
+ let show = announcement.platforms.some(platform => allowedPlatforms.indexOf(platform) > -1);
+
+ if (announcement.appVersion) {
+ return announcement.appVersion === APP_VERSION;
+ }
+
+ if (!show) return false;
+ const subStatus = PremiumService.getUser()?.subscription?.type;
+ show = announcement.userTypes.some(userType => {
+ switch (userType) {
+ case 'pro':
+ return PremiumService.get();
+ case 'trial':
+ return subStatus === SUBSCRIPTION_STATUS.TRIAL;
+ case 'trialExpired':
+ return subStatus === SUBSCRIPTION_STATUS.BASIC;
+ case 'loggedOut':
+ return !PremiumService.getUser();
+ case 'verified':
+ return PremiumService.getUser()?.isEmailVerified;
+ case 'loggedIn':
+ return !!PremiumService.getUser();
+ case 'unverified':
+ return !PremiumService.getUser()?.isEmailVerified;
+ case 'proExpired':
+ return (
+ subStatus === SUBSCRIPTION_STATUS.PREMIUM_EXPIRED ||
+ subStatus === SUBSCRIPTION_STATUS.PREMIUM_CANCELLED
+ );
+ case 'any':
+ default:
+ return true;
+ }
+ });
+
+ return show;
+}
diff --git a/apps/mobile/src/stores/useNavigationStore.ts b/apps/mobile/src/stores/useNavigationStore.ts
new file mode 100644
index 000000000..89cffeb0d
--- /dev/null
+++ b/apps/mobile/src/stores/useNavigationStore.ts
@@ -0,0 +1,88 @@
+import create, { State } from 'zustand';
+import { COLORS_NOTE } from '../utils/color-scheme';
+import { LiteralUnion } from '../utils/types';
+
+export type RouteName =
+ | 'Notes'
+ | 'Notebooks'
+ | 'Notebook'
+ | 'NotesPage'
+ | 'Tags'
+ | 'Favorites'
+ | 'Trash'
+ | 'Search'
+ | 'Settings'
+ | 'TaggedNotes'
+ | 'ColoredNotes'
+ | 'TopicNotes'
+ | 'Monographs';
+
+export type Route = LiteralUnion<RouteName>;
+
+export type CurrentScreen = {
+ name: Route;
+ id?: string;
+ title?: string;
+ type?: string;
+ color?: null;
+ alias?: string;
+ notebookId?: string;
+};
+
+export type HeaderRightButton = {
+ title: string;
+ onPress: () => void;
+};
+
+interface NavigationStore extends State {
+ currentScreen: CurrentScreen;
+ canGoBack: boolean | undefined;
+ update: (
+ currentScreen: CurrentScreen,
+ canGoBack?: boolean,
+ headerRightButtons?: HeaderRightButton[]
+ ) => void;
+ headerRightButtons?: HeaderRightButton[];
+}
+
+const useNavigationStore = create<NavigationStore>((set, get) => ({
+ currentScreen: {
+ name: 'Notes',
+ id: 'notes_navigation',
+ title: 'Notes',
+ type: 'notes'
+ },
+ canGoBack: false,
+ update: (currentScreen, canGoBack, headerRightButtons) => {
+ //@ts-ignore
+ const color = COLORS_NOTE[currentScreen.title?.toLowerCase()];
+ if (
+ currentScreen.name === get().currentScreen.name &&
+ !currentScreen.id &&
+ get().currentScreen.id?.endsWith('_navigation')
+ )
+ return;
+
+ if (
+ currentScreen.name === get().currentScreen.name &&
+ currentScreen.id === get().currentScreen.id
+ )
+ return;
+ console.log('UPDATING STATE', currentScreen.name, canGoBack);
+ set({
+ currentScreen: {
+ name: currentScreen.name,
+ id: currentScreen.id || currentScreen.name.toLowerCase() + '_navigation',
+ title: currentScreen.alias || currentScreen.title || currentScreen.name,
+ type: currentScreen.type,
+ color: color,
+ notebookId: currentScreen.notebookId
+ },
+ canGoBack,
+ headerRightButtons: headerRightButtons
+ });
+ },
+ headerRightButtons: []
+}));
+
+export default useNavigationStore;
diff --git a/apps/mobile/src/stores/useNotebookStore.ts b/apps/mobile/src/stores/useNotebookStore.ts
new file mode 100644
index 000000000..f81f045b7
--- /dev/null
+++ b/apps/mobile/src/stores/useNotebookStore.ts
@@ -0,0 +1,35 @@
+//@ts-ignore
+import { groupArray } from 'notes-core/utils/grouping';
+import create, { State } from 'zustand';
+import { db } from '../utils/database';
+import { NotebookType } from '../utils/types';
+export interface NotebookStore extends State {
+ notebooks: NotebookType[];
+ setNotebooks: (items?: NotebookType[]) => void;
+ clearNotebooks: () => void;
+}
+
+export const useNotebookStore = create<NotebookStore>((set, get) => ({
+ notebooks: [],
+ setNotebooks: items => {
+ if (!items) {
+ set({
+ notebooks: groupArray(
+ (db?.notebooks?.all as NotebookType[]) || [],
+ db.settings?.getGroupOptions('notebooks')
+ )
+ });
+ return;
+ }
+ let prev = get().notebooks;
+ for (let 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: [] })
+}));
diff --git a/apps/mobile/src/stores/useNotesStore.ts b/apps/mobile/src/stores/useNotesStore.ts
new file mode 100644
index 000000000..aca1b94d3
--- /dev/null
+++ b/apps/mobile/src/stores/useNotesStore.ts
@@ -0,0 +1,37 @@
+//@ts-ignore
+import { groupArray } from 'notes-core/utils/grouping';
+import create, { State } from 'zustand';
+import { db } from '../utils/database';
+import { NoteType } from '../utils/types';
+
+export interface NoteStore extends State {
+ notes: NoteType[];
+ loading: boolean;
+ setLoading: (loading: boolean) => void;
+ setNotes: (items?: NoteType[]) => void;
+ clearNotes: () => void;
+}
+
+export const useNoteStore = create<NoteStore>((set, get) => ({
+ notes: [],
+ loading: true,
+ setLoading: loading => set({ loading: loading }),
+ setNotes: items => {
+ if (!items) {
+ set({
+ notes: groupArray((db.notes?.all as NoteType[]) || [], db.settings?.getGroupOptions('home'))
+ });
+ return;
+ }
+ let prev = get().notes;
+ for (let 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: [] })
+}));
diff --git a/apps/mobile/src/stores/useSearchStore.ts b/apps/mobile/src/stores/useSearchStore.ts
new file mode 100644
index 000000000..98f553f50
--- /dev/null
+++ b/apps/mobile/src/stores/useSearchStore.ts
@@ -0,0 +1,17 @@
+//@ts-ignore
+import create, { State } from 'zustand';
+export interface SearchStore extends State {
+ searchResults: object[];
+ searching: boolean;
+ searchStatus: string | null;
+ setSearchResults: (results: object[]) => void;
+ setSearchStatus: (searching: boolean, status: string | null) => void;
+}
+
+export const useSearchStore = create<SearchStore>((set, get) => ({
+ searchResults: [],
+ searching: false,
+ searchStatus: null,
+ setSearchResults: results => set({ searchResults: results }),
+ setSearchStatus: (searching, status) => set({ searching, searchStatus: status })
+}));
diff --git a/apps/mobile/src/stores/useSelectionStore.ts b/apps/mobile/src/stores/useSelectionStore.ts
new file mode 100644
index 000000000..77044a061
--- /dev/null
+++ b/apps/mobile/src/stores/useSelectionStore.ts
@@ -0,0 +1,56 @@
+//@ts-ignore
+import create, { State } from 'zustand';
+import { history } from '../utils';
+
+export interface SelectionStore extends State {
+ selectedItemsList: Array<Object>;
+ selectionMode: boolean;
+ setAll: (all: Array<Object>) => void;
+ setSelectionMode: (mode: boolean) => void;
+ setSelectedItem: (item: Item) => void;
+ clearSelection: (noanimation: boolean) => void;
+}
+
+export const useSelectionStore = create<SelectionStore>((set, get) => ({
+ selectedItemsList: [],
+ selectionMode: false,
+ setAll: all => {
+ //@ts-ignore
+ history.selectedItemsList = all;
+ set({ selectedItemsList: all });
+ },
+ setSelectionMode: mode => {
+ if (!mode) {
+ history.selectedItemsList = [];
+ history.selectionMode = false;
+ } else {
+ history.selectionMode = true;
+ }
+ set({
+ selectionMode: mode,
+ selectedItemsList: mode ? get().selectedItemsList : []
+ });
+ },
+ setSelectedItem: item => {
+ let selectedItems = get().selectedItemsList;
+ let index = selectedItems.findIndex((i: any) => i.id === item.id);
+ if (index !== -1) {
+ selectedItems.splice(index, 1);
+ } else {
+ selectedItems.push(item);
+ }
+ selectedItems = [...new Set(selectedItems)];
+ //@ts-ignore
+ history.selectedItemsList = selectedItems;
+ history.selectionMode = selectedItems.length > 0 ? get().selectionMode : false;
+ set({
+ selectedItemsList: selectedItems,
+ selectionMode: history.selectionMode
+ });
+ },
+ clearSelection: noanimation => {
+ history.selectedItemsList = [];
+ history.selectionMode = false;
+ set({ selectionMode: false, selectedItemsList: [] });
+ }
+}));
diff --git a/apps/mobile/src/stores/useSettingStore.ts b/apps/mobile/src/stores/useSettingStore.ts
new file mode 100644
index 000000000..351d009cf
--- /dev/null
+++ b/apps/mobile/src/stores/useSettingStore.ts
@@ -0,0 +1,121 @@
+//@ts-ignore
+import { Dimensions } from 'react-native';
+import { FileType } from 'react-native-scoped-storage';
+import create, { State } from 'zustand';
+import { ACCENT } from '../utils/color-scheme';
+
+export type Settings = {
+ showToolbarOnTop?: boolean;
+ showKeyboardOnOpen?: boolean;
+ fontScale?: number;
+ forcePortraitOnTablet?: boolean;
+ useSystemTheme?: boolean;
+ reminder?: string;
+ encryptedBackup?: boolean;
+ homepage?: string;
+ sort?: string;
+ sortOrder?: string;
+ screenshotMode?: boolean;
+ privacyScreen?: boolean;
+ appLockMode?: string;
+ telemetry?: boolean;
+ notebooksListMode?: 'normal' | 'compact';
+ notesListMode?: 'normal' | 'compact';
+ devMode?: boolean;
+ notifNotes?: boolean;
+ pitchBlack?: boolean;
+ reduceAnimations?: boolean;
+ rateApp?: boolean | number;
+ migrated?: boolean;
+ introCompleted?: boolean;
+ nextBackupRequestTime?: number | undefined;
+ lastBackupDate?: number | undefined;
+ userEmailConfirmed?: boolean;
+ recoveryKeySaved?: boolean;
+ theme: {
+ accent: string;
+ dark: boolean;
+ };
+ backupDirectoryAndroid?: FileType | null;
+ showBackupCompleteSheet: boolean;
+ lastRecoveryEmailTime?: number;
+ lastVerificationEmailTime?: number;
+ sessionExpired: boolean;
+ version: number | null;
+};
+
+type Dimensions = {
+ width: number;
+ height: number;
+};
+
+export interface SettingStore extends State {
+ settings: Settings;
+ fullscreen: boolean;
+ deviceMode: string | null;
+ dimensions: Dimensions;
+ setSettings: (settings: Settings) => void;
+ setFullscreen: (fullscreen: boolean) => void;
+ setDeviceMode: (mode: string) => void;
+ setDimensions: (dimensions: Dimensions) => void;
+ appLoading: boolean;
+ setAppLoading: (appLoading: boolean) => void;
+ setSheetKeyboardHandler: (sheetKeyboardHandler: boolean) => void;
+ sheetKeyboardHandler: boolean;
+ requestBiometrics: boolean;
+ setRequestBiometrics: (requestBiometrics: boolean) => void;
+}
+
+let { width, height } = Dimensions.get('window');
+
+export const useSettingStore = create<SettingStore>((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',
+ telemetry: true,
+ notebooksListMode: 'normal',
+ notesListMode: 'normal',
+ devMode: false,
+ notifNotes: false,
+ pitchBlack: false,
+ reduceAnimations: false,
+ rateApp: false,
+ migrated: false,
+ introCompleted: false,
+ nextBackupRequestTime: undefined,
+ lastBackupDate: undefined,
+ userEmailConfirmed: false,
+ recoveryKeySaved: false,
+ theme: {
+ accent: ACCENT.color,
+ dark: false
+ },
+ showBackupCompleteSheet: true,
+ sessionExpired: false,
+ version: null
+ },
+ sheetKeyboardHandler: true,
+ fullscreen: false,
+ deviceMode: 'mobile',
+ dimensions: { width, height },
+ appLoading: true,
+ setSettings: settings => set({ settings }),
+ setFullscreen: fullscreen => set({ fullscreen }),
+ setDeviceMode: mode => set({ deviceMode: mode }),
+ setDimensions: dimensions => set({ dimensions: dimensions }),
+ setAppLoading: appLoading => set({ appLoading }),
+ setSheetKeyboardHandler: sheetKeyboardHandler => set({ sheetKeyboardHandler }),
+ requestBiometrics: false,
+ setRequestBiometrics: requestBiometrics => set({ requestBiometrics })
+}));
diff --git a/apps/mobile/src/stores/useTagStore.ts b/apps/mobile/src/stores/useTagStore.ts
new file mode 100644
index 000000000..42b02bc44
--- /dev/null
+++ b/apps/mobile/src/stores/useTagStore.ts
@@ -0,0 +1,34 @@
+//@ts-ignore
+import 'notes-core/types';
+import { groupArray } from 'notes-core/utils/grouping';
+import create, { State } from 'zustand';
+import { db } from '../utils/database';
+import { TagType } from '../utils/types';
+
+export interface TagStore extends State {
+ tags: TagType[];
+ setTags: (items?: TagType[]) => void;
+ clearTags: () => void;
+}
+
+export const useTagStore = create<TagStore>((set, get) => ({
+ tags: [],
+ setTags: items => {
+ if (!items) {
+ set({
+ tags: groupArray((db?.tags?.all as TagType[]) || [], db.settings?.getGroupOptions('tags'))
+ });
+ return;
+ }
+ let prev = get().tags;
+ for (let 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: [] })
+}));
diff --git a/apps/mobile/src/stores/theme.ts b/apps/mobile/src/stores/useThemeStore.ts
similarity index 100%
rename from apps/mobile/src/stores/theme.ts
rename to apps/mobile/src/stores/useThemeStore.ts
diff --git a/apps/mobile/src/stores/useTrashStore.ts b/apps/mobile/src/stores/useTrashStore.ts
new file mode 100644
index 000000000..7c31e118b
--- /dev/null
+++ b/apps/mobile/src/stores/useTrashStore.ts
@@ -0,0 +1,33 @@
+//@ts-ignore
+import { groupArray } from 'notes-core/utils/grouping';
+import create, { State } from 'zustand';
+import { db } from '../utils/database';
+import { NotebookType, NoteType } from '../utils/types';
+
+export interface TrashStore extends State {
+ trash: Array<NoteType | NotebookType>;
+ setTrash: (items?: Array<NoteType | NotebookType>) => void;
+ clearTrash: () => void;
+}
+
+export const useTrashStore = create<TrashStore>((set, get) => ({
+ trash: [],
+ setTrash: items => {
+ if (!items) {
+ set({
+ trash: groupArray(db?.trash?.all || [], db.settings?.getGroupOptions('trash'))
+ });
+ return;
+ }
+ let prev = get().trash;
+ for (let 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: [] })
+}));
diff --git a/apps/mobile/src/stores/useUserStore.ts b/apps/mobile/src/stores/useUserStore.ts
new file mode 100644
index 000000000..43b3ba11a
--- /dev/null
+++ b/apps/mobile/src/stores/useUserStore.ts
@@ -0,0 +1,28 @@
+//@ts-ignore
+import create, { State } from 'zustand';
+
+export interface UserStore extends State {
+ user: User | null | undefined;
+ premium: boolean;
+ lastSynced: string;
+ syncing: boolean;
+ setUser: (user: User | null | undefined) => void;
+ setPremium: (premium: boolean) => void;
+ setSyncing: (syncing: boolean) => void;
+ setLastSynced: (lastSynced: string) => void;
+ verifyUser: boolean;
+ setVerifyUser: (verified: boolean) => void;
+}
+
+export const useUserStore = create<UserStore>((set, get) => ({
+ user: null,
+ premium: false,
+ lastSynced: 'Never',
+ syncing: false,
+ verifyUser: false,
+ setUser: user => set({ user: user }),
+ setPremium: premium => set({ premium: premium }),
+ setSyncing: syncing => set({ syncing: syncing }),
+ setLastSynced: lastSynced => set({ lastSynced: lastSynced }),
+ setVerifyUser: verified => set({ verifyUser: verified })
+}));
diff --git a/apps/mobile/src/utils/analytics/index.js b/apps/mobile/src/utils/analytics/index.js
index 47fe215a4..7fa40c8c2 100644
--- a/apps/mobile/src/utils/analytics/index.js
+++ b/apps/mobile/src/utils/analytics/index.js
@@ -1,6 +1,6 @@
import { Platform } from 'react-native';
import { MMKV } from '../database/mmkv';
-import { useSettingStore } from '../../stores/stores';
+import { useSettingStore } from '../../stores/use-setting-store';
const WEBSITE_ID = `3c6890ce-8410-49d5-8831-15fb2eb28a21`;
const baseUrl = `https://analytics.streetwriters.co/api/collect`;
diff --git a/apps/mobile/src/utils/colorscheme/index.js b/apps/mobile/src/utils/colorscheme/index.js
index 038961190..88b2b4efe 100644
--- a/apps/mobile/src/utils/colorscheme/index.js
+++ b/apps/mobile/src/utils/colorscheme/index.js
@@ -1,7 +1,7 @@
import { Platform, StatusBar } from 'react-native';
import { AndroidModule } from '..';
import { eSendEvent } from '../../services/event-manager';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eThemeUpdated } from '../events';
export const ACCENT = {
diff --git a/apps/mobile/src/utils/constants.js b/apps/mobile/src/utils/constants.js
index 05d06c40b..f7f08b4c2 100644
--- a/apps/mobile/src/utils/constants.js
+++ b/apps/mobile/src/utils/constants.js
@@ -1,4 +1,5 @@
import { Platform } from 'react-native';
+import { Monographs } from '../screens/notes/monographs';
import { eSendEvent } from '../services/event-manager';
import Navigation from '../services/navigation';
import { refreshNotesPage } from './events';
@@ -105,20 +106,7 @@ export const MenuItemsList = [
icon: 'text-box-multiple-outline',
close: true,
func: () => {
- let params = {
- type: 'notes',
- menu: true,
- get: 'monographs',
- title: 'Monographs',
- id: 'monographs_navigation'
- };
-
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: 'Monographs',
- id: 'monographs_navigation',
- type: 'notes'
- });
+ Monographs.navigate();
}
},
{
diff --git a/apps/mobile/src/utils/database/Storage.js b/apps/mobile/src/utils/database/Storage.js
index e3fb17a95..f6898e1e9 100644
--- a/apps/mobile/src/utils/database/Storage.js
+++ b/apps/mobile/src/utils/database/Storage.js
@@ -16,10 +16,10 @@ import { MMKV } from './mmkv';
async function read(key) {
if (!key) return null;
let data = MMKV.getString(key);
-
if (!data) return null;
try {
- return JSON.parse(data);
+ let parse = JSON.parse(data);
+ return parse;
} catch (e) {
return data;
}
diff --git a/apps/mobile/src/utils/filesystem/download.js b/apps/mobile/src/utils/filesystem/download.js
index 2a077a469..81baf8bf7 100644
--- a/apps/mobile/src/utils/filesystem/download.js
+++ b/apps/mobile/src/utils/filesystem/download.js
@@ -4,7 +4,7 @@ import * as ScopedStorage from 'react-native-scoped-storage';
import Sodium from 'react-native-sodium';
import RNFetchBlob from 'rn-fetch-blob';
import { ShareComponent } from '../../components/sheets/export-notes/share';
-import { useAttachmentStore } from '../../stores/stores';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
import { presentSheet, ToastEvent } from '../../services/event-manager';
import { db } from '../database';
import Storage from '../database/storage';
diff --git a/apps/mobile/src/utils/filesystem/upload.js b/apps/mobile/src/utils/filesystem/upload.js
index 19a988b24..5daa27527 100644
--- a/apps/mobile/src/utils/filesystem/upload.js
+++ b/apps/mobile/src/utils/filesystem/upload.js
@@ -1,5 +1,5 @@
import RNFetchBlob from 'rn-fetch-blob';
-import { useAttachmentStore } from '../../stores/stores';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
import { db } from '../database';
import { cacheDir } from './utils';
diff --git a/apps/mobile/src/utils/functions.js b/apps/mobile/src/utils/functions.js
index 00499899f..1aaea5028 100644
--- a/apps/mobile/src/utils/functions.js
+++ b/apps/mobile/src/utils/functions.js
@@ -3,7 +3,8 @@ import { history } from '.';
import { eSendEvent, ToastEvent } from '../services/event-manager';
import Navigation from '../services/navigation';
import SearchService from '../services/search';
-import { useMenuStore, useSelectionStore } from '../stores/stores';
+import { useSelectionStore } from '../stores/use-selection-store';
+import { useMenuStore } from '../stores/use-menu-store';
import { db } from './database';
import { eClearEditor } from './events';
@@ -44,7 +45,7 @@ export const deleteItems = async item => {
await db.notes.delete(...ids);
- Navigation.setRoutesToUpdate([Navigation.routeNames.Notes, Navigation.routeNames.NotesPage]);
+ Navigation.queueRoutesForUpdate([Navigation.routeNames.Notes, Navigation.routeNames.NotesPage]);
eSendEvent(eClearEditor);
}
if (topics?.length > 0) {
@@ -54,7 +55,10 @@ export const deleteItems = async item => {
}
// layoutmanager.withAnimation(150);
- Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks, Navigation.routeNames.Notebook]);
+ Navigation.queueRoutesForUpdate([
+ Navigation.routeNames.Notebooks,
+ Navigation.routeNames.Notebook
+ ]);
useMenuStore.getState().setMenuPins();
ToastEvent.show({
heading: 'Topics deleted',
@@ -67,7 +71,7 @@ export const deleteItems = async item => {
await db.notebooks.delete(...ids);
//layoutmanager.withAnimation(150);
- Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks, Navigation.routeNames.Notes]);
+ Navigation.queueRoutesForUpdate([Navigation.routeNames.Notebooks, Navigation.routeNames.Notes]);
useMenuStore.getState().setMenuPins();
}
@@ -90,7 +94,7 @@ export const deleteItems = async item => {
await db.trash.restore(...ids);
//layoutmanager.withAnimation(150);
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
Navigation.routeNames.Trash,
@@ -106,7 +110,7 @@ export const deleteItems = async item => {
});
}
history.selectedItemsList = [];
- Navigation.setRoutesToUpdate([Navigation.routeNames.Trash]);
+ Navigation.queueRoutesForUpdate([Navigation.routeNames.Trash]);
useSelectionStore.getState().clearSelection(true);
useMenuStore.getState().setMenuPins();
useMenuStore.getState().setColorNotes();
diff --git a/apps/mobile/src/utils/globalrefs.ts b/apps/mobile/src/utils/globalrefs.ts
index dac522ce4..c4eb99622 100644
--- a/apps/mobile/src/utils/globalrefs.ts
+++ b/apps/mobile/src/utils/globalrefs.ts
@@ -1,9 +1,9 @@
import { createNavigationContainerRef } from '@react-navigation/native';
import { createRef } from 'react';
import { TextInput, View } from 'react-native';
-import Tabs from '../components/tabs';
+import { TabsRef } from '../components/tabs/new';
export const inputRef = createRef<TextInput>();
export const rootNavigatorRef = createNavigationContainerRef();
-export const tabBarRef = createRef<Tabs>();
+export const tabBarRef = createRef<TabsRef>();
export const editorRef = createRef<View>();
diff --git a/apps/mobile/src/utils/hooks/useActions.js b/apps/mobile/src/utils/hooks/useActions.js
index 142d00e0d..5b5232695 100644
--- a/apps/mobile/src/utils/hooks/useActions.js
+++ b/apps/mobile/src/utils/hooks/useActions.js
@@ -19,14 +19,12 @@ import {
} from '../../services/event-manager';
import Navigation from '../../services/navigation';
import Notifications from '../../services/notifications';
-import {
- useEditorStore,
- useMenuStore,
- useSelectionStore,
- useTagStore,
- useUserStore
-} from '../../stores/stores';
-import { useThemeStore } from '../../stores/theme';
+import { useSelectionStore } from '../../stores/use-selection-store';
+import { useUserStore } from '../../stores/use-user-store';
+import { useMenuStore } from '../../stores/use-menu-store';
+import { useEditorStore } from '../../stores/use-editor-store';
+import { useTagStore } from '../../stores/use-tag-store';
+import { useThemeStore } from '../../stores/use-theme-store';
import { toggleDarkMode } from '../color-scheme/utils';
import { db } from '../database';
import {
@@ -125,7 +123,7 @@ export const useActions = ({ close = () => {}, item }) => {
if (!item.id) return;
close();
await db.notes.note(item.id).favorite();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes
@@ -144,7 +142,7 @@ export const useActions = ({ close = () => {}, item }) => {
return;
}
await db[`${type}s`][type](item.id).pin();
- Navigation.setRoutesToUpdate([Navigation.routeNames.Notebooks, Navigation.routeNames.Notes]);
+ Navigation.queueRoutesForUpdate([Navigation.routeNames.Notebooks, Navigation.routeNames.Notes]);
}
async function pinToNotifications() {
@@ -180,7 +178,7 @@ export const useActions = ({ close = () => {}, item }) => {
if (!checkNoteSynced()) return;
close();
await db.trash.restore(item.id);
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Tags,
Navigation.routeNames.Notes,
Navigation.routeNames.Notebooks,
@@ -301,7 +299,7 @@ export const useActions = ({ close = () => {}, item }) => {
let note = db.notes.note(item.id).data;
if (note.locked) {
close();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes
@@ -363,7 +361,7 @@ export const useActions = ({ close = () => {}, item }) => {
await db.tags.rename(item.id, db.tags.sanitize(value));
useTagStore.getState().setTags();
useMenuStore.getState().setMenuPins();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Tags
@@ -409,7 +407,7 @@ export const useActions = ({ close = () => {}, item }) => {
positivePress: async value => {
await db.tags.remove(item.id);
useTagStore.getState().setTags();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
Navigation.routeNames.Tags
@@ -443,7 +441,7 @@ export const useActions = ({ close = () => {}, item }) => {
.notebook(editing.actionAfterFirstSave.notebook)
.topics.topic(editing.actionAfterFirstSave.id)
.delete(item.id);
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.Notebooks,
Navigation.routeNames.Notes,
Navigation.routeNames.NotesPage,
@@ -463,7 +461,7 @@ export const useActions = ({ close = () => {}, item }) => {
negativeText: 'Cancel',
positivePress: async () => {
await db.trash.delete(item.id);
- Navigation.setRoutesToUpdate([Navigation.routeNames.Trash]);
+ Navigation.queueRoutesForUpdate([Navigation.routeNames.Trash]);
useSelectionStore.getState().setSelectionMode(false);
ToastEvent.show({
heading: 'Permanantly deleted items',
@@ -498,7 +496,7 @@ export const useActions = ({ close = () => {}, item }) => {
async function toggleLocalOnly() {
if (!checkNoteSynced()) return;
db.notes.note(item.id).localOnly();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes
@@ -513,7 +511,7 @@ export const useActions = ({ close = () => {}, item }) => {
useEditorStore.getState().setReadonly(current);
tiny.call(EditorWebView, tiny.toogleReadMode(current ? 'readonly' : 'design'));
}
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes
@@ -524,7 +522,7 @@ export const useActions = ({ close = () => {}, item }) => {
const duplicateNote = async () => {
if (!checkNoteSynced()) return;
await db.notes.note(item.id).duplicate();
- Navigation.setRoutesToUpdate([
+ Navigation.queueRoutesForUpdate([
Navigation.routeNames.NotesPage,
Navigation.routeNames.Favorites,
Navigation.routeNames.Notes
diff --git a/apps/mobile/src/utils/hooks/useAppEvents.js b/apps/mobile/src/utils/hooks/useAppEvents.js
index 86fca2aec..2e35dd37c 100644
--- a/apps/mobile/src/utils/hooks/useAppEvents.js
+++ b/apps/mobile/src/utils/hooks/useAppEvents.js
@@ -20,7 +20,6 @@ import {
updateNoteInEditor
} from '../../screens/editor/Functions';
import tiny from '../../screens/editor/tiny/tiny';
-import Backup from '../../services/backup';
import BiometricService from '../../services/biometrics';
import {
eSendEvent,
@@ -38,15 +37,12 @@ import {
import PremiumService from '../../services/premium';
import SettingsService from '../../services/settings';
import Sync from '../../services/sync';
-import {
- clearAllStores,
- initialize,
- useAttachmentStore,
- useMessageStore,
- useNoteStore,
- useSettingStore,
- useUserStore
-} from '../../stores/stores';
+import { clearAllStores, initialize } from '../../stores';
+import { useUserStore } from '../../stores/use-user-store';
+import { useMessageStore } from '../../stores/use-message-store';
+import { useSettingStore } from '../../stores/use-setting-store';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
+import { useNoteStore } from '../../stores/use-notes-store';
import { updateStatusBarColor } from '../color-scheme';
import { db } from '../database';
import { MMKV } from '../database/mmkv';
@@ -54,7 +50,6 @@ import { eClearEditor, eCloseProgressDialog, eOpenLoginDialog, refreshNotesPage
import { sleep } from '../time';
const SodiumEventEmitter = new NativeEventEmitter(NativeModules.Sodium);
-
export const useAppEvents = () => {
const loading = useNoteStore(state => state.loading);
const setLastSynced = useUserStore(state => state.setLastSynced);
@@ -104,12 +99,14 @@ export const useAppEvents = () => {
if (!loading) {
const eventManager = db?.eventManager;
eventManager?.subscribe(EVENTS.syncProgress, onSyncProgress);
- eventManager?.subscribe(EVENTS.databaseSyncRequested, onRequestPartialSync);
+ let sub = eventManager?.subscribe(EVENTS.databaseSyncRequested, onRequestPartialSync);
eventManager?.subscribe(EVENTS.syncCompleted, onSyncComplete);
+ console.log('SUBSCRIBED', sub);
}
return () => {
const eventManager = db?.eventManager;
+ console.log('UNSUBSCRIBED');
eventManager?.unsubscribe(EVENTS.syncCompleted, onSyncComplete);
eventManager?.unsubscribe(EVENTS.syncProgress, onSyncProgress);
eventManager?.unsubscribe(EVENTS.databaseSyncRequested, onRequestPartialSync);
@@ -254,31 +251,7 @@ export const useAppEvents = () => {
};
const onLogout = async reason => {
- setUser(null);
- clearAllStores();
-
- SettingsService.init();
- setSyncing(false);
- setLoginMessage();
- await PremiumService.setPremiumStatus();
- SettingsService.set({
- introCompleted: true
- });
- presentSheet({
- title: reason ? reason : 'User logged out',
- paragraph: `You have been logged out of your account.`,
- action: async () => {
- eSendEvent(eCloseProgressDialog);
- await sleep(300);
- eSendEvent(eOpenLoginDialog);
- },
- icon: 'logout',
- actionText: 'Login'
- });
-
- setTimeout(() => {
- initialize();
- }, 1000);
+ console.log('LOGOUT', reason);
};
const unsubIAP = () => {
diff --git a/apps/mobile/src/utils/hooks/useAttachmentProgress.js b/apps/mobile/src/utils/hooks/useAttachmentProgress.js
index 8ce8a0acf..9b985afe9 100644
--- a/apps/mobile/src/utils/hooks/useAttachmentProgress.js
+++ b/apps/mobile/src/utils/hooks/useAttachmentProgress.js
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
-import { useAttachmentStore } from '../../stores/stores';
+import { useAttachmentStore } from '../../stores/use-attachment-store';
export const useAttachmentProgress = (attachment, encryption) => {
const progress = useAttachmentStore(state => state.progress);
diff --git a/apps/mobile/src/utils/hooks/useEditorTags.ts b/apps/mobile/src/utils/hooks/useEditorTags.ts
index 85b82c4b2..fed67de1f 100644
--- a/apps/mobile/src/utils/hooks/useEditorTags.ts
+++ b/apps/mobile/src/utils/hooks/useEditorTags.ts
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
-import { useEditorStore, useTagStore } from '../../stores/stores';
+import { useEditorStore } from '../../stores/use-editor-store';
+import { useTagStore } from '../../stores/use-tag-store';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { db } from '../database';
import { EditorWebView } from '../../screens/editor/Functions';
diff --git a/apps/mobile/src/utils/hooks/useImmediate.ts b/apps/mobile/src/utils/hooks/useImmediate.ts
new file mode 100644
index 000000000..183328166
--- /dev/null
+++ b/apps/mobile/src/utils/hooks/useImmediate.ts
@@ -0,0 +1,13 @@
+import { DependencyList, EffectCallback, useEffect } from 'react';
+
+const useImmediateEffect = (callback: EffectCallback, deps: DependencyList) => {
+ useEffect(() => {
+ let cleanup;
+ setImmediate(() => {
+ cleanup = callback();
+ });
+ return cleanup;
+ }, deps);
+};
+
+export default useImmediateEffect;
diff --git a/apps/mobile/src/utils/hooks/useNavigationFocus.ts b/apps/mobile/src/utils/hooks/useNavigationFocus.ts
new file mode 100644
index 000000000..6a5333f41
--- /dev/null
+++ b/apps/mobile/src/utils/hooks/useNavigationFocus.ts
@@ -0,0 +1,53 @@
+import { NativeStackNavigationProp } from '@react-navigation/native-stack';
+import { RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react';
+import SettingsService from '../../services/settings';
+import useNavigationStore from '../../stores/use-navigation-store';
+
+type NavigationFocus = {
+ onFocus?: (prev: RefObject<boolean>) => boolean;
+ onBlur?: (prev: RefObject<boolean>) => boolean;
+ delay?: number;
+ focusOnInit?: boolean;
+};
+
+export const useNavigationFocus = (
+ navigation: NativeStackNavigationProp<any>,
+ { onFocus, onBlur, delay, focusOnInit }: NavigationFocus
+) => {
+ const [isFocused, setFocused] = useState(focusOnInit);
+ const prev = useRef(false);
+
+ const _onFocus = useCallback(() => {
+ setTimeout(() => {
+ console.log('on focus', prev);
+ let shouldFocus = onFocus ? onFocus(prev) : true;
+ if (shouldFocus) {
+ setFocused(true);
+ prev.current = true;
+ }
+ }, delay || 300);
+ }, [onFocus, prev]);
+
+ const _onBlur = useCallback(() => {
+ setTimeout(() => {
+ let shouldBlur = onBlur ? onBlur(prev) : true;
+ if (shouldBlur) {
+ prev.current = false;
+ setFocused(false);
+ }
+ }, delay || 300);
+ }, [onBlur, prev]);
+
+ useEffect(() => {
+ if (!navigation) return;
+ const subs = [
+ navigation.addListener('focus', _onFocus),
+ navigation.addListener('blur', _onBlur)
+ ];
+ return () => {
+ subs.forEach(sub => sub());
+ };
+ }, [navigation]);
+
+ return isFocused;
+};
diff --git a/apps/mobile/src/utils/hooks/useTooltip.ts b/apps/mobile/src/utils/hooks/useTooltip.ts
index 06350a2f5..0cbff13e1 100644
--- a/apps/mobile/src/utils/hooks/useTooltip.ts
+++ b/apps/mobile/src/utils/hooks/useTooltip.ts
@@ -2,7 +2,7 @@ import { RefObject, useEffect, useRef } from 'react';
import { Platform } from 'react-native';
//@ts-ignore
import RNTooltips from 'react-native-tooltips';
-import { useThemeStore } from '../../stores/theme';
+import { useThemeStore } from '../../stores/use-theme-store';
import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/event-manager';
import { Popup } from '../../services/tip-manager';
import useKeyboard from './use-keyboard';
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index d4c4ff178..b14361442 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -1,8 +1,6 @@
-import { Dimensions, NativeModules, Platform } from 'react-native';
-import BackgroundService from 'react-native-background-actions';
+import { AppState, Dimensions, NativeModules, Platform } from 'react-native';
import { beginBackgroundTask, endBackgroundTask } from 'react-native-begin-background-task';
import RNTooltips from 'react-native-tooltips';
-import { bgTaskOptions } from './constants';
import { db } from './database';
import { tabBarRef } from './global-refs';
@@ -93,11 +91,9 @@ export async function doInBackground(cb) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (res, rej) => {
try {
- await BackgroundService.start(async () => {
- let result = await cb();
- await BackgroundService.stop();
- res(result);
- }, bgTaskOptions);
+ console.log('APP STATE AT SYNC: ', AppState.currentState);
+ let result = await cb();
+ res(result);
} catch (e) {
res(e.message);
}
diff --git a/apps/mobile/src/utils/types.ts b/apps/mobile/src/utils/types.ts
new file mode 100644
index 000000000..2355c9ff5
--- /dev/null
+++ b/apps/mobile/src/utils/types.ts
@@ -0,0 +1,132 @@
+// eslint-disable-next-line @typescript-eslint/ban-types
+export type LiteralUnion<T extends U, U = string> = T | (U & {});
+
+// types from notesnook-core
+export type CollectionTypes = 'notes' | 'notebooks' | 'attachments' | 'content' | 'tags' | 'colors';
+export type EntityTypes =
+ | 'note'
+ | 'notebook'
+ | 'tiny'
+ | 'topic'
+ | 'attachment'
+ | 'settings'
+ | 'trash'
+ | 'tag'
+ | 'color'
+ | 'header';
+
+export type CollectionEntityTypeMap = {
+ notes: 'note';
+ notebooks: 'notebook';
+ attachments: 'attachment';
+ content: 'tiny';
+ tags: 'tag';
+ colors: 'color';
+};
+
+export type Item = NoteType | NotebookType | TopicType | AttachmentType | TagType | TrashType;
+
+export type MonographType = {
+ type: 'monograph';
+};
+
+export interface Entity<TType extends EntityTypes> {
+ id: string;
+ type: TType;
+ dateModified: number;
+ dateCreated: number;
+
+ // flags
+ migrated?: boolean;
+ remote?: boolean;
+ deleted?: boolean;
+}
+
+export type NotebookReference = {
+ id: string;
+ topics: string[];
+};
+
+export interface NoteType extends Entity<'note'> {
+ title: string;
+ notebooks: NotebookReference[];
+ tags: string[];
+ dateCreated: number;
+ dateEdited: number;
+
+ pinned: boolean;
+ locked: boolean;
+ favorite: boolean;
+ localOnly: boolean;
+ conflicted: boolean;
+ readonly: boolean;
+
+ contentId?: string;
+ headline?: string;
+ color?: string;
+}
+
+export interface NotebookType extends Entity<'notebook'> {
+ title: string;
+ description?: string;
+ dateCreated: number;
+ dateEdited: number;
+ pinned: boolean;
+ topics: TopicType[];
+}
+
+export interface TopicType extends Entity<'topic'> {
+ title: string;
+ notebookId: string;
+ notes: string[];
+ dateCreated: number;
+ dateEdited: number;
+}
+
+export interface AttachmentType extends Entity<'attachment'> {
+ noteIds: string[];
+ iv: string;
+ salt: string;
+ length: number;
+ alg: string; // TODO
+ chunkSize: number;
+ key: {
+ iv: string;
+ salt: string;
+ length: number;
+ cipher: string;
+ alg: string; // TODO
+ };
+ metadata: {
+ hash: string;
+ hashType: string; // TODO
+ filename: string;
+ type: string;
+ };
+ dateCreated: number;
+ dateEdited: number;
+ dateUploaded: number;
+ dateDeleted: number;
+}
+
+interface BaseTag<TType extends 'tag' | 'color'> extends Entity<TType> {
+ title: string;
+ alias?: string;
+ noteIds: string[];
+}
+
+export type TagType = BaseTag<'tag'>;
+export type ColorType = BaseTag<'color'>;
+
+type TrashItem<TItem extends Entity<'note' | 'notebook'>> = Entity<'trash'> & {
+ title: string;
+ itemType: TItem['type'];
+ dateDeleted: number;
+ deleted: boolean;
+} & Omit<TItem, 'id' | 'type'>;
+
+type TrashType = TrashItem<NoteType> | TrashItem<NotebookType>;
+
+export interface GroupHeader extends Omit<Entity<'header'>, 'id' | 'dateCreated' | 'dateModified'> {
+ title: string;
+}