From dede82d1a3beda27d98568dee92f45bac04f2cd6 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 18 Mar 2020 11:58:56 +0500 Subject: [PATCH] add selectAll to multi-select --- apps/mobile/src/components/Container/index.js | 6 ++- .../src/components/SelectionHeader/index.js | 52 ++++++++++++++++--- apps/mobile/src/provider/actions.js | 1 + apps/mobile/src/provider/reducer.js | 8 +++ apps/mobile/src/utils/utils.js | 5 ++ 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/apps/mobile/src/components/Container/index.js b/apps/mobile/src/components/Container/index.js index 2bb10ed8f..cb9bf8006 100644 --- a/apps/mobile/src/components/Container/index.js +++ b/apps/mobile/src/components/Container/index.js @@ -15,7 +15,7 @@ import {useTracked} from '../../provider'; import {ACTIONS} from '../../provider/actions'; import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager'; import {eScrollEvent, eClearSearch} from '../../services/events'; -import {db, getElevation, ToastEvent, DDS} from '../../utils/utils'; +import {db, getElevation, ToastEvent, DDS, selection} from '../../utils/utils'; import {Header} from '../header'; import {Search, inputRef} from '../SearchInput'; import SelectionHeader from '../SelectionHeader'; @@ -171,6 +171,8 @@ export const Container = ({ }, []); useEffect(() => { + selection.data = data; + selection.type = type; eSubscribeEvent(eScrollEvent, onScroll); return () => { @@ -194,7 +196,7 @@ export const Container = ({ style={{ height: '100%', }}> - {noSelectionHeader ? null : } + {noSelectionHeader ? null : } { +export const SelectionHeader = () => { // State const [state, dispatch] = useTracked(); const {colors, selectionMode, selectedItemsList, currentScreen} = state; + const [selectAll, setSelectAll] = useState(false); useEffect(() => { + console.log(selection.data, selection.type); console.log(currentScreen); }, [currentScreen]); @@ -38,7 +40,7 @@ export const SelectionHeader = ({navigation}) => { style={{ width: '100%', position: 'absolute', - height: Platform.OS === 'android' ? 50 + StatusBar.currentHeight : 50, + height: Platform.OS === 'android' ? 80 + StatusBar.currentHeight : 80, backgroundColor: colors.bg, paddingTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight, justifyContent: 'flex-end', @@ -67,7 +69,6 @@ export const SelectionHeader = ({navigation}) => { { dispatch({type: ACTIONS.SELECTION_MODE, enabled: !selectionMode}); - dispatch({type: ACTIONS.CLEAR_SELECTION}); }} hitSlop={{top: 20, bottom: 20, left: 50, right: 40}} @@ -86,6 +87,7 @@ export const SelectionHeader = ({navigation}) => { size={SIZE.xxxl} /> + { color: colors.pri, textAlignVertical: 'center', }}> - {selectedItemsList.length} + {selectAll ? 'All' : selectedItemsList.length} @@ -227,6 +229,44 @@ export const SelectionHeader = ({navigation}) => { ) : null} + + { + if (selectAll) { + dispatch({type: ACTIONS.SELECT_ALL, selected: []}); + } else { + dispatch({ + type: ACTIONS.SELECT_ALL, + selected: + selection.type === 'notes' ? db.notes.all : selection.data, + }); + } + + setSelectAll(!selectAll); + }} + hitSlop={{top: 20, bottom: 20, left: 20, right: 40}} + style={{ + justifyContent: 'center', + alignItems: 'center', + height: 40, + flexDirection: 'row', + alignSelf: 'flex-start', + }}> + + + Select All + + ); }; diff --git a/apps/mobile/src/provider/actions.js b/apps/mobile/src/provider/actions.js index d6256cca5..31f046fb2 100644 --- a/apps/mobile/src/provider/actions.js +++ b/apps/mobile/src/provider/actions.js @@ -17,4 +17,5 @@ export const ACTIONS = { USER: 'getUser', CURRENT_SCREEN: 'currentScreen', SETTINGS: 'getSettings', + SELECT_ALL: 'selectAll', }; diff --git a/apps/mobile/src/provider/reducer.js b/apps/mobile/src/provider/reducer.js index b254eb14a..4b7f88cfc 100644 --- a/apps/mobile/src/provider/reducer.js +++ b/apps/mobile/src/provider/reducer.js @@ -96,6 +96,14 @@ export const reducer = (state, action) => { selectionMode: action.enabled, }; } + case ACTIONS.SELECT_ALL: { + console.log(action.selected); + + return { + ...state, + selectedItemsList: action.selected, + }; + } case ACTIONS.SELECTED_ITEMS: { let selectedItems = [...state.selectedItemsList]; if (selectedItems.includes(action.item)) { diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.js index 0bff4e2a2..be680eaec 100755 --- a/apps/mobile/src/utils/utils.js +++ b/apps/mobile/src/utils/utils.js @@ -31,6 +31,11 @@ export const editing = { type: null, }, }; +export const selection = { + data: [], + type: null, + selectedItems: [], +}; export const history = { selectedItemsList: [],