Skip to content

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

refactor

ammarahm-ed7ff66aa4b32c
diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js
index fd9527ef4..069c93db4 100644
--- a/apps/mobile/src/components/ActionSheetComponent/index.js
+++ b/apps/mobile/src/components/ActionSheetComponent/index.js
@@ -21,7 +21,8 @@ import {
SIZE,
WEIGHT,
} from '../../common/common';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {
moveNoteEvent,
_recieveEvent,
diff --git a/apps/mobile/src/components/AddNotebookDialog/index.js b/apps/mobile/src/components/AddNotebookDialog/index.js
index b0c5cf4d7..817759b9d 100644
--- a/apps/mobile/src/components/AddNotebookDialog/index.js
+++ b/apps/mobile/src/components/AddNotebookDialog/index.js
@@ -11,7 +11,7 @@ import {FlatList, TextInput} from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/Feather';
import {db, DDS} from '../../../App';
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
-import {ACTIONS} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {getElevation, ToastEvent} from '../../utils/utils';
import {updateEvent} from '../DialogManager';
diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.js
index eb059fe52..0e2c1bcad 100644
--- a/apps/mobile/src/components/Dialog/index.js
+++ b/apps/mobile/src/components/Dialog/index.js
@@ -9,7 +9,7 @@ import {
import Icon from 'react-native-vector-icons/Feather';
import {db, DDS} from '../../../App';
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
-import {ACTIONS} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService';
import {getElevation, ToastEvent} from '../../utils/utils';
import {dialogActions, updateEvent} from '../DialogManager';
diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.js
index 8e8541184..729c06a91 100644
--- a/apps/mobile/src/components/DialogManager/index.js
+++ b/apps/mobile/src/components/DialogManager/index.js
@@ -346,6 +346,7 @@ export class DialogManager extends Component {
DDS.isTab
? {
borderRadius: 10,
+ backgroundColor: colors.bg,
}
: null
}
diff --git a/apps/mobile/src/components/EditorMenu/index.js b/apps/mobile/src/components/EditorMenu/index.js
index 976c9cdee..c8867a5c0 100644
--- a/apps/mobile/src/components/EditorMenu/index.js
+++ b/apps/mobile/src/components/EditorMenu/index.js
@@ -1,7 +1,6 @@
import React, {useState, useEffect} from 'react';
import {
ActivityIndicator,
- FlatList,
KeyboardAvoidingView,
Platform,
ScrollView,
@@ -21,9 +20,9 @@ import {
SIZE,
WEIGHT,
} from '../../common/common';
-import {useTracked, ACTIONS} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {AnimatedSafeAreaView} from '../../views/Home';
-import {VaultDialog} from '../VaultDialog';
import {db} from '../../../App';
import {w} from '../../utils/utils';
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 68c3edded..299c539d9 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -2,10 +2,7 @@ import React from 'react';
import {Modal, DeviceEventEmitter, View, TouchableOpacity} from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
-import {ACTIONS} from '../../provider';
-import Folders from '../../views/Folders';
-import Notebook from '../../views/Notebook';
-import Notes from '../../views/Notes';
+import {ACTIONS} from '../../provider/actions';
import {updateEvent} from '../DialogManager';
import * as Animatable from 'react-native-animatable';
import Login from '../../views/Login';
diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js
index 6809b87c8..e1b4605d4 100644
--- a/apps/mobile/src/components/Menu/index.js
+++ b/apps/mobile/src/components/Menu/index.js
@@ -21,7 +21,8 @@ import {
SIZE,
WEIGHT,
} from '../../common/common';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService';
import {AnimatedSafeAreaView} from '../../views/Home';
import {DDS} from '../../../App';
diff --git a/apps/mobile/src/components/ModalMenu/index.js b/apps/mobile/src/components/ModalMenu/index.js
index aa8755b63..1bd9353cf 100644
--- a/apps/mobile/src/components/ModalMenu/index.js
+++ b/apps/mobile/src/components/ModalMenu/index.js
@@ -1,18 +1,7 @@
import React, {Component} from 'react';
-import {
- Modal,
- Text,
- TouchableOpacity,
- View,
- DeviceEventEmitter,
-} from 'react-native';
-import Icon from 'react-native-vector-icons/Feather';
-import {db} from '../../../App';
-import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
-import {ACTIONS} from '../../provider';
-import NavigationService from '../../services/NavigationService';
-import {getElevation, ToastEvent, w} from '../../utils/utils';
-import {dialogActions, updateEvent} from '../DialogManager';
+import {Modal, TouchableOpacity, View, DeviceEventEmitter} from 'react-native';
+import {ACTIONS} from '../../provider/actions';
+import {getElevation, w} from '../../utils/utils';
import * as Animatable from 'react-native-animatable';
import {Menu} from '../Menu';
diff --git a/apps/mobile/src/components/MoveNoteDialog/index.js b/apps/mobile/src/components/MoveNoteDialog/index.js
index 2e6b42ae7..982cb6604 100644
--- a/apps/mobile/src/components/MoveNoteDialog/index.js
+++ b/apps/mobile/src/components/MoveNoteDialog/index.js
@@ -2,7 +2,7 @@ import React from 'react';
import {Modal, DeviceEventEmitter, View, TouchableOpacity} from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
-import {ACTIONS} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import Folders from '../../views/Folders';
import Notebook from '../../views/Notebook';
import Notes from '../../views/Notes';
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index 2c65f8441..ef46f2b1f 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -1,7 +1,8 @@
import React, {useEffect} from 'react';
import {FlatList, Platform, SectionList, Text, View} from 'react-native';
import {SIZE, WEIGHT} from '../../common/common';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {slideLeft, slideRight} from '../../utils/animations';
import {w} from '../../utils/utils';
import {NotesPlaceHolder} from '../ListPlaceholders';
diff --git a/apps/mobile/src/components/SelectionHeader/index.js b/apps/mobile/src/components/SelectionHeader/index.js
index b15e48d81..13228307a 100644
--- a/apps/mobile/src/components/SelectionHeader/index.js
+++ b/apps/mobile/src/components/SelectionHeader/index.js
@@ -10,7 +10,8 @@ import {
import * as Animatable from 'react-native-animatable';
import Icon from 'react-native-vector-icons/Feather';
import {SIZE, WEIGHT} from '../../common/common';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {w} from '../../utils/utils';
export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
diff --git a/apps/mobile/src/components/SelectionWrapper/index.js b/apps/mobile/src/components/SelectionWrapper/index.js
index b8d53f9d0..11eea2090 100644
--- a/apps/mobile/src/components/SelectionWrapper/index.js
+++ b/apps/mobile/src/components/SelectionWrapper/index.js
@@ -3,7 +3,8 @@ import {View, TouchableOpacity} from 'react-native';
import {SIZE} from '../../common/common';
import Icon from 'react-native-vector-icons/Feather';
import {w} from '../../utils/utils';
-import {useTracked, ACTIONS} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
const SelectionWrapper = ({children, item, currentEditingNote}) => {
const [state, dispatch] = useTracked();
diff --git a/apps/mobile/src/provider/actions.js b/apps/mobile/src/provider/actions.js
new file mode 100644
index 000000000..7ef8380bd
--- /dev/null
+++ b/apps/mobile/src/provider/actions.js
@@ -0,0 +1,15 @@
+export const ACTIONS = {
+ NOTES: 'note',
+ NOTEBOOKS: 'notebook',
+ TRASH: 'trash',
+ TAGS: 'tags',
+ PINNED: 'pinned',
+ FAVORITES: 'favorites',
+ SELECTION_MODE: 'selectionMode',
+ SELECTED_ITEMS: 'selectedItemsList',
+ THEME: 'theme',
+ MODAL_NAVIGATOR: 'modalNavigator',
+ CLEAR_SELECTION: 'clearSelection',
+ LOGIN_NAVIGATOR: 'loginNavigator',
+ CURRENT_EDITING_NOTE: 'currentEditingNote',
+};
diff --git a/apps/mobile/src/provider/defaultState.js b/apps/mobile/src/provider/defaultState.js
new file mode 100644
index 000000000..12b6775e4
--- /dev/null
+++ b/apps/mobile/src/provider/defaultState.js
@@ -0,0 +1,35 @@
+export const defaultState = {
+ isMenuOpen: {
+ current: false,
+ },
+ selectionMode: false,
+ selectedItemsList: [],
+ notes: [],
+ notebooks: [],
+ trash: [],
+ favorites: [],
+ pinned: [],
+ tags: [],
+ colors: {
+ night: false,
+ bg: 'white',
+ fg: '#0560FF',
+ navbg: '#f6fbfc',
+ nav: '#f0f0f0',
+ pri: 'black',
+ sec: 'white',
+ accent: '#0560FF',
+ shade: '#0560FF12',
+ normal: 'black',
+ icon: 'gray',
+ errorBg: '#FFD2D2',
+ errorText: '#D8000C',
+ successBg: '#DFF2BF',
+ successText: '#4F8A10',
+ warningBg: '#FEEFB3',
+ warningText: '#9F6000',
+ },
+ preventDefaultMargins: false,
+ isLoginNavigator: false,
+ currenEditingNote: null,
+};
diff --git a/apps/mobile/src/provider/index.js b/apps/mobile/src/provider/index.js
index 2d44369fd..587bc5e65 100644
--- a/apps/mobile/src/provider/index.js
+++ b/apps/mobile/src/provider/index.js
@@ -1,154 +1,7 @@
import {useReducer} from 'react';
-import {db} from '../../App';
import {createContainer} from 'react-tracked';
-import {SideMenuEvent} from '../utils/utils';
-const defaultState = {
- isMenuOpen: {
- current: false,
- },
- selectionMode: false,
- selectedItemsList: [],
- notes: [],
- notebooks: [],
- trash: [],
- favorites: [],
- pinned: [],
- tags: [],
- colors: {
- night: false,
- bg: 'white',
- fg: '#0560FF',
- navbg: '#f6fbfc',
- nav: '#f0f0f0',
- pri: 'black',
- sec: 'white',
- accent: '#0560FF',
- shade: '#0560FF12',
- normal: 'black',
- icon: 'gray',
- errorBg: '#FFD2D2',
- errorText: '#D8000C',
- successBg: '#DFF2BF',
- successText: '#4F8A10',
- warningBg: '#FEEFB3',
- warningText: '#9F6000',
- },
- preventDefaultMargins: false,
- isLoginNavigator: false,
- currenEditingNote: null,
-};
-
-export const ACTIONS = {
- NOTES: 'note',
- NOTEBOOKS: 'notebook',
- TRASH: 'trash',
- TAGS: 'tags',
- PINNED: 'pinned',
- FAVORITES: 'favorites',
- SELECTION_MODE: 'selectionMode',
- SELECTED_ITEMS: 'selectedItemsList',
- THEME: 'theme',
- MODAL_NAVIGATOR: 'modalNavigator',
- CLEAR_SELECTION: 'clearSelection',
- LOGIN_NAVIGATOR: 'loginNavigator',
- CURRENT_EDITING_NOTE: 'currentEditingNote',
-};
-
-const reducer = (state, action) => {
- switch (action.type) {
- case ACTIONS.NOTES:
- let notes = db.groupNotes();
- return {
- ...state,
- notes: notes,
- };
- case ACTIONS.THEME: {
- return {
- ...state,
- colors: {...action.colors},
- };
- }
- case ACTIONS.NOTEBOOKS: {
- let notebooks = [...db.getNotebooks()];
- return {
- ...state,
- notebooks: notebooks,
- };
- }
- case ACTIONS.PINNED: {
- let pinned = [...db.getPinned()];
- return {
- ...state,
- pinned: pinned,
- };
- }
- case ACTIONS.TAGS: {
- return {
- ...state,
- };
- }
- case ACTIONS.FAVORITES: {
- let favorites = [...db.getFavorites()];
-
- return {
- ...state,
- favorites: [...favorites],
- };
- }
- case ACTIONS.SELECTION_MODE: {
- if (action.enabled) {
- SideMenuEvent.disable();
- } else {
- SideMenuEvent.enable();
- }
-
- return {
- ...state,
- selectionMode: action.enabled,
- selectedItemsList: [],
- };
- }
- case ACTIONS.SELECTED_ITEMS: {
- let selectedItems = [...state.selectedItemsList];
- if (selectedItems.includes(action.item)) {
- selectedItems.splice(selectedItems.indexOf(action.item), 1);
- } else {
- selectedItems.push(action.item);
- }
- console.log(action.item, selectedItems);
- return {
- ...state,
- selectedItemsList: selectedItems,
- };
- }
- case ACTIONS.CLEAR_SELECTION: {
- return {
- ...state,
- selectedItemsList: [],
- };
- }
- case ACTIONS.MODAL_NAVIGATOR: {
- return {
- ...state,
- preventDefaultMargins: action.enabled,
- };
- }
- case ACTIONS.LOGIN_NAVIGATOR: {
- return {
- ...state,
- isLoginNavigator: action.enabled,
- };
- }
- case ACTIONS.CURRENT_EDITING_NOTE: {
- return {
- ...state,
- currentEditingNote: action.dateCreated,
- };
- }
- default:
- throw new Error('unknown action type');
- }
-};
+import {reducer} from './reducer';
+import {defaultState} from './defaultState';
const useValue = () => useReducer(reducer, defaultState);
diff --git a/apps/mobile/src/provider/reducer.js b/apps/mobile/src/provider/reducer.js
new file mode 100644
index 000000000..af03deaec
--- /dev/null
+++ b/apps/mobile/src/provider/reducer.js
@@ -0,0 +1,99 @@
+import {db} from '../../App';
+import {SideMenuEvent} from '../utils/utils';
+import {ACTIONS} from './actions';
+
+export const reducer = (state, action) => {
+ switch (action.type) {
+ case ACTIONS.NOTES:
+ let notes = db.groupNotes();
+ return {
+ ...state,
+ notes: notes,
+ };
+ case ACTIONS.THEME: {
+ return {
+ ...state,
+ colors: {...action.colors},
+ };
+ }
+ case ACTIONS.NOTEBOOKS: {
+ let notebooks = [...db.getNotebooks()];
+ return {
+ ...state,
+ notebooks: notebooks,
+ };
+ }
+ case ACTIONS.PINNED: {
+ let pinned = [...db.getPinned()];
+ return {
+ ...state,
+ pinned: pinned,
+ };
+ }
+ case ACTIONS.TAGS: {
+ return {
+ ...state,
+ };
+ }
+ case ACTIONS.FAVORITES: {
+ let favorites = [...db.getFavorites()];
+
+ return {
+ ...state,
+ favorites: [...favorites],
+ };
+ }
+ case ACTIONS.SELECTION_MODE: {
+ if (action.enabled) {
+ SideMenuEvent.disable();
+ } else {
+ SideMenuEvent.enable();
+ }
+
+ return {
+ ...state,
+ selectionMode: action.enabled,
+ selectedItemsList: [],
+ };
+ }
+ case ACTIONS.SELECTED_ITEMS: {
+ let selectedItems = [...state.selectedItemsList];
+ if (selectedItems.includes(action.item)) {
+ selectedItems.splice(selectedItems.indexOf(action.item), 1);
+ } else {
+ selectedItems.push(action.item);
+ }
+ console.log(action.item, selectedItems);
+ return {
+ ...state,
+ selectedItemsList: selectedItems,
+ };
+ }
+ case ACTIONS.CLEAR_SELECTION: {
+ return {
+ ...state,
+ selectedItemsList: [],
+ };
+ }
+ case ACTIONS.MODAL_NAVIGATOR: {
+ return {
+ ...state,
+ preventDefaultMargins: action.enabled,
+ };
+ }
+ case ACTIONS.LOGIN_NAVIGATOR: {
+ return {
+ ...state,
+ isLoginNavigator: action.enabled,
+ };
+ }
+ case ACTIONS.CURRENT_EDITING_NOTE: {
+ return {
+ ...state,
+ currentEditingNote: action.dateCreated,
+ };
+ }
+ default:
+ throw new Error('unknown action type');
+ }
+};
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index a99c36b1d..109b65a22 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -24,7 +24,8 @@ import {
_unSubscribeEvent,
TEMPLATE_EXIT_FULLSCREEN,
} from '../../components/DialogManager';
-import {useTracked, ACTIONS} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {SideMenuEvent, w, h} from '../../utils/utils';
import {AnimatedSafeAreaView} from '../Home';
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 65e082b06..ed564c921 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -9,7 +9,8 @@ import {NotebookItem} from '../../components/NotebookItem';
import NoteItem from '../../components/NoteItem';
import {Search} from '../../components/SearchInput';
import SelectionWrapper from '../../components/SelectionWrapper';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
export const Favorites = ({navigation}) => {
// Global State
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 7f9e02e29..e53c8a10a 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -11,7 +11,8 @@ import {NotebookItem} from '../../components/NotebookItem';
import {Search} from '../../components/SearchInput';
import SelectionHeader from '../../components/SelectionHeader';
import SelectionWrapper from '../../components/SelectionWrapper';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {slideLeft, slideRight} from '../../utils/animations';
import {w} from '../../utils/utils';
import {AddNotebookEvent} from '../../components/DialogManager';
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 3f8e7e93a..cdac98087 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -7,7 +7,8 @@ import {Header} from '../../components/header';
import {NotesList} from '../../components/NotesList';
import {Search} from '../../components/SearchInput';
import SelectionHeader from '../../components/SelectionHeader';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService';
import {SideMenuEvent, ToastEvent} from '../../utils/utils';
import {useIsFocused} from 'react-navigation-hooks';
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 191711111..40614807d 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -22,7 +22,8 @@ import {
} from '../../common/common';
import Container from '../../components/Container';
import {Header} from '../../components/header';
-import {useTracked, ACTIONS} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService';
export const Settings = ({navigation}) => {
const [state, dispatch] = useTracked();
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 12796e644..803e6bad5 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -11,7 +11,8 @@ import {TrashPlaceHolder} from '../../components/ListPlaceholders';
import {NotebookItem} from '../../components/NotebookItem';
import NoteItem from '../../components/NoteItem';
import SelectionHeader from '../../components/SelectionHeader';
-import {ACTIONS, useTracked} from '../../provider';
+import {useTracked} from '../../provider';
+import {ACTIONS} from '../../provider/actions';
import {w} from '../../utils/utils';
export const Trash = ({navigation}) => {