From 4e9d71a969308cb8ec588a08b10c42c7e80dd244 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 13 Oct 2020 17:02:14 +0500 Subject: [PATCH] cleanup and refactor --- apps/mobile/.detoxrc.json | 5 +- apps/mobile/App.js | 389 +++++++++--------- apps/mobile/e2e/firstTest.e2e.js | 21 +- apps/mobile/index.mobile.js | 4 +- apps/mobile/index.tablet.js | 9 +- apps/mobile/loading.js | 8 +- apps/mobile/src/common/common.js | 249 ----------- .../mobile/src/components/ActionIcon/index.js | 3 +- .../src/components/ActionSheet/index.js | 4 +- .../src/components/ActionSheet/styles.js | 4 +- .../components/ActionSheetComponent/index.js | 72 ++-- .../src/components/AddNotebookDialog/index.js | 12 +- .../src/components/AddTopicDialog/index.js | 10 +- apps/mobile/src/components/Button/index.js | 2 +- .../Container/ContainerBottomButton.js | 5 +- .../Container/ContainerTopSection.js | 5 +- .../src/components/ContextMenu/index.js | 6 +- .../src/components/Dialog/DialogHeader.js | 2 +- apps/mobile/src/components/Dialog/index.js | 42 +- .../{dialogActions.js => DialogActions.js} | 0 .../{recievers.js => Recievers.js} | 4 +- .../{templates.js => Templates.js} | 4 +- .../src/components/DialogManager/index.js | 9 +- .../src/components/ExportDialog/index.js | 11 +- .../{header => Header}/HeaderMenu.js | 14 +- .../{header => Header}/HeaderTitle.js | 2 +- .../components/{header => Header}/index.js | 51 +-- apps/mobile/src/components/Loading/index.js | 2 +- .../src/components/LoginDialog/index.js | 30 +- .../src/components/Menu/ColorSection.js | 19 +- .../src/components/Menu/MenuListItem.js | 15 +- .../mobile/src/components/Menu/TagsSection.js | 18 +- apps/mobile/src/components/Menu/TimeSince.js | 2 +- .../mobile/src/components/Menu/UserSection.js | 24 +- apps/mobile/src/components/Menu/index.js | 24 +- .../src/components/MergeEditor/index.js | 27 +- .../src/components/MoveNoteDialog/index.js | 26 +- apps/mobile/src/components/NoteItem/index.js | 4 +- .../src/components/NotebookItem/index.js | 4 +- .../src/components/Premium/PendingDialog.js | 12 +- .../src/components/Premium/PremiumDialog.js | 14 +- .../components/Premium/PremiumStatusDialog.js | 9 +- .../src/components/Premium/PremiumTag.js | 2 +- .../src/components/PressableButton/index.js | 4 +- .../src/components/ProgressDialog/index.js | 9 +- .../src/components/RecoveryKeyDialog/index.js | 15 +- .../src/components/RestoreDialog/index.js | 62 +-- .../src/components/SearchInput/index.js | 18 +- .../src/components/SelectionHeader/index.js | 26 +- .../src/components/SelectionWrapper/index.js | 24 +- .../components/SimpleList/NoteItemWrapper.js | 17 +- .../SimpleList/NotebookItemWrapper.js | 14 +- .../mobile/src/components/SimpleList/index.js | 19 +- apps/mobile/src/components/Toast/index.js | 10 +- .../src/components/VaultDialog/index.js | 26 +- apps/mobile/src/navigation/Drawer.js | 68 +++ apps/mobile/src/navigation/NavigatorStack.js | 54 +++ .../src/provider/{actions.js => Actions.js} | 2 +- .../{defaultState.js => DefaultState.js} | 0 .../src/provider/{reducer.js => Reducer.js} | 65 +-- apps/mobile/src/provider/index.js | 4 +- apps/mobile/src/provider/useAppContext.js | 77 ---- .../DeviceDetection.js} | 40 +- apps/mobile/src/services/EventManager.js | 70 ++++ apps/mobile/src/services/Exporter.js | 94 +++++ .../{NavigationService.js => Navigation.js} | 2 +- apps/mobile/src/services/Navigator.js | 113 ----- .../services/{validation.js => Validation.js} | 2 +- apps/mobile/src/services/eventManager.js | 34 -- .../utils/{animations.js => Animations.js} | 2 +- apps/mobile/src/utils/ColorUtils.js | 121 ++++++ apps/mobile/src/utils/Colors.js | 76 ++++ apps/mobile/src/utils/DB.js | 12 + .../{services/events.js => utils/Events.js} | 2 + apps/mobile/src/utils/{hooks.js => Hooks.js} | 4 +- apps/mobile/src/utils/MMKV.js | 3 + apps/mobile/src/utils/{refs.js => Refs.js} | 0 apps/mobile/src/utils/SizeUtils.js | 94 +++++ apps/mobile/src/utils/Storage.js | 128 ++++++ apps/mobile/src/utils/TimeUtils.js | 86 ++++ apps/mobile/src/utils/index.js | 58 +++ apps/mobile/src/utils/storage.js | 204 --------- apps/mobile/src/utils/utils.js | 381 ----------------- apps/mobile/src/views/Editor/Functions.js | 315 ++++++++++++++ apps/mobile/src/views/Editor/func.js | 311 -------------- apps/mobile/src/views/Editor/index.js | 15 +- apps/mobile/src/views/Favorites/index.js | 16 +- apps/mobile/src/views/Folders/index.js | 18 +- apps/mobile/src/views/ForgotPassword/index.js | 125 ------ apps/mobile/src/views/Home/index.js | 28 +- apps/mobile/src/views/Home/styles.js | 3 +- apps/mobile/src/views/Notebook/index.js | 26 +- apps/mobile/src/views/Notes/index.js | 24 +- apps/mobile/src/views/Settings/index.js | 121 +++--- apps/mobile/src/views/Tags/index.js | 20 +- apps/mobile/src/views/Trash/index.js | 18 +- 96 files changed, 1974 insertions(+), 2285 deletions(-) delete mode 100755 apps/mobile/src/common/common.js rename apps/mobile/src/components/DialogManager/{dialogActions.js => DialogActions.js} (100%) rename apps/mobile/src/components/DialogManager/{recievers.js => Recievers.js} (93%) rename apps/mobile/src/components/DialogManager/{templates.js => Templates.js} (96%) rename apps/mobile/src/components/{header => Header}/HeaderMenu.js (85%) rename apps/mobile/src/components/{header => Header}/HeaderTitle.js (93%) rename apps/mobile/src/components/{header => Header}/index.js (92%) create mode 100644 apps/mobile/src/navigation/Drawer.js create mode 100644 apps/mobile/src/navigation/NavigatorStack.js rename apps/mobile/src/provider/{actions.js => Actions.js} (97%) rename apps/mobile/src/provider/{defaultState.js => DefaultState.js} (100%) rename apps/mobile/src/provider/{reducer.js => Reducer.js} (79%) delete mode 100644 apps/mobile/src/provider/useAppContext.js rename apps/mobile/src/{utils/deviceDetection.js => services/DeviceDetection.js} (75%) create mode 100644 apps/mobile/src/services/EventManager.js create mode 100644 apps/mobile/src/services/Exporter.js rename apps/mobile/src/services/{NavigationService.js => Navigation.js} (90%) delete mode 100644 apps/mobile/src/services/Navigator.js rename apps/mobile/src/services/{validation.js => Validation.js} (95%) delete mode 100644 apps/mobile/src/services/eventManager.js rename apps/mobile/src/utils/{animations.js => Animations.js} (97%) create mode 100644 apps/mobile/src/utils/ColorUtils.js create mode 100644 apps/mobile/src/utils/Colors.js create mode 100644 apps/mobile/src/utils/DB.js rename apps/mobile/src/{services/events.js => utils/Events.js} (98%) rename apps/mobile/src/utils/{hooks.js => Hooks.js} (93%) create mode 100644 apps/mobile/src/utils/MMKV.js rename apps/mobile/src/utils/{refs.js => Refs.js} (100%) create mode 100644 apps/mobile/src/utils/SizeUtils.js create mode 100644 apps/mobile/src/utils/Storage.js create mode 100644 apps/mobile/src/utils/TimeUtils.js create mode 100755 apps/mobile/src/utils/index.js delete mode 100644 apps/mobile/src/utils/storage.js delete mode 100755 apps/mobile/src/utils/utils.js create mode 100644 apps/mobile/src/views/Editor/Functions.js delete mode 100644 apps/mobile/src/views/Editor/func.js diff --git a/apps/mobile/.detoxrc.json b/apps/mobile/.detoxrc.json index b28b04a6c..c68274276 100644 --- a/apps/mobile/.detoxrc.json +++ b/apps/mobile/.detoxrc.json @@ -3,10 +3,11 @@ "runnerConfig": "e2e/config.json", "configurations": { "ios": { + "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Notesnook.app", + "build": "xcodebuild -workspace ios/Notesnook.xcworkspace -scheme Notesnook -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build", "type": "ios.simulator", - "binaryPath": "SPECIFY_PATH_TO_YOUR_APP_BINARY", "device": { - "type": "iPhone 11" + "type": "iPhone 11 Pro" } }, "android.emu.debug": { diff --git a/apps/mobile/App.js b/apps/mobile/App.js index b3b9fa80d..4e52d8a12 100644 --- a/apps/mobile/App.js +++ b/apps/mobile/App.js @@ -1,232 +1,217 @@ import {useNetInfo} from '@react-native-community/netinfo'; import React, {useEffect, useState} from 'react'; -import {Dimensions, useColorScheme} from 'react-native'; +import {useColorScheme} from 'react-native'; import Orientation from 'react-native-orientation'; import {SafeAreaProvider} from 'react-native-safe-area-context'; -import { - getColorScheme, - getDeviceSize, - scale, - updateSize, -} from './src/common/common'; import {useTracked} from './src/provider'; -import {ACTIONS} from './src/provider/actions'; -import {defaultState} from './src/provider/defaultState'; -import { - eSendEvent, - eSubscribeEvent, - eUnSubscribeEvent, -} from './src/services/eventManager'; -import { - eDispatchAction, - eOnLoadNote, - eResetApp, - eStartSyncer, -} from './src/services/events'; -import {MMKV} from './src/utils/storage'; -import {db, DDS, sleep, ToastEvent} from './src/utils/utils'; +import {Actions} from './src/provider/Actions'; +import {defaultState} from './src/provider/DefaultState'; +import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent, ToastEvent,} from './src/services/EventManager'; +import {eDispatchAction, eOnLoadNote, eResetApp, eStartSyncer,} from './src/utils/Events'; import DeviceInfo from 'react-native-device-info'; -import {getNote} from './src/views/Editor/func'; -import {openEditorAnimation} from './src/utils/animations'; +import {getNote} from './src/views/Editor/Functions'; +import {openEditorAnimation} from './src/utils/Animations'; +import {sleep} from "./src/utils/TimeUtils"; +import {getColorScheme} from "./src/utils/ColorUtils"; +import {getDeviceSize, scale, updateSize} from "./src/utils/SizeUtils"; +import {db} from "./src/utils/DB"; +import {DDS} from "./src/services/DeviceDetection"; +import {MMKV} from "./src/utils/MMKV"; let firstLoad = true; let note = null; const App = () => { - const [, dispatch] = useTracked(); - const [init, setInit] = useState(false); - const netInfo = useNetInfo(); - const colorScheme = useColorScheme(); - let I = - DDS.isTab && !DDS.isSmallTab - ? require('./index.tablet') - : require('./index.mobile'); + const [, dispatch] = useTracked(), [init, setInit] = useState(false), netInfo = useNetInfo(), + colorScheme = useColorScheme(); + let I = + DDS.isTab && !DDS.isSmallTab + ? require('./index.tablet') + : require('./index.mobile'); - const _onOrientationChange = (o) => { - console.log(o, 'orientation'); - let smallTab = DDS.isSmallTab; - DDS.setNewValues(); - DDS.checkSmallTab(o); - if (smallTab === DDS.isSmallTab) { - console.log('nothing changed'); - return; - } - - I = - DDS.isTab && !DDS.isSmallTab - ? require('./index.tablet') - : require('./index.mobile'); - - setTimeout(() => { - resetApp(); - }, 1000); - }; - - useEffect(() => { - updateTheme(); - }, [colorScheme]); - - const updateTheme = async () => { - let settings; - try { - settings = await MMKV.getStringAsync('settings'); - } catch (e) { - console.log(e.message); - } finally { - if (!settings) { - return; - } - settings = JSON.parse(settings); - if (settings.useSystemTheme) { - let newColors = await getColorScheme(settings.useSystemTheme); - dispatch({type: ACTIONS.THEME, colors: newColors}); - } - } - }; - - useEffect(() => { - if (!netInfo.isConnected || !netInfo.isInternetReachable) { - db.user?.get().then((user) => { - if (user) { - ToastEvent.show('No internet connection', 'error'); - } else { + const _onOrientationChange = (o) => { + console.log(o, 'orientation'); + let smallTab = DDS.isSmallTab; + DDS.setNewValues(); + DDS.checkSmallTab(o); + if (smallTab === DDS.isSmallTab) { + console.log('nothing changed'); + return; } - }); - } else { - db.user?.get().then((user) => { - if (user) { - ToastEvent.show('Internet connection restored', 'success'); - } else { - } - }); - } - }, [netInfo]); - const startSyncer = async () => { - try { - let user = await db.user.get(); - if (user) { - db.ev.subscribe('db:refresh', syncChanges); - } - } catch (e) { - console.log(e); - } - }; - const syncChanges = async () => { - dispatch({type: ACTIONS.ALL}); - }; + I = + DDS.isTab && !DDS.isSmallTab + ? require('./index.tablet') + : require('./index.mobile'); - const resetApp = () => { - note = getNote(); - console.log(note, 'NOTE BEFORE RELOAD'); - setInit(false); - Initialize().then(async () => { - setInit(true); - await sleep(300); - console.log(note, 'NOTE ON RELOAD'); - if (note && note.id) { - console.log(note); - eSendEvent(eOnLoadNote, note); - if (DDS.isPhone || DDS.isSmallTab) { - openEditorAnimation(); - } - note = null; - } - }); - }; - - useEffect(() => { - eSubscribeEvent(eStartSyncer, startSyncer); - eSubscribeEvent(eResetApp, resetApp); - Orientation.addOrientationListener(_onOrientationChange); - eSubscribeEvent(eDispatchAction, (type) => { - dispatch(type); - }); - return () => { - db?.ev?.unsubscribe('db:refresh', syncChanges); - eUnSubscribeEvent(eStartSyncer, startSyncer); - eUnSubscribeEvent(eResetApp, resetApp); - eUnSubscribeEvent(eDispatchAction, (type) => { - dispatch(type); - }); - Orientation.removeOrientationListener(_onOrientationChange); + setTimeout(() => { + resetApp(); + }, 1000); }; - }, []); - useEffect(() => { - let error = null; - let user; - Initialize().finally(async () => { - try { - await db.init(); - user = await db.user.get(); - } catch (e) { - error = e; - console.log(e,"ERROR IN DB") - } finally { - if (user) { - dispatch({type: ACTIONS.USER, user: user}); - startSyncer(); + useEffect(() => { + updateTheme().then(r => r); + }, [colorScheme]); + + const updateTheme = async () => { + let settings; + try { + settings = await MMKV.getStringAsync('settings'); + } catch (e) { + console.log(e.message); + } finally { + if (settings) { + settings = JSON.parse(settings); + if (settings.useSystemTheme) { + let newColors = await getColorScheme(settings.useSystemTheme); + dispatch({type: Actions.THEME, colors: newColors}); + } + } } - dispatch({type: ACTIONS.ALL}); + }; - setInit(true); - - if (error) { - setTimeout(() => { - ToastEvent.show(error.message); - }, 500); + useEffect(() => { + if (!netInfo.isConnected || !netInfo.isInternetReachable) { + db.user?.get().then((user) => { + if (user) { + ToastEvent.show('No internet connection', 'error'); + } else { + } + }); + } else { + db.user?.get().then((user) => { + if (user) { + ToastEvent.show('Internet connection restored', 'success'); + } else { + } + }); } - } - }); - }, []); + }, [netInfo]); - async function Initialize(colors = colors) { - let settings; - scale.fontScale = 1; + const syncChanges = async () => { + dispatch({type: Actions.ALL}); + }, resetApp = () => { + note = getNote(); + console.log(note, 'NOTE BEFORE RELOAD'); + setInit(false); + Initialize().then(async () => { + setInit(true); + await sleep(300); + console.log(note, 'NOTE ON RELOAD'); + if (note && note.id) { + console.log(note); + eSendEvent(eOnLoadNote, note); + if (DDS.isPhone || DDS.isSmallTab) { + openEditorAnimation(); + } + note = null; + } + }); + }, startSyncer = async () => { + try { + let user = await db.user.get(); + if (user) { + db.ev.subscribe('db:refresh', syncChanges); + } + } catch (e) { + console.log(e); + } + }; - if (firstLoad) { - if (DeviceInfo.isTablet() && getDeviceSize() > 9) { - Orientation.lockToLandscape(); - _onOrientationChange('LANDSCAPE'); - } else { - Orientation.lockToPortrait(); - } - firstLoad = false; + useEffect(() => { + eSubscribeEvent(eStartSyncer, startSyncer); + eSubscribeEvent(eResetApp, resetApp); + Orientation.addOrientationListener(_onOrientationChange); + eSubscribeEvent(eDispatchAction, (type) => { + dispatch(type); + }); + return () => { + db?.ev?.unsubscribe('db:refresh', syncChanges); + eUnSubscribeEvent(eStartSyncer, startSyncer); + eUnSubscribeEvent(eResetApp, resetApp); + eUnSubscribeEvent(eDispatchAction, (type) => { + dispatch(type); + }); + + Orientation.removeOrientationListener(_onOrientationChange); + }; + }, []); + + useEffect(() => { + let error = null; + let user; + + Initialize().finally(async () => { + try { + await db.init(); + user = await db.user.get(); + } catch (e) { + error = e; + console.log(e, "ERROR IN DB") + } finally { + if (user) { + dispatch({type: Actions.USER, user: user}); + await startSyncer(); + } + dispatch({type: Actions.ALL}); + + setInit(true); + + if (error) { + setTimeout(() => { + ToastEvent.show(error.message); + }, 500); + } + } + }); + }, []); + + async function Initialize() { + let settings; + scale.fontScale = 1; + + if (firstLoad) { + if (DeviceInfo.isTablet() && getDeviceSize() > 9) { + Orientation.lockToLandscape(); + _onOrientationChange('LANDSCAPE'); + } else { + Orientation.lockToPortrait(); + } + firstLoad = false; + } + + try { + settings = await MMKV.getStringAsync('settings'); + settings = JSON.parse(settings); + + if (settings.fontScale) { + scale.fontScale = settings.fontScale; + } + updateSize(); + } catch (e) { + if (!settings || !settings.includes('fontScale')) { + settings = defaultState.settings; + await MMKV.setStringAsync('settings', JSON.stringify(settings)); + } + } finally { + let newColors = await getColorScheme(settings.useSystemTheme); + dispatch({type: Actions.SETTINGS, settings: {...settings}}); + dispatch({type: Actions.THEME, colors: newColors}); + } } - try { - settings = await MMKV.getStringAsync('settings'); - settings = JSON.parse(settings); - - if (settings.fontScale) { - scale.fontScale = settings.fontScale; - } - updateSize(); - } catch (e) { - if (!settings || !settings.includes('fontScale')) { - settings = defaultState.settings; - await MMKV.setStringAsync('settings', JSON.stringify(settings)); - } - } finally { - let newColors = await getColorScheme(settings.useSystemTheme); - dispatch({type: ACTIONS.SETTINGS, settings: {...settings}}); - dispatch({type: ACTIONS.THEME, colors: newColors}); + if (!init) { + return <>; } - } - - if (!init) { - return <>; - } - return ( - <> - + return ( <> - + + <> + + + - - - ); + ); }; export default App; diff --git a/apps/mobile/e2e/firstTest.e2e.js b/apps/mobile/e2e/firstTest.e2e.js index 4d1bf69e3..e27da4644 100644 --- a/apps/mobile/e2e/firstTest.e2e.js +++ b/apps/mobile/e2e/firstTest.e2e.js @@ -8,31 +8,30 @@ it('CHECK APP LOADED', async () => { }); it('CHECK MENU NAVIGATION', async () => { - menu = element(by.id('left_menu_button')); + await expect(element(by.id('left_menu_button'))).toBeVisible(); + +/* await element(by.id('Notebooks')).tap(); menu.tap(); await sleep(200); - element(by.id('Notebooks')).tap(); + await element(by.id('Favorites')).tap(); menu.tap(); await sleep(200); - element(by.id('Favorites')).tap(); + await element(by.id('Trash')).tap(); menu.tap(); await sleep(200); - element(by.id('Trash')).tap(); + await element(by.text('Tags')).tap(); menu.tap(); await sleep(200); - element(by.text('Tags')).tap(); + await element(by.id('Settings')).tap(); menu.tap(); - await sleep(200); - element(by.id('Settings')).tap(); - menu.tap(); - await sleep(200); + await sleep(200); */ }); it('CHECK NIGHT MODE SWITCHING', async () => { - element(by.id('night_mode')).tap(); +/* await element(by.id('night_mode')).tap(); await sleep(2000); - element(by.id('night_mode')).tap(); + await element(by.id('night_mode')).tap(); */ }); diff --git a/apps/mobile/index.mobile.js b/apps/mobile/index.mobile.js index 2e997ec69..10cd38542 100644 --- a/apps/mobile/index.mobile.js +++ b/apps/mobile/index.mobile.js @@ -6,14 +6,14 @@ import {Screen, ScreenContainer} from 'react-native-screens'; import {DialogManager} from './src/components/DialogManager'; import {Toast} from './src/components/Toast'; import {useTracked} from './src/provider'; -import {NavigationStack} from './src/services/Navigator'; import { EditorOpacity, EditorPosition, EditorScale, EditorTranslateY, -} from './src/utils/animations'; +} from './src/utils/Animations'; import Editor from './src/views/Editor'; +import {NavigationStack} from "./src/navigation/Drawer"; const editorRef = createRef(); diff --git a/apps/mobile/index.tablet.js b/apps/mobile/index.tablet.js index da1f96f7f..f7e5ddc7e 100644 --- a/apps/mobile/index.tablet.js +++ b/apps/mobile/index.tablet.js @@ -8,14 +8,15 @@ import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent, -} from './src/services/eventManager'; +} from './src/services/EventManager'; import { eCloseFullscreenEditor, eOnLoadNote, eOpenFullscreenEditor, -} from './src/services/events'; -import {MainComponent, NavigationStack} from './src/services/Navigator'; +} from './src/utils/Events'; +import {NavigatorStack} from './src/navigation/NavigatorStack'; import Editor from './src/views/Editor'; +import {NavigationStack} from "./src/navigation/Drawer"; const editorRef = createRef(); let outColors; @@ -100,7 +101,7 @@ const NavWrapper = () => { borderRightColor: colors.nav, borderRightWidth: 1, }}> - + { const [state, dispatch] = useTracked(); const {colors, loading} = state; @@ -27,7 +27,7 @@ export const Loading = () => { zIndex: 999, transform: [ { - translateX: loading ? 0 : -w * 2, + translateX: loading ? 0 : -dWidth * 2, }, ], }}> @@ -71,7 +71,7 @@ export const Loading = () => { zIndex: 999, transform: [ { - translateX: loading ? 0 : w * 2, + translateX: loading ? 0 : dWidth * 2, }, ], }}> diff --git a/apps/mobile/src/common/common.js b/apps/mobile/src/common/common.js deleted file mode 100755 index 9ad0252b7..000000000 --- a/apps/mobile/src/common/common.js +++ /dev/null @@ -1,249 +0,0 @@ -import { - Dimensions, - PixelRatio, - StatusBar, - Platform, - Appearance, -} from 'react-native'; -import { - eSendEvent, - eSubscribeEvent, - eUnSubscribeEvent, -} from '../services/eventManager'; -import {eThemeUpdated} from '../services/events'; -import {DDS} from '../utils/utils'; -import {MMKV} from '../utils/storage'; - -export const scale = { - fontScale: 1, -}; -const {height, width} = Dimensions.get('window'); - -//COLOR SCHEME -export const ACCENT = { - color: '#0560FF', - shade: '#0560FF12', -}; - -const fixedColors = { - accent: ACCENT.color, - shade: ACCENT.shade, - fg: ACCENT.color, - normal: 'black', - icon: 'gray', - errorBg: '#FFD2D2', - errorText: '#ff6961', - successBg: '#DFF2BF', - successText: '#4F8A10', - warningBg: '#FEEFB3', - warningText: '#9F6000', -}; - -export var COLOR_SCHEME = { - night: false, - bg: 'white', - navbg: '#f6fbfc', - nav: '#f0f0f0', - pri: '#000000', - sec: 'white', - ...fixedColors, -}; - -export const COLOR_SCHEME_LIGHT = { - night: false, - bg: 'white', - navbg: '#f6fbfc', - nav: '#f0f0f0', - input: 'transparent', - heading: '#000000', - pri: '#24292e', - sec: 'white', - ...fixedColors, -}; -export const COLOR_SCHEME_DARK = { - night: true, - bg: '#1f1f1f', - navbg: '#1c1c1c', - input: '#2d2d2d', - nav: '#2d2d2d', - heading: '#ffffff', - pri: '#D3D3D3', - sec: 'black', - ...fixedColors, -}; - -let windowSize = Dimensions.get('window'); -let adjustedWidth = windowSize.width * PixelRatio.get(); -let adjustedHeight = windowSize.height * PixelRatio.get(); -const pixelDensity = PixelRatio.get(); - -export const COLORS_NOTE = { - red: '#f44336', - orange: '#FF9800', - yellow: '#FFD600', - green: '#4CAF50', - blue: '#2196F3', - purple: '#673AB7', - gray: '#9E9E9E', -}; - -export const getDeviceSize = () => { - let dpi = getDpi(pixelDensity); - let deviceWidthInInches = adjustedWidth / dpi; - let deviceHeightInInches = adjustedHeight / dpi; - let diagonalSize = Math.sqrt( - Math.pow(deviceWidthInInches, 2) + Math.pow(deviceHeightInInches, 2), - ); - return diagonalSize; -}; - -const getDpi = (pd) => { - return 160 * pd; -}; - -const correction = (size, multiplier) => { - let dSize = getDeviceSize(); - if (dSize >= 4 && dSize <= 5.3 && pixelDensity <= 3) { - return size * 0.92; - } else if (dSize > 5.3 && dSize < 7 && pixelDensity < 3 && !DDS.isTab) { - if (Platform.OS === 'ios') { - return size; - } - return size * 0.93; - } else if (dSize <= 7 && pixelDensity >= 3 && !DDS.isTab) { - return size * 0.98; - } else if (dSize >= 6.5 && dSize <= 7.2 && DDS.isTab) { - return size * multiplier; - } else if (dSize > 7.2 && dSize <= 8.5 && DDS.isTab) { - return size * (multiplier + 0.10); - } else if (dSize > 8.5 && dSize <= 9.8 && DDS.isTab) { - return size * (multiplier + 0.15); - } else if (dSize > 9.8) { - return size; - } else { - return size; - } -}; - -export const normalize = (size) => { - let pd = pixelDensity; - if (pd === 1 || pd < 1) { - return correction(size, 0.82); - } else if (pd > 1 && pd <= 1.5) { - return correction(size, 0.7); - } else if (pd > 1.5 && pd <= 2) { - return correction(size, 0.9); - } else if (pd > 2 && pd <= 3) { - return correction(size, 0.93); - } else if (pd > 3) { - return correction(size, 1); - } -}; - -export const SIZE = { - xxs: 10 * scale.fontScale, - xs: 12 * scale.fontScale, - sm: normalize(15) * scale.fontScale, - md: normalize(17) * scale.fontScale, - lg: normalize(24) * scale.fontScale, - xl: normalize(27) * scale.fontScale, - xxl: normalize(31) * scale.fontScale, - xxxl: normalize(34) * scale.fontScale, -}; - -export function updateSize() { - SIZE.xxs = 10 * scale.fontScale; - SIZE.xs = 12 * scale.fontScale; - SIZE.sm = normalize(15) * scale.fontScale; - SIZE.md = normalize(17) * scale.fontScale; - SIZE.lg = normalize(24) * scale.fontScale; - SIZE.xl = normalize(27) * scale.fontScale; - SIZE.xxl = normalize(31) * scale.fontScale; - SIZE.xxxl = normalize(34) * scale.fontScale; - ph = normalize(10) * scale.fontScale; - pv = normalize(10) * scale.fontScale; -} - -export const br = 5; // border radius -export var ph = normalize(10); // padding horizontal -export var pv = normalize(10); // padding vertical -export const opacity = 0.5; // active opacity - -// GLOBAL FONT - -export const WEIGHT = { - light: 'DMSans-Regular', - regular: 'DMSans-Regular', - medium: 'DMSans-Regular', - semibold: 'DMSerifText-Regular', - bold: 'DMSerifText-Regular', -}; - -export function setColorScheme(colors = COLOR_SCHEME, accent = ACCENT) { - COLOR_SCHEME = {...colors, accent: accent.color, shade: accent.shade}; - - eSendEvent(eThemeUpdated); - - return COLOR_SCHEME; -} - -export async function getColorScheme(useSystemTheme) { - let accentColor; - let theme; - try { - accentColor = await MMKV.getStringAsync('accentColor'); - } catch (e) {} - - try { - theme = await MMKV.getStringAsync('theme'); - } catch (e) {} - - if (typeof accentColor !== 'string') { - MMKV.setStringAsync('accentColor', '#0560FF'); - setAccentColor('#0560FF'); - } else { - setAccentColor(accentColor); - } - - if (useSystemTheme) { - StatusBar.setBarStyle( - Appearance.getColorScheme() === 'dark' ? 'light-content' : 'dark-content', - ); - - Appearance.getColorScheme() === 'dark' - ? setColorScheme(COLOR_SCHEME_DARK) - : setColorScheme(COLOR_SCHEME_LIGHT); - - return COLOR_SCHEME; - } - - if (typeof theme !== 'string') { - MMKV.setStringAsync('theme', JSON.stringify({night: false})); - - setColorScheme(COLOR_SCHEME_LIGHT); - } else { - theme = JSON.parse(theme); - theme.night - ? setColorScheme(COLOR_SCHEME_DARK) - : setColorScheme(COLOR_SCHEME_LIGHT); - StatusBar.setBarStyle(theme.night ? 'light-content' : 'dark-content'); - } - - eSendEvent(eThemeUpdated); - - return COLOR_SCHEME; -} - -export function setAccentColor(color) { - ACCENT.color = color; - ACCENT.shade = color + '12'; - - return ACCENT; -} - -export const onThemeUpdate = (func = () => {}) => { - return eSubscribeEvent(eThemeUpdated, func); -}; -export const clearThemeUpdateListener = (func = () => {}) => { - return eUnSubscribeEvent(eThemeUpdated, func); -}; diff --git a/apps/mobile/src/components/ActionIcon/index.js b/apps/mobile/src/components/ActionIcon/index.js index e052693f9..c130cf36f 100644 --- a/apps/mobile/src/components/ActionIcon/index.js +++ b/apps/mobile/src/components/ActionIcon/index.js @@ -1,8 +1,8 @@ import React from 'react'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {SIZE} from '../../common/common'; import {useTracked} from '../../provider'; import {PressableButton} from '../PressableButton'; +import {SIZE} from "../../utils/SizeUtils"; export const ActionIcon = ({ onPress, @@ -34,6 +34,7 @@ export const ActionIcon = ({ alignItems: 'center', borderRadius: 100, ...customStyle, + }}> diff --git a/apps/mobile/src/components/ActionSheet/index.js b/apps/mobile/src/components/ActionSheet/index.js index 257dec978..fae6e2ccb 100644 --- a/apps/mobile/src/components/ActionSheet/index.js +++ b/apps/mobile/src/components/ActionSheet/index.js @@ -17,7 +17,7 @@ import { ViewPropTypes, } from 'react-native'; -import {w} from '../../utils/utils'; +import {dWidth} from '../../utils'; import {styles} from './styles'; var deviceHeight = getDeviceHeight(); @@ -514,7 +514,7 @@ export default class ActionSheet extends Component { onScroll={this._onScroll} style={styles.scrollView} contentContainerStyle={{ - width: w, + width: dWidth, }} data={['dummy']} keyExtractor={(item) => item} diff --git a/apps/mobile/src/components/ActionSheet/styles.js b/apps/mobile/src/components/ActionSheet/styles.js index 2cc9eada9..68f446487 100644 --- a/apps/mobile/src/components/ActionSheet/styles.js +++ b/apps/mobile/src/components/ActionSheet/styles.js @@ -1,10 +1,10 @@ import {StyleSheet} from 'react-native'; -import { w } from '../../utils/utils'; +import { dWidth } from '../../utils'; export const styles = StyleSheet.create({ scrollview: { height: '100%', - width: w, + width: dWidth, backgroundColor: 'transparent', }, container: { diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js index 8c0a18c5c..2260afd30 100644 --- a/apps/mobile/src/components/ActionSheetComponent/index.js +++ b/apps/mobile/src/components/ActionSheetComponent/index.js @@ -11,39 +11,31 @@ import { } from 'react-native'; import Share from 'react-native-share'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import { - ACCENT, - COLORS_NOTE, - COLOR_SCHEME, - COLOR_SCHEME_DARK, - COLOR_SCHEME_LIGHT, - opacity, - ph, - pv, - setColorScheme, - SIZE, - WEIGHT, -} from '../../common/common'; import {useTracked} from '../../provider'; -import {ACTIONS} from '../../provider/actions'; -import {eSendEvent, openVault} from '../../services/eventManager'; +import {Actions} from '../../provider/Actions'; +import {eSendEvent, openVault, ToastEvent} from '../../services/EventManager'; import { eOpenLoginDialog, eOpenMoveNoteDialog, refreshNotesPage, -} from '../../services/events'; -import {MMKV} from '../../utils/storage'; -import { - db, - DDS, - hexToRGBA, - RGB_Linear_Shade, - timeConverter, - ToastEvent, -} from '../../utils/utils'; +} from '../../utils/Events'; import {PremiumTag} from '../Premium/PremiumTag'; import {PressableButton} from '../PressableButton'; import {Toast} from '../Toast'; +import {hexToRGBA, RGB_Linear_Shade} from "../../utils/ColorUtils"; +import {timeConverter} from "../../utils/TimeUtils"; +import { + ACCENT, + COLOR_SCHEME, + COLOR_SCHEME_DARK, + COLOR_SCHEME_LIGHT, + COLORS_NOTE, + setColorScheme +} from "../../utils/Colors"; +import {opacity, ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; +import {DDS} from "../../services/DeviceDetection"; +import {MMKV} from "../../utils/MMKV"; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; @@ -82,7 +74,7 @@ export const ActionSheetComponent = ({ let newColors = setColorScheme(colors, accent); StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content'); - dispatch({type: ACTIONS.THEME, colors: newColors}); + dispatch({type: Actions.THEME, colors: newColors}); } useEffect(() => { @@ -111,7 +103,7 @@ export const ActionSheetComponent = ({ await db.notes.note(note.id).tag(tag); setNote({...db.notes.note(note.id).data}); - dispatch({type: ACTIONS.TAGS}); + dispatch({type: Actions.TAGS}); tagsInputRef.current?.setNativeProps({ text: '', }); @@ -201,8 +193,8 @@ export const ActionSheetComponent = ({ if (!nodispatch) { dispatch({type: type}); - dispatch({type: ACTIONS.PINNED}); - dispatch({type: ACTIONS.FAVORITES}); + dispatch({type: Actions.PINNED}); + dispatch({type: Actions.FAVORITES}); } setNote({...toAdd}); }; @@ -212,8 +204,8 @@ export const ActionSheetComponent = ({ name: 'Add to', icon: 'book-outline', func: () => { - dispatch({type: ACTIONS.MODAL_NAVIGATOR, enabled: true}); - dispatch({type: ACTIONS.SELECTED_ITEMS, item: note}); + dispatch({type: Actions.MODAL_NAVIGATOR, enabled: true}); + dispatch({type: Actions.SELECTED_ITEMS, item: note}); close(); setTimeout(() => { eSendEvent(eOpenMoveNoteDialog); @@ -277,7 +269,7 @@ export const ActionSheetComponent = ({ name: 'Restore', icon: 'delete-restore', func: async () => { - dispatch({type: ACTIONS.TRASH}); + dispatch({type: Actions.TRASH}); localRefresh(note.type); ToastEvent.show( item.type === 'note' ? 'Note restored' : 'Notebook restored', @@ -328,7 +320,7 @@ export const ActionSheetComponent = ({ } else { await db.notebooks.notebook(note.id).pin(); } - dispatch({type: ACTIONS.PINNED}); + dispatch({type: Actions.PINNED}); localRefresh(item.type); }, close: false, @@ -349,7 +341,7 @@ export const ActionSheetComponent = ({ } else { await db.notebooks.notebook(note.id).favorite(); } - dispatch({type: ACTIONS.FAVORITES}); + dispatch({type: Actions.FAVORITES}); localRefresh(item.type); }, close: false, @@ -374,9 +366,9 @@ export const ActionSheetComponent = ({ db.vault .add(note.id) .then(() => { - dispatch({type: ACTIONS.NOTES}); + dispatch({type: Actions.NOTES}); eSendEvent(refreshNotesPage); - dispatch({type: ACTIONS.PINNED}); + dispatch({type: Actions.PINNED}); close(); }) .catch(async (e) => { @@ -410,7 +402,7 @@ export const ActionSheetComponent = ({ .note(note.id) .untag(oldProps.tags[oldProps.tags.indexOf(tag)]); localRefresh(oldProps.type); - dispatch({type: ACTIONS.TAGS}); + dispatch({type: Actions.TAGS}); } catch (e) { localRefresh(oldProps.type); } @@ -464,7 +456,7 @@ export const ActionSheetComponent = ({ } else { await db.notes.note(note.id).color(color.name); } - dispatch({type: ACTIONS.COLORS}); + dispatch({type: Actions.COLORS}); localRefresh(note.type); }} customStyle={{ @@ -611,7 +603,7 @@ export const ActionSheetComponent = ({ setRefreshing(true); try { let user = await db.user.get(); - dispatch({type: ACTIONS.USER, user: user}); + dispatch({type: Actions.USER, user: user}); await db.sync(); localRefresh(); ToastEvent.show('Note synced', 'success', 'local'); @@ -620,7 +612,7 @@ export const ActionSheetComponent = ({ } finally { setRefreshing(false); } - dispatch({type: ACTIONS.ALL}); + dispatch({type: Actions.ALL}); } }; diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js index 5a56e4375..30836a2c3 100644 --- a/apps/mobile/src/components/AddNotebookDialog/index.js +++ b/apps/mobile/src/components/AddNotebookDialog/index.js @@ -11,12 +11,14 @@ import { } from 'react-native'; import {FlatList, TextInput} from 'react-native-gesture-handler'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {ph, pv, SIZE, WEIGHT} from '../../common/common'; -import {ACTIONS} from '../../provider/actions'; -import {db, DDS, ToastEvent} from '../../utils/utils'; +import {Actions} from '../../provider/Actions'; import {Button} from '../Button'; import {updateEvent} from '../DialogManager/recievers'; import {Toast} from '../Toast'; +import {ToastEvent} from "../../services/EventManager"; +import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; +import {DDS} from "../../services/DeviceDetection"; let refs = []; @@ -173,8 +175,8 @@ export class AddNotebookDialog extends React.Component { }); } this.close(); - updateEvent({type: ACTIONS.NOTEBOOKS}); - updateEvent({type: ACTIONS.PINNED}); + updateEvent({type: Actions.NOTEBOOKS}); + updateEvent({type: Actions.PINNED}); //ToastEvent.show('New notebook added', 'success', 'local'); }; diff --git a/apps/mobile/src/components/AddTopicDialog/index.js b/apps/mobile/src/components/AddTopicDialog/index.js index 7164c6180..62b89b5b0 100644 --- a/apps/mobile/src/components/AddTopicDialog/index.js +++ b/apps/mobile/src/components/AddTopicDialog/index.js @@ -2,15 +2,17 @@ import React, {createRef} from 'react'; import {Modal, Text, TouchableOpacity, View} from 'react-native'; import {TextInput} from 'react-native-gesture-handler'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common'; -import {getElevation, ToastEvent, db, DDS} from '../../utils/utils'; -import {eSendEvent} from '../../services/eventManager'; -import {eOnNewTopicAdded} from '../../services/events'; +import {getElevation} from '../../utils'; +import {eSendEvent, ToastEvent} from '../../services/EventManager'; +import {eOnNewTopicAdded} from '../../utils/Events'; import {Toast} from '../Toast'; import {Button} from '../Button'; import BaseDialog from '../Dialog/base-dialog'; import DialogHeader from '../Dialog/dialog-header'; import DialogButtons from '../Dialog/dialog-buttons'; +import {opacity, ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; +import {DDS} from "../../services/DeviceDetection"; export class AddTopicDialog extends React.Component { constructor(props) { diff --git a/apps/mobile/src/components/Button/index.js b/apps/mobile/src/components/Button/index.js index d942fdb42..ce82f6203 100644 --- a/apps/mobile/src/components/Button/index.js +++ b/apps/mobile/src/components/Button/index.js @@ -1,9 +1,9 @@ import React from 'react'; import { ActivityIndicator, StyleSheet, Text } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import { ph, pv, SIZE, WEIGHT } from '../../common/common'; import { useTracked } from '../../provider'; import { PressableButton } from '../PressableButton'; +import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; export const Button = ({ height = 40, diff --git a/apps/mobile/src/components/Container/ContainerBottomButton.js b/apps/mobile/src/components/Container/ContainerBottomButton.js index bb442a781..20fe9c6a2 100644 --- a/apps/mobile/src/components/Container/ContainerBottomButton.js +++ b/apps/mobile/src/components/Container/ContainerBottomButton.js @@ -2,10 +2,11 @@ import React, {useEffect, useState} from 'react'; import {Keyboard, Platform, Text, View} from 'react-native'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {DDS, getElevation} from '../../utils/utils'; +import {getElevation} from '../../utils'; import {PressableButton} from '../PressableButton'; +import {pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; export const ContainerBottomButton = ({title, onPress, color}) => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/Container/ContainerTopSection.js b/apps/mobile/src/components/Container/ContainerTopSection.js index 1f15d5bc1..19869310b 100644 --- a/apps/mobile/src/components/Container/ContainerTopSection.js +++ b/apps/mobile/src/components/Container/ContainerTopSection.js @@ -1,7 +1,7 @@ import React, {useEffect} from 'react'; import Animated, {Easing, useValue} from 'react-native-reanimated'; import {useTracked} from '../../provider'; -import {Header} from '../header'; +import {Header} from '../Header'; import {Search} from '../SearchInput'; export const ContainerTopSection = ({root}) => { @@ -38,8 +38,9 @@ export const ContainerTopSection = ({root}) => { }, ], }}> -
+ +
); diff --git a/apps/mobile/src/components/ContextMenu/index.js b/apps/mobile/src/components/ContextMenu/index.js index 082200f20..80e01c0c3 100644 --- a/apps/mobile/src/components/ContextMenu/index.js +++ b/apps/mobile/src/components/ContextMenu/index.js @@ -1,9 +1,9 @@ import React, {useEffect, useState} from 'react'; import {Text, View} from 'react-native'; -import {SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; -import { getElevation } from '../../utils/utils'; +import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager'; +import { getElevation } from '../../utils'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; let contextTimeout = null; diff --git a/apps/mobile/src/components/Dialog/DialogHeader.js b/apps/mobile/src/components/Dialog/DialogHeader.js index bd9b45713..7fd8389ba 100644 --- a/apps/mobile/src/components/Dialog/DialogHeader.js +++ b/apps/mobile/src/components/Dialog/DialogHeader.js @@ -1,8 +1,8 @@ import React from 'react'; import {Text, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import { SIZE, WEIGHT } from '../../common/common'; import {useTracked} from '../../provider'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; const DialogHeader = ({icon, title, paragraph}) => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.js index cf45c563f..9e3a81814 100644 --- a/apps/mobile/src/components/Dialog/index.js +++ b/apps/mobile/src/components/Dialog/index.js @@ -1,24 +1,26 @@ import React, {Component} from 'react'; import {Modal, Text, TouchableOpacity, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {ph, pv, SIZE, WEIGHT} from '../../common/common'; -import {ACTIONS} from '../../provider/actions'; -import {eSendEvent} from '../../services/eventManager'; +import {Actions} from '../../provider/Actions'; +import {eSendEvent, ToastEvent} from '../../services/EventManager'; import { eApplyChanges, eClearEditor, eCloseFullscreenEditor, eOnLoadNote, eOnNewTopicAdded, -} from '../../services/events'; -import NavigationService from '../../services/NavigationService'; -import {db, DDS, getElevation, history, ToastEvent} from '../../utils/utils'; +} from '../../utils/Events'; +import NavigationService from '../../services/Navigation'; +import {getElevation, history} from '../../utils'; import {Button} from '../Button'; -import {dialogActions} from '../DialogManager/dialogActions'; +import {dialogActions} from '../DialogManager/DialogActions'; import {updateEvent} from '../DialogManager/recievers'; import BaseDialog from './base-dialog'; import DialogButtons from './dialog-buttons'; import DialogHeader from './dialog-header'; +import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; +import {DDS} from "../../services/DeviceDetection"; export class Dialog extends Component { constructor(props) { @@ -55,7 +57,7 @@ export class Dialog extends Component { updateEvent({type: it.type}); } } - updateEvent({type: ACTIONS.PINNED}); + updateEvent({type: Actions.PINNED}); let message; let notes = history.selectedItemsList.filter((o) => o.type === 'note'); @@ -99,15 +101,15 @@ export class Dialog extends Component { await db.trash.restore(trashItem.id); updateEvent({type: it.type}); } - updateEvent({type: ACTIONS.TRASH}); - updateEvent({type: ACTIONS.PINNED}); + updateEvent({type: Actions.TRASH}); + updateEvent({type: Actions.PINNED}); ToastEvent.hide(); }, 'Undo', ); - updateEvent({type: ACTIONS.CLEAR_SELECTION}); - updateEvent({type: ACTIONS.SELECTION_MODE, enabled: false}); + updateEvent({type: Actions.CLEAR_SELECTION}); + updateEvent({type: Actions.SELECTION_MODE, enabled: false}); this.hide(); break; @@ -122,9 +124,9 @@ export class Dialog extends Component { await db.trash.delete(...ids); - updateEvent({type: ACTIONS.TRASH}); - updateEvent({type: ACTIONS.CLEAR_SELECTION}); - updateEvent({type: ACTIONS.SELECTION_MODE, enabled: false}); + updateEvent({type: Actions.TRASH}); + updateEvent({type: Actions.CLEAR_SELECTION}); + updateEvent({type: Actions.SELECTION_MODE, enabled: false}); ToastEvent.show('Item permanantly deleted'); this.hide(); break; @@ -144,17 +146,17 @@ export class Dialog extends Component { } case dialogActions.ACTION_EMPTY_TRASH: { await db.trash.clear(); - updateEvent({type: ACTIONS.TRASH}); + updateEvent({type: Actions.TRASH}); - updateEvent({type: ACTIONS.CLEAR_SELECTION}); - updateEvent({type: ACTIONS.SELECTION_MODE, enabled: false}); + updateEvent({type: Actions.CLEAR_SELECTION}); + updateEvent({type: Actions.SELECTION_MODE, enabled: false}); ToastEvent.show('Trash cleared', 'error'); this.hide(); break; } case dialogActions.ACTION_EXIT_FULLSCREEN: { - updateEvent({type: ACTIONS.NOTES}); + updateEvent({type: Actions.NOTES}); eSendEvent(eCloseFullscreenEditor); this.hide(); break; @@ -169,7 +171,7 @@ export class Dialog extends Component { 'success', ); - updateEvent({type: ACTIONS.TRASH}); + updateEvent({type: Actions.TRASH}); this.hide(); break; } diff --git a/apps/mobile/src/components/DialogManager/dialogActions.js b/apps/mobile/src/components/DialogManager/DialogActions.js similarity index 100% rename from apps/mobile/src/components/DialogManager/dialogActions.js rename to apps/mobile/src/components/DialogManager/DialogActions.js diff --git a/apps/mobile/src/components/DialogManager/recievers.js b/apps/mobile/src/components/DialogManager/Recievers.js similarity index 93% rename from apps/mobile/src/components/DialogManager/recievers.js rename to apps/mobile/src/components/DialogManager/Recievers.js index 43dd75ed0..781a8d2d8 100644 --- a/apps/mobile/src/components/DialogManager/recievers.js +++ b/apps/mobile/src/components/DialogManager/Recievers.js @@ -1,4 +1,4 @@ -import {eSendEvent} from '../../services/eventManager'; +import {eSendEvent} from '../../services/EventManager'; import { eCloseActionSheet, eCloseAddNotebookDialog, @@ -11,7 +11,7 @@ import { eOpenMoveNoteDialog, eOpenSimpleDialog, eDispatchAction, -} from '../../services/events'; +} from '../../utils/Events'; export const ActionSheetEvent = ( item, diff --git a/apps/mobile/src/components/DialogManager/templates.js b/apps/mobile/src/components/DialogManager/Templates.js similarity index 96% rename from apps/mobile/src/components/DialogManager/templates.js rename to apps/mobile/src/components/DialogManager/Templates.js index 9a81aa67e..b88acecfb 100644 --- a/apps/mobile/src/components/DialogManager/templates.js +++ b/apps/mobile/src/components/DialogManager/Templates.js @@ -1,5 +1,5 @@ -import {dialogActions} from './dialogActions'; -import {timeConverter} from '../../utils/utils'; +import {dialogActions} from './DialogActions'; +import {timeConverter} from "../../utils/TimeUtils"; export const TEMPLATE_DELETE = type => { return { diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.js index 71f4e4d61..6d7139569 100644 --- a/apps/mobile/src/components/DialogManager/index.js +++ b/apps/mobile/src/components/DialogManager/index.js @@ -5,7 +5,7 @@ import { eSubscribeEvent, eUnSubscribeEvent, openVault, -} from '../../services/eventManager'; +} from '../../services/EventManager'; import { eCloseActionSheet, eCloseAddNotebookDialog, @@ -23,8 +23,7 @@ import { eOpenMoveNoteDialog, eOpenPremiumDialog, eOpenSimpleDialog, -} from '../../services/events'; -import {DDS, hexToRGBA} from '../../utils/utils'; +} from '../../utils/Events'; import ActionSheet from '../ActionSheet'; import {ActionSheetComponent} from '../ActionSheetComponent'; import {AddNotebookDialog} from '../AddNotebookDialog'; @@ -41,7 +40,9 @@ import ProgressDialog from '../ProgressDialog'; import RecoveryKeyDialog from '../RecoveryKeyDialog'; import RestoreDialog from '../RestoreDialog'; import {VaultDialog} from '../VaultDialog'; -import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './templates'; +import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './Templates'; +import {hexToRGBA} from "../../utils/ColorUtils"; +import {DDS} from "../../services/DeviceDetection"; export class DialogManager extends Component { constructor(props) { diff --git a/apps/mobile/src/components/ExportDialog/index.js b/apps/mobile/src/components/ExportDialog/index.js index 73576240a..4569e8049 100644 --- a/apps/mobile/src/components/ExportDialog/index.js +++ b/apps/mobile/src/components/ExportDialog/index.js @@ -10,24 +10,27 @@ import { import FileViewer from 'react-native-file-viewer'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import RNFetchBlob from 'rn-fetch-blob'; -import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; import storage from '../../utils/storage'; -import {DDS, getElevation, sleep, ToastEvent} from '../../utils/utils'; +import {getElevation} from '../../utils'; import {Button} from '../Button/index'; import BaseDialog from '../Dialog/base-dialog'; import DialogHeader from '../Dialog/dialog-header'; import {Loading} from '../Loading'; import Seperator from '../Seperator'; +import {sleep} from "../../utils/TimeUtils"; +import {ToastEvent} from "../../services/EventManager"; +import {opacity, ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; const { eSubscribeEvent, eUnSubscribeEvent, -} = require('../../services/eventManager'); +} = require('../../services/EventManager'); const { eOpenExportDialog, eCloseExportDialog, -} = require('../../services/events'); +} = require('../../utils/Events'); const ExportDialog = () => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/header/HeaderMenu.js b/apps/mobile/src/components/Header/HeaderMenu.js similarity index 85% rename from apps/mobile/src/components/header/HeaderMenu.js rename to apps/mobile/src/components/Header/HeaderMenu.js index 5221bd08b..179eaa05e 100644 --- a/apps/mobile/src/components/header/HeaderMenu.js +++ b/apps/mobile/src/components/Header/HeaderMenu.js @@ -1,9 +1,9 @@ import React, { createRef } from 'react'; import Menu, { MenuDivider, MenuItem } from 'react-native-material-menu'; -import { SIZE, WEIGHT } from '../../common/common'; import { useTracked } from '../../provider'; -import { ACTIONS } from '../../provider/actions'; +import { Actions } from '../../provider/Actions'; import { ActionIcon } from '../ActionIcon'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; const menuRef = createRef(); export const HeaderMenu = () => { const [state, dispatch] = useTracked(); @@ -51,7 +51,7 @@ export const HeaderMenu = () => { color: colors.pri, }} onPress={() => { - dispatch({type: ACTIONS.NOTES, sort: null}); + dispatch({type: Actions.NOTES, sort: null}); menuRef.current?.hide(); }}> Default @@ -62,7 +62,7 @@ export const HeaderMenu = () => { color: colors.pri, }} onPress={() => { - dispatch({type: ACTIONS.NOTES, sort: 'abc'}); + dispatch({type: Actions.NOTES, sort: 'abc'}); menuRef.current?.hide(); }}> Alphabetical @@ -73,7 +73,7 @@ export const HeaderMenu = () => { color: colors.pri, }} onPress={() => { - dispatch({type: ACTIONS.NOTES, sort: 'year'}); + dispatch({type: Actions.NOTES, sort: 'year'}); menuRef.current?.hide(); }}> By year @@ -84,7 +84,7 @@ export const HeaderMenu = () => { color: colors.pri, }} onPress={() => { - dispatch({type: ACTIONS.NOTES, sort: 'month'}); + dispatch({type: Actions.NOTES, sort: 'month'}); menuRef.current?.hide(); }}> By month @@ -95,7 +95,7 @@ export const HeaderMenu = () => { color: colors.pri, }} onPress={() => { - dispatch({type: ACTIONS.NOTES, sort: 'week'}); + dispatch({type: Actions.NOTES, sort: 'week'}); menuRef.current?.hide(); }}> By week diff --git a/apps/mobile/src/components/header/HeaderTitle.js b/apps/mobile/src/components/Header/HeaderTitle.js similarity index 93% rename from apps/mobile/src/components/header/HeaderTitle.js rename to apps/mobile/src/components/Header/HeaderTitle.js index 6722e8082..00ec3b913 100644 --- a/apps/mobile/src/components/header/HeaderTitle.js +++ b/apps/mobile/src/components/Header/HeaderTitle.js @@ -1,7 +1,7 @@ import React from 'react'; import {Text} from 'react-native'; -import {SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; export const HeaderTitle = ({root}) => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/Header/index.js similarity index 92% rename from apps/mobile/src/components/header/index.js rename to apps/mobile/src/components/Header/index.js index 8a8d24356..943e41f42 100644 --- a/apps/mobile/src/components/header/index.js +++ b/apps/mobile/src/components/Header/index.js @@ -2,15 +2,16 @@ import React from 'react'; import {ActivityIndicator, Platform, StyleSheet, View} from 'react-native'; import * as Animatable from 'react-native-animatable'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; -import {SIZE} from '../../common/common'; import {useTracked} from '../../provider'; -import {eSendEvent} from '../../services/eventManager'; -import NavigationService from '../../services/NavigationService'; -import {useHideHeader} from '../../utils/hooks'; -import {DDS, w} from '../../utils/utils'; +import {eSendEvent} from '../../services/EventManager'; +import NavigationService from '../../services/Navigation'; +import {useHideHeader} from '../../utils/Hooks'; +import {dWidth} from '../../utils'; import {ActionIcon} from '../ActionIcon'; import {HeaderMenu} from './HeaderMenu'; import {HeaderTitle} from './HeaderTitle'; +import {SIZE} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; export const Header = ({showSearch, root}) => { const [state, dispatch] = useTracked(); @@ -37,6 +38,25 @@ export const Header = ({showSearch, root}) => { overflow: 'hidden', }, ]}> + + {!DDS.isTab ? ( + + ) : undefined} + + {Platform.OS === 'android' ? : null} + + {Platform.OS !== 'android' ? : null} + { - - {!DDS.isTab ? ( - - ) : undefined} - - {Platform.OS === 'android' ? : null} - - {Platform.OS !== 'android' ? : null} - { const [state, dispatch] = useTracked(); @@ -120,18 +122,18 @@ const LoginDialog = () => { let user = await db.user.get(); if (!user) throw new Error('Username or password incorrect'); setStatus('Syncing your notes'); - dispatch({type: ACTIONS.USER, user: user}); - dispatch({type: ACTIONS.SYNCING, syncing: true}); + dispatch({type: Actions.USER, user: user}); + dispatch({type: Actions.SYNCING, syncing: true}); await db.sync(); eSendEvent(eStartSyncer); - dispatch({type: ACTIONS.ALL}); + dispatch({type: Actions.ALL}); eSendEvent(refreshNotesPage); setVisible(false); ToastEvent.show(`Logged in as ${username}`, 'success', 'local'); } catch (e) { ToastEvent.show(e.message, 'error', 'local'); } finally { - dispatch({type: ACTIONS.SYNCING, syncing: false}); + dispatch({type: Actions.SYNCING, syncing: false}); setLoggingIn(false); } }; @@ -189,7 +191,7 @@ const LoginDialog = () => { let k = await db.user.key(); setKey(k.key); setStatus('Setting up crenditials'); - dispatch({type: ACTIONS.USER, user: user}); + dispatch({type: Actions.USER, user: user}); eSendEvent(eStartSyncer); setModalVisible(true); } catch (e) { diff --git a/apps/mobile/src/components/Menu/ColorSection.js b/apps/mobile/src/components/Menu/ColorSection.js index bf9efa63e..510d95b17 100644 --- a/apps/mobile/src/components/Menu/ColorSection.js +++ b/apps/mobile/src/components/Menu/ColorSection.js @@ -1,12 +1,13 @@ import React, { useEffect } from 'react'; import { Text, View } from 'react-native'; -import { COLORS_NOTE, SIZE } from '../../common/common'; import { useTracked } from '../../provider'; -import { ACTIONS } from '../../provider/actions'; -import { eSendEvent } from '../../services/eventManager'; -import { refreshNotesPage } from '../../services/events'; -import NavigationService from '../../services/NavigationService'; +import { Actions } from '../../provider/Actions'; +import { eSendEvent } from '../../services/EventManager'; +import { refreshNotesPage } from '../../utils/Events'; +import NavigationService from '../../services/Navigation'; import { PressableButton } from '../PressableButton'; +import {COLORS_NOTE} from "../../utils/Colors"; +import {SIZE} from "../../utils/SizeUtils"; export const ColorSection = ({noTextMode}) => { const [state, dispatch] = useTracked(); @@ -14,7 +15,7 @@ export const ColorSection = ({noTextMode}) => { useEffect(() => { - dispatch({type: ACTIONS.TAGS}); + dispatch({type: Actions.TAGS}); }, []); return ( @@ -40,18 +41,18 @@ export const ColorSection = ({noTextMode}) => { color: item, }; dispatch({ - type: ACTIONS.HEADER_VERTICAL_MENU, + type: Actions.HEADER_VERTICAL_MENU, state: false, }); dispatch({ - type: ACTIONS.CONTAINER_BOTTOM_BUTTON, + type: Actions.CONTAINER_BOTTOM_BUTTON, state: { bottomButtonText: 'Create a new Note', }, }); dispatch({ - type: ACTIONS.HEADER_TEXT_STATE, + type: Actions.HEADER_TEXT_STATE, state: { heading: item.title, }, diff --git a/apps/mobile/src/components/Menu/MenuListItem.js b/apps/mobile/src/components/Menu/MenuListItem.js index 10baacf67..b495cebed 100644 --- a/apps/mobile/src/components/Menu/MenuListItem.js +++ b/apps/mobile/src/components/Menu/MenuListItem.js @@ -1,14 +1,15 @@ import React from 'react'; import {Text, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {ACTIONS} from '../../provider/actions'; -import {eSendEvent} from '../../services/eventManager'; -import {eClearSearch} from '../../services/events'; -import NavigationService from '../../services/NavigationService'; -import {DDS, showContext} from '../../utils/utils'; +import {Actions} from '../../provider/Actions'; +import {eSendEvent} from '../../services/EventManager'; +import {eClearSearch} from '../../utils/Events'; +import NavigationService from '../../services/Navigation'; +import {showContext} from '../../utils'; import {PressableButton} from '../PressableButton'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; export const MenuListItem = ({item, index, noTextMode, ignore, testID}) => { const [state, dispatch] = useTracked(); @@ -17,7 +18,7 @@ export const MenuListItem = ({item, index, noTextMode, ignore, testID}) => { const _onPress = (event) => { if (!ignore) { dispatch({ - type: ACTIONS.HEADER_TEXT_STATE, + type: Actions.HEADER_TEXT_STATE, state: { heading: item.name, }, diff --git a/apps/mobile/src/components/Menu/TagsSection.js b/apps/mobile/src/components/Menu/TagsSection.js index 8449ef140..678883e6d 100644 --- a/apps/mobile/src/components/Menu/TagsSection.js +++ b/apps/mobile/src/components/Menu/TagsSection.js @@ -1,11 +1,11 @@ import React, { useEffect } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; -import { opacity, SIZE, WEIGHT } from '../../common/common'; import { useTracked } from '../../provider'; -import { ACTIONS } from '../../provider/actions'; -import { eSendEvent } from '../../services/eventManager'; -import { refreshNotesPage } from '../../services/events'; -import NavigationService from '../../services/NavigationService'; +import { Actions } from '../../provider/Actions'; +import { eSendEvent } from '../../services/EventManager'; +import { refreshNotesPage } from '../../utils/Events'; +import NavigationService from '../../services/Navigation'; +import {opacity, SIZE, WEIGHT} from "../../utils/SizeUtils"; export const TagsSection = () => { @@ -14,7 +14,7 @@ export const TagsSection = () => { useEffect(() => { - dispatch({type: ACTIONS.TAGS}); + dispatch({type: Actions.TAGS}); }, []); return ( { }; dispatch({ - type: ACTIONS.HEADER_VERTICAL_MENU, + type: Actions.HEADER_VERTICAL_MENU, state: false, }); dispatch({ - type: ACTIONS.CONTAINER_BOTTOM_BUTTON, + type: Actions.CONTAINER_BOTTOM_BUTTON, state: { bottomButtonText:'Create a new Note', }, }); dispatch({ - type: ACTIONS.HEADER_TEXT_STATE, + type: Actions.HEADER_TEXT_STATE, state: { heading: item.title, }, diff --git a/apps/mobile/src/components/Menu/TimeSince.js b/apps/mobile/src/components/Menu/TimeSince.js index 4f0d1a357..c80e8d411 100644 --- a/apps/mobile/src/components/Menu/TimeSince.js +++ b/apps/mobile/src/components/Menu/TimeSince.js @@ -1,6 +1,6 @@ import React, {useEffect, useState} from 'react'; import {Text} from 'react-native'; -import {timeSince} from '../../utils/utils'; +import {timeSince} from "../../utils/TimeUtils"; export const TimeSince = ({time}) => { const [timeAgo, setTimeAgo] = useState(null); diff --git a/apps/mobile/src/components/Menu/UserSection.js b/apps/mobile/src/components/Menu/UserSection.js index e0b4be322..6f7fdbea0 100644 --- a/apps/mobile/src/components/Menu/UserSection.js +++ b/apps/mobile/src/components/Menu/UserSection.js @@ -7,14 +7,16 @@ import { View, } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {ACTIONS} from '../../provider/actions'; -import {eSendEvent} from '../../services/eventManager'; -import {eOpenLoginDialog} from '../../services/events'; -import {db, hexToRGBA, showContext, ToastEvent} from '../../utils/utils'; +import {Actions} from '../../provider/Actions'; +import {eSendEvent, ToastEvent} from '../../services/EventManager'; +import {eOpenLoginDialog} from '../../utils/Events'; +import {showContext} from '../../utils'; import {PressableButton} from '../PressableButton'; import {TimeSince} from './TimeSince'; +import {hexToRGBA} from "../../utils/ColorUtils"; +import {pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; export const UserSection = ({noTextMode}) => { const [state, dispatch] = useTracked(); @@ -22,7 +24,7 @@ export const UserSection = ({noTextMode}) => { useEffect(() => { console.log(user); - dispatch({type: ACTIONS.TAGS}); + dispatch({type: Actions.TAGS}); }, []); return user && user.username ? ( @@ -66,13 +68,13 @@ export const UserSection = ({noTextMode}) => { { dispatch({ - type: ACTIONS.SYNCING, + type: Actions.SYNCING, syncing: true, }); try { if (!user) { let u = await db.user.get(); - dispatch({type: ACTIONS.USER, user: u}); + dispatch({type: Actions.USER, user: u}); } await db.sync(); ToastEvent.show('Sync Complete', 'success'); @@ -80,10 +82,10 @@ export const UserSection = ({noTextMode}) => { ToastEvent.show(e.message, 'error'); } let u = await db.user.get(); - dispatch({type: ACTIONS.USER, user: u}); - dispatch({type: ACTIONS.ALL}); + dispatch({type: Actions.USER, user: u}); + dispatch({type: Actions.ALL}); dispatch({ - type: ACTIONS.SYNCING, + type: Actions.SYNCING, syncing: false, }); }} diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js index 3c73f6b2d..6d160e85b 100644 --- a/apps/mobile/src/components/Menu/index.js +++ b/apps/mobile/src/components/Menu/index.js @@ -10,27 +10,21 @@ import { import {createAnimatableComponent} from 'react-native-animatable'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import { - ACCENT, - COLOR_SCHEME, - COLOR_SCHEME_DARK, - COLOR_SCHEME_LIGHT, - ph, - setColorScheme, - SIZE, -} from '../../common/common'; import {useTracked} from '../../provider'; -import {ACTIONS} from '../../provider/actions'; -import NavigationService from '../../services/NavigationService'; -import {sideMenuRef} from '../../utils/refs'; -import {DDS, w} from '../../utils/utils'; +import {Actions} from '../../provider/Actions'; +import NavigationService from '../../services/Navigation'; +import {sideMenuRef} from '../../utils/Refs'; +import {dWidth} from '../../utils'; import {ColorSection} from './ColorSection'; import {MenuListItem} from './MenuListItem'; import {TagsSection} from './TagsSection'; import {UserSection} from './UserSection'; -import {MMKV} from '../../utils/storage'; import Seperator from '../Seperator'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; +import {ACCENT, COLOR_SCHEME, COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT, setColorScheme} from "../../utils/Colors"; +import {ph, SIZE} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; +import {MMKV} from "../../utils/MMKV"; export const Menu = ({ close = () => {}, @@ -46,7 +40,7 @@ export const Menu = ({ function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) { let newColors = setColorScheme(colors, accent); StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content'); - dispatch({type: ACTIONS.THEME, colors: newColors}); + dispatch({type: Actions.THEME, colors: newColors}); } const listItems = [ diff --git a/apps/mobile/src/components/MergeEditor/index.js b/apps/mobile/src/components/MergeEditor/index.js index 22081ecf6..0e746f6db 100644 --- a/apps/mobile/src/components/MergeEditor/index.js +++ b/apps/mobile/src/components/MergeEditor/index.js @@ -3,28 +3,29 @@ import {Modal, Text, TouchableOpacity, View, SafeAreaView} from 'react-native'; import Animated, {Easing} from 'react-native-reanimated'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import WebView from 'react-native-webview'; -import {normalize, SIZE} from '../../common/common'; import {useTracked} from '../../provider'; -import {ACTIONS} from '../../provider/actions'; +import {Actions} from '../../provider/Actions'; import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent, -} from '../../services/eventManager'; +} from '../../services/EventManager'; import { eApplyChanges, eShowMergeDialog, refreshNotesPage, -} from '../../services/events'; -import {db, h} from '../../utils/utils'; +} from '../../utils/Events'; +import {dHeight} from '../../utils'; import {Button} from '../Button'; import {simpleDialogEvent, updateEvent} from '../DialogManager/recievers'; -import {TEMPLATE_APPLY_CHANGES} from '../DialogManager/templates'; +import {TEMPLATE_APPLY_CHANGES} from '../DialogManager/Templates'; +import {normalize, SIZE} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; const {Value, timing} = Animated; -const firstWebViewHeight = new Value(h * 0.5 - 50); -const secondWebViewHeight = new Value(h * 0.5 - 50); +const firstWebViewHeight = new Value(dHeight * 0.5 - 50); +const secondWebViewHeight = new Value(dHeight * 0.5 - 50); const primaryWebView = createRef(); const secondaryWebView = createRef(); let note = null; @@ -36,13 +37,13 @@ function openEditorAnimation( ) { let openConfig = { duration: 300, - toValue: !siblingStatus ? h - 100 : h * 0.5 - 50, + toValue: !siblingStatus ? dHeight - 100 : dHeight * 0.5 - 50, easing: Easing.inOut(Easing.ease), }; let extendConfig = { duration: 300, - toValue: h * 0.5 - 50, + toValue: dHeight * 0.5 - 50, easing: Easing.inOut(Easing.ease), }; @@ -61,7 +62,7 @@ function closeEditorAnimation(heightToAnimate, heightToExtend = null) { let extendConfig = { duration: 300, - toValue: h - 100, + toValue: dHeight - 100, easing: Easing.inOut(Easing.ease), }; if (heightToExtend) { @@ -189,8 +190,8 @@ const MergeEditor = () => { }); } eSendEvent(refreshNotesPage); - updateEvent({type: ACTIONS.NOTES}); - updateEvent({type: ACTIONS.FAVORITES}); + updateEvent({type: Actions.NOTES}); + updateEvent({type: Actions.FAVORITES}); close(); }; diff --git a/apps/mobile/src/components/MoveNoteDialog/index.js b/apps/mobile/src/components/MoveNoteDialog/index.js index 9b48ef7c8..04ce83a34 100644 --- a/apps/mobile/src/components/MoveNoteDialog/index.js +++ b/apps/mobile/src/components/MoveNoteDialog/index.js @@ -9,14 +9,16 @@ import { } from 'react-native'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {ACTIONS} from '../../provider/actions'; -import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; -import {eOpenMoveNoteDialog} from '../../services/events'; -import {db, DDS, getElevation, ToastEvent} from '../../utils/utils'; +import {Actions} from '../../provider/Actions'; +import {eSubscribeEvent, eUnSubscribeEvent, ToastEvent} from '../../services/EventManager'; +import {eOpenMoveNoteDialog} from '../../utils/Events'; +import {getElevation} from '../../utils'; import {PressableButton} from '../PressableButton'; import {Toast} from '../Toast'; +import {pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; +import {DDS} from "../../services/DeviceDetection"; let newNotebookTitle = null; let newTopicTitle = null; @@ -64,8 +66,8 @@ const MoveNoteDialog = () => { }); notebookInput.current?.clear(); notebookInput.current?.blur(); - dispatch({type: ACTIONS.NOTEBOOKS}); - dispatch({type: ACTIONS.PINNED}); + dispatch({type: Actions.NOTEBOOKS}); + dispatch({type: Actions.PINNED}); }; const addNewTopic = async () => { @@ -75,8 +77,8 @@ const MoveNoteDialog = () => { let res = await db.notebooks.notebook(expanded).topics.add(newTopicTitle); - dispatch({type: ACTIONS.NOTEBOOKS}); - dispatch({type: ACTIONS.PINNED}); + dispatch({type: Actions.NOTEBOOKS}); + dispatch({type: Actions.PINNED}); topicInput.current?.clear(); topicInput.current?.blur(); newTopicTitle = null; @@ -364,9 +366,9 @@ const MoveNoteDialog = () => { }, ...noteIds, ); - dispatch({type: ACTIONS.CLEAR_SELECTION}); - dispatch({type: ACTIONS.NOTEBOOKS}); - dispatch({type: ACTIONS.PINNED}); + dispatch({type: Actions.CLEAR_SELECTION}); + dispatch({type: Actions.NOTEBOOKS}); + dispatch({type: Actions.PINNED}); close(); let notebookName = db.notebooks.notebook( item.notebookId, diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js index 5ee45704a..7df02cd31 100644 --- a/apps/mobile/src/components/NoteItem/index.js +++ b/apps/mobile/src/components/NoteItem/index.js @@ -1,10 +1,10 @@ import React from 'react'; import { Dimensions, Text, View } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import { ph, SIZE, WEIGHT } from '../../common/common'; -import { timeSince } from '../../utils/utils'; import { ActionIcon } from '../ActionIcon'; import { ActionSheetEvent } from '../DialogManager/recievers'; +import {timeSince} from "../../utils/TimeUtils"; +import {ph, SIZE, WEIGHT} from "../../utils/SizeUtils"; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js index bf983d65c..370a85b99 100644 --- a/apps/mobile/src/components/NotebookItem/index.js +++ b/apps/mobile/src/components/NotebookItem/index.js @@ -1,11 +1,11 @@ import React from 'react'; import {Text, TouchableOpacity, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import NavigationService from '../../services/NavigationService'; +import NavigationService from '../../services/Navigation'; import {ActionSheetEvent} from '../DialogManager/recievers'; import Seperator from '../Seperator'; +import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; export const NotebookItem = ({ item, diff --git a/apps/mobile/src/components/Premium/PendingDialog.js b/apps/mobile/src/components/Premium/PendingDialog.js index c4f5f6dbd..4f674eb5b 100644 --- a/apps/mobile/src/components/Premium/PendingDialog.js +++ b/apps/mobile/src/components/Premium/PendingDialog.js @@ -1,11 +1,13 @@ import React, {createRef} from 'react'; import {Text, View} from 'react-native'; -import {SIZE, WEIGHT} from '../../common/common'; -import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; -import {eClosePendingDialog, eOpenPendingDialog} from '../../services/events'; -import {db, DDS, w} from '../../utils/utils'; +import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager'; +import {eClosePendingDialog, eOpenPendingDialog} from '../../utils/Events'; +import {dWidth} from '../../utils'; import ActionSheet from '../ActionSheet'; import Seperator from '../Seperator'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; +import {DDS} from "../../services/DeviceDetection"; const actionSheet = createRef(); class PendingDialog extends React.Component { @@ -74,7 +76,7 @@ class PendingDialog extends React.Component { initialOffsetFromBottom={1}> {[ { diff --git a/apps/mobile/src/components/Premium/PremiumStatusDialog.js b/apps/mobile/src/components/Premium/PremiumStatusDialog.js index f833958e7..b8d4c5151 100644 --- a/apps/mobile/src/components/Premium/PremiumStatusDialog.js +++ b/apps/mobile/src/components/Premium/PremiumStatusDialog.js @@ -1,19 +1,20 @@ import React, {useEffect, useState} from 'react'; import {Modal, StyleSheet, Text, TouchableOpacity, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; -import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {DDS, getElevation} from '../../utils/utils'; +import {getElevation} from '../../utils'; import Seperator from '../Seperator'; +import {ph, pv, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; const { eSubscribeEvent, eUnSubscribeEvent, -} = require('../../services/eventManager'); +} = require('../../services/EventManager'); const { eOpenPremiumStatusDialog, eClosePremiumStatusDialog, -} = require('../../services/events'); +} = require('../../utils/Events'); const PremiumStatusDialog = () => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/Premium/PremiumTag.js b/apps/mobile/src/components/Premium/PremiumTag.js index 9ab924742..f27b6186e 100644 --- a/apps/mobile/src/components/Premium/PremiumTag.js +++ b/apps/mobile/src/components/Premium/PremiumTag.js @@ -1,7 +1,7 @@ import React from 'react'; import {Text, View} from 'react-native'; -import {WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; +import {WEIGHT} from "../../utils/SizeUtils"; export const PremiumTag = ({pro}) => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/PressableButton/index.js b/apps/mobile/src/components/PressableButton/index.js index 67edeefcf..8fd109fb7 100644 --- a/apps/mobile/src/components/PressableButton/index.js +++ b/apps/mobile/src/components/PressableButton/index.js @@ -1,7 +1,7 @@ import React from 'react'; import {Pressable} from 'react-native'; -import {br} from '../../common/common'; -import {hexToRGBA, RGB_Linear_Shade} from '../../utils/utils'; +import {hexToRGBA, RGB_Linear_Shade} from "../../utils/ColorUtils"; +import {br} from "../../utils/SizeUtils"; export const PressableButton = ({ color, diff --git a/apps/mobile/src/components/ProgressDialog/index.js b/apps/mobile/src/components/ProgressDialog/index.js index 301f5f1ab..c49989fb7 100644 --- a/apps/mobile/src/components/ProgressDialog/index.js +++ b/apps/mobile/src/components/ProgressDialog/index.js @@ -1,12 +1,13 @@ import React, {useEffect, useState} from 'react'; import {Text, View} from 'react-native'; -import {ph, SIZE, WEIGHT} from '../../common/common'; import {useTracked} from '../../provider'; -import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; -import {eOpenProgressDialog, eCloseProgressDialog} from '../../services/events'; -import {DDS, getElevation} from '../../utils/utils'; +import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager'; +import {eOpenProgressDialog, eCloseProgressDialog} from '../../utils/Events'; +import {getElevation} from '../../utils'; import BaseDialog from '../Dialog/base-dialog'; import {Loading} from '../Loading'; +import {ph, SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {DDS} from "../../services/DeviceDetection"; const ProgressDialog = () => { const [state, dispatch] = useTracked(); diff --git a/apps/mobile/src/components/RecoveryKeyDialog/index.js b/apps/mobile/src/components/RecoveryKeyDialog/index.js index 38b0706e5..f30e2a9e1 100644 --- a/apps/mobile/src/components/RecoveryKeyDialog/index.js +++ b/apps/mobile/src/components/RecoveryKeyDialog/index.js @@ -4,14 +4,15 @@ import QRCode from 'react-native-qrcode-svg'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import RNFetchBlob from 'rn-fetch-blob'; import {LOGO_BASE64} from '../../assets/images/assets'; -import {SIZE, WEIGHT} from '../../common/common'; -import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; -import {eOpenRecoveryKeyDialog} from '../../services/events'; -import {db, ToastEvent, w} from '../../utils/utils'; +import {eSubscribeEvent, eUnSubscribeEvent, ToastEvent} from '../../services/EventManager'; +import {eOpenRecoveryKeyDialog} from '../../utils/Events'; +import {dWidth} from '../../utils'; import ActionSheet from '../ActionSheet'; import {Button} from '../Button'; import Seperator from '../Seperator'; import {Toast} from '../Toast'; +import {SIZE, WEIGHT} from "../../utils/SizeUtils"; +import {db} from "../../utils/DB"; class RecoveryKeyDialog extends React.Component { constructor(props) { super(props); @@ -92,7 +93,7 @@ class RecoveryKeyDialog extends React.Component { initialOffsetFromBottom={1}>