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 ( { justifyContent: 'space-between', alignItems: 'center', }}> - { - dispatch({type: ACTIONS.SELECTION_MODE, enabled: false}); - eSendEvent(eOpenMoveNoteDialog); - }}> - - + {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : ( + { + dispatch({type: ACTIONS.SELECTION_MODE, enabled: false}); + eSendEvent(eOpenMoveNoteDialog); + }}> + + + )} + {currentScreen === 'trash' || currentScreen === 'notebooks' ? null : ( + { + 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'); + } + }}> + + + )} - - - + {currentScreen === 'trash' ? null : ( + { + 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'); + } - - - + dispatch({type: ACTIONS.SELECTION_MODE, enabled: false}); + + dispatch({type: ACTIONS.CLEAR_SELECTION}); + } + }}> + + + )} + + {currentScreen === 'trash' ? ( + { + 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'); + } + }}> + + + ) : null} 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}) => (