Skip to content

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

add multi-select functions

ammarahm-ed5a4c835ae0f2
diff --git a/apps/mobile/src/components/SelectionHeader/index.js b/apps/mobile/src/components/SelectionHeader/index.js
index c073f791c..e1e847109 100644
--- a/apps/mobile/src/components/SelectionHeader/index.js
+++ b/apps/mobile/src/components/SelectionHeader/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useEffect} from 'react';
import {
Platform,
SafeAreaView,
@@ -12,9 +12,10 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {SIZE, WEIGHT} from '../../common/common';
import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions';
-import {w} from '../../utils/utils';
+import {w, ToastEvent} from '../../utils/utils';
import {eSendEvent} from '../../services/eventManager';
import {eOpenMoveNoteDialog} from '../../services/events';
+import {db} from '../../../App';
export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
SafeAreaView,
@@ -23,9 +24,11 @@ export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
export const SelectionHeader = ({navigation}) => {
// State
const [state, dispatch] = useTracked();
- const {colors, selectionMode, selectedItemsList} = state;
+ const {colors, selectionMode, selectedItemsList, currentScreen} = state;
- // Render
+ useEffect(() => {
+ console.log(currentScreen);
+ }, [currentScreen]);
return (
<Animatable.View
@@ -98,42 +101,111 @@ export const SelectionHeader = ({navigation}) => {
justifyContent: 'space-between',
alignItems: 'center',
}}>
- <TouchableOpacity
- onPress={() => {
- dispatch({type: ACTIONS.SELECTION_MODE, enabled: false});
- eSendEvent(eOpenMoveNoteDialog);
- }}>
- <Icon
- style={{
- paddingLeft: 25,
- }}
- color={colors.accent}
- name={'plus'}
- size={SIZE.xl}
- />
- </TouchableOpacity>
+ {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : (
+ <TouchableOpacity
+ onPress={() => {
+ dispatch({type: ACTIONS.SELECTION_MODE, enabled: false});
+ eSendEvent(eOpenMoveNoteDialog);
+ }}>
+ <Icon
+ style={{
+ paddingLeft: 25,
+ }}
+ color={colors.accent}
+ name={'plus'}
+ size={SIZE.xl}
+ />
+ </TouchableOpacity>
+ )}
+ {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : (
+ <TouchableOpacity
+ onPress={async () => {
+ if (selectedItemsList.length > 0) {
+ selectedItemsList.forEach(async item => {
+ await db.notes.note(item.id).favorite();
+ });
+ dispatch({type: ACTIONS.SELECTION_MODE, enabled: false});
+ dispatch({type: ACTIONS.NOTES});
+ dispatch({type: ACTIONS.CLEAR_SELECTION});
+ ToastEvent.show('Notes added to favorites');
+ }
+ }}>
+ <Icon
+ style={{
+ paddingLeft: 25,
+ }}
+ color={colors.accent}
+ name={'star'}
+ size={SIZE.xl - 3}
+ />
+ </TouchableOpacity>
+ )}
- <TouchableOpacity>
- <Icon
- style={{
- paddingLeft: 25,
- }}
- color={colors.accent}
- name={'star'}
- size={SIZE.xl - 3}
- />
- </TouchableOpacity>
+ {currentScreen === 'trash' ? null : (
+ <TouchableOpacity
+ onPress={async () => {
+ if (selectedItemsList.length > 0) {
+ let noteIds = [];
+ selectedItemsList.forEach(item => {
+ noteIds.push(item.id);
+ });
+ if (currentScreen === 'notebooks') {
+ await db.notebooks.delete(...noteIds);
+ dispatch({type: ACTIONS.NOTEBOOKS});
+ ToastEvent.show('Notebooks moved to trash');
+ } else if (currentScreen === 'notebook') {
+ ToastEvent.show('Topics moved to trash');
+ // TODO
+ } else {
+ await db.notes.delete(...noteIds);
+ dispatch({type: ACTIONS.NOTES});
+ ToastEvent.show('Notes moved to trash');
+ }
- <TouchableOpacity>
- <Icon
- style={{
- paddingLeft: 25,
- }}
- color={colors.errorText}
- name={'delete'}
- size={SIZE.xl - 3}
- />
- </TouchableOpacity>
+ dispatch({type: ACTIONS.SELECTION_MODE, enabled: false});
+
+ dispatch({type: ACTIONS.CLEAR_SELECTION});
+ }
+ }}>
+ <Icon
+ style={{
+ paddingLeft: 25,
+ }}
+ color={colors.errorText}
+ name={'delete'}
+ size={SIZE.xl - 3}
+ />
+ </TouchableOpacity>
+ )}
+
+ {currentScreen === 'trash' ? (
+ <TouchableOpacity
+ onPress={async () => {
+ if (selectedItemsList.length > 0) {
+ let noteIds = [];
+ selectedItemsList.forEach(item => {
+ noteIds.push(item.id);
+ });
+
+ await db.trash.restore(...noteIds);
+ console.log(noteIds);
+ dispatch({type: ACTIONS.TRASH});
+ dispatch({type: ACTIONS.SELECTION_MODE, enabled: false});
+
+ dispatch({type: ACTIONS.CLEAR_SELECTION});
+ ToastEvent.show('Notes moved to trash');
+ }
+ }}>
+ <Icon
+ style={{
+ paddingLeft: 25,
+ }}
+ color={colors.errorText}
+ name="delete-restore"
+ size={SIZE.xl - 3}
+ />
+ </TouchableOpacity>
+ ) : null}
</View>
</View>
</Animatable.View>
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 708466c34..746d4def2 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -17,6 +17,10 @@ export const Favorites = ({navigation}) => {
const {colors, selectionMode, favorites} = state;
const [refreshing, setRefreshing] = useState(false);
useEffect(() => {
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'favorites',
+ });
dispatch({type: ACTIONS.FAVORITES});
}, []);
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 8d7573101..f51edd1b0 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -45,6 +45,15 @@ export const Folders = ({navigation}) => {
eSendEvent(eScrollEvent, 0);
dispatch({type: ACTIONS.NOTEBOOKS});
+ if (isFocused) {
+ if (isFocused) {
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'notebooks',
+ });
+ }
+ }
+
let backhandler;
if (isFocused) {
backhandler = BackHandler.addEventListener(
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 2d412d55a..380a047d8 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -23,6 +23,13 @@ export const Home = ({navigation}) => {
const isFocused = useIsFocused();
useEffect(() => {
+ if (isFocused) {
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'home',
+ });
+ }
+
eSendEvent(eScrollEvent, 0);
dispatch({type: ACTIONS.COLORS});
dispatch({type: ACTIONS.NOTES});
diff --git a/apps/mobile/src/views/Login/index.js b/apps/mobile/src/views/Login/index.js
index ceb3241e2..8102b07d4 100644
--- a/apps/mobile/src/views/Login/index.js
+++ b/apps/mobile/src/views/Login/index.js
@@ -83,15 +83,18 @@ export const Login = ({navigation}) => {
}, 500);
}, 300);
setStatus('Logging in...');
+
if (!invalidPassword && !invalidUsername) {
try {
+ console.log('here reacched');
await db.user.login(username, password);
} catch (e) {
- console.log(e);
+ console.log(e, 'ERROR');
setLoggingIn(false);
}
let user;
+ console.log(await db.user.get());
try {
user = await db.user.get();
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 9117cedfe..127794dec 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -19,6 +19,7 @@ import {
eScrollEvent,
} from '../../services/events';
import {ToastEvent, w} from '../../utils/utils';
+import {ACTIONS} from '../../provider/actions';
export const Notebook = ({navigation}) => {
const [state, dispatch] = useTracked();
@@ -61,6 +62,13 @@ export const Notebook = ({navigation}) => {
};
useEffect(() => {
+ if (isFocused) {
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'notebook',
+ });
+ }
+
eSubscribeEvent(eMoveNoteDialogNavigateBack, handleBackPress);
return () => {
eUnSubscribeEvent(eMoveNoteDialogNavigateBack, handleBackPress);
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index e1032eb70..c89f3730e 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -24,6 +24,10 @@ export const Tags = ({navigation}) => {
const [refreshing, setRefreshing] = useState(false);
useEffect(() => {
dispatch({type: ACTIONS.TAGS});
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'tags',
+ });
}, []);
return (
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index d16ccc883..40a06407a 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -22,7 +22,11 @@ export const Trash = ({navigation}) => {
dispatch({
type: ACTIONS.TRASH,
});
- console.log(trash);
+
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'trash',
+ });
}, []);
const _renderItem = ({item, index}) => (