2020-11-04 20:49:21 +05:00
|
|
|
import React, {useEffect} from 'react';
|
|
|
|
|
import {TouchableOpacity, View} from 'react-native';
|
2020-09-14 17:17:17 +05:00
|
|
|
import Animated, {Easing, useValue} from 'react-native-reanimated';
|
2020-09-09 14:55:59 +05:00
|
|
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
2020-02-11 20:33:36 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-09-09 14:55:59 +05:00
|
|
|
import {useTracked} from '../../provider';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {Actions} from '../../provider/Actions';
|
|
|
|
|
import {eSendEvent, ToastEvent} from '../../services/EventManager';
|
2020-11-04 20:49:21 +05:00
|
|
|
import {db} from '../../utils/DB';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {eOpenMoveNoteDialog, eOpenSimpleDialog} from '../../utils/Events';
|
2020-11-04 20:49:21 +05:00
|
|
|
import {SIZE} from '../../utils/SizeUtils';
|
2020-12-16 11:08:58 +05:00
|
|
|
import {sleep} from '../../utils/TimeUtils';
|
2020-11-04 20:49:21 +05:00
|
|
|
import {ActionIcon} from '../ActionIcon';
|
2020-10-13 17:02:14 +05:00
|
|
|
import {TEMPLATE_DELETE} from '../DialogManager/Templates';
|
2020-11-04 20:49:21 +05:00
|
|
|
import Heading from '../Typography/Heading';
|
2020-01-13 14:47:28 +05:00
|
|
|
|
2020-03-18 11:58:56 +05:00
|
|
|
export const SelectionHeader = () => {
|
2020-01-13 14:47:28 +05:00
|
|
|
// State
|
2020-01-17 21:26:01 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
2020-09-07 19:19:20 +05:00
|
|
|
const {
|
|
|
|
|
colors,
|
|
|
|
|
selectionMode,
|
|
|
|
|
selectedItemsList,
|
|
|
|
|
currentScreen,
|
|
|
|
|
premiumUser,
|
|
|
|
|
} = state;
|
|
|
|
|
const insets = useSafeAreaInsets();
|
|
|
|
|
const translateY = useValue(-150);
|
2020-01-17 21:26:01 +05:00
|
|
|
|
2020-09-07 19:19:20 +05:00
|
|
|
useEffect(() => {
|
2020-09-09 14:55:59 +05:00
|
|
|
Animated.timing(translateY, {
|
|
|
|
|
duration: 300,
|
|
|
|
|
toValue: selectionMode ? 0 : -150,
|
|
|
|
|
easing: Easing.in(Easing.ease),
|
|
|
|
|
}).start();
|
|
|
|
|
}, [selectionMode]);
|
2020-01-13 14:47:28 +05:00
|
|
|
|
2020-09-27 10:15:19 +05:00
|
|
|
return (
|
2020-09-07 19:19:20 +05:00
|
|
|
<Animated.View
|
2020-01-13 14:47:28 +05:00
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
position: 'absolute',
|
2020-11-04 20:49:21 +05:00
|
|
|
height: 50 + insets.top,
|
|
|
|
|
paddingTop: insets.top,
|
2020-01-18 00:46:29 +05:00
|
|
|
backgroundColor: colors.bg,
|
2020-11-04 20:49:21 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
2020-01-31 18:40:56 +05:00
|
|
|
zIndex: 999,
|
2020-01-22 02:51:24 +05:00
|
|
|
paddingHorizontal: 12,
|
2020-01-31 18:40:56 +05:00
|
|
|
transform: [
|
|
|
|
|
{
|
2020-09-07 19:19:20 +05:00
|
|
|
translateY: translateY,
|
2020-01-31 18:40:56 +05:00
|
|
|
},
|
|
|
|
|
],
|
2020-01-13 14:47:28 +05:00
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
2020-11-04 20:49:21 +05:00
|
|
|
justifyContent: 'flex-start',
|
2020-01-13 14:47:28 +05:00
|
|
|
alignItems: 'center',
|
2020-11-04 20:49:21 +05:00
|
|
|
position: 'absolute',
|
|
|
|
|
left: 12,
|
|
|
|
|
paddingTop: insets.top,
|
2020-01-13 14:47:28 +05:00
|
|
|
}}>
|
2020-11-04 20:49:21 +05:00
|
|
|
<ActionIcon
|
|
|
|
|
customStyle={{
|
|
|
|
|
justifyContent: 'center',
|
2020-01-13 14:47:28 +05:00
|
|
|
alignItems: 'center',
|
2020-11-04 20:49:21 +05:00
|
|
|
height: 40,
|
|
|
|
|
width: 40,
|
|
|
|
|
borderRadius: 100,
|
|
|
|
|
marginLeft: -5,
|
|
|
|
|
marginRight: 25,
|
|
|
|
|
}}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
dispatch({type: Actions.SELECTION_MODE, enabled: !selectionMode});
|
|
|
|
|
dispatch({type: Actions.CLEAR_SELECTION});
|
|
|
|
|
}}
|
|
|
|
|
color={colors.heading}
|
|
|
|
|
name="arrow-left"
|
|
|
|
|
size={SIZE.xxxl}
|
|
|
|
|
/>
|
2020-03-02 11:13:40 +05:00
|
|
|
|
2020-11-04 20:49:21 +05:00
|
|
|
{Platform.OS === 'android' ? (
|
|
|
|
|
<Heading>{selectedItemsList.length + ' Selected'}</Heading>
|
|
|
|
|
) : null}
|
|
|
|
|
</View>
|
2020-03-02 11:13:40 +05:00
|
|
|
|
2020-11-04 20:49:21 +05:00
|
|
|
{Platform.OS !== 'android' ? (
|
|
|
|
|
<Heading>{selectedItemsList.length + ' Selected'}</Heading>
|
|
|
|
|
) : null}
|
2020-03-02 11:13:40 +05:00
|
|
|
|
2020-11-04 20:49:21 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
right: 12,
|
|
|
|
|
paddingTop: insets.top,
|
|
|
|
|
}}>
|
2020-12-16 12:10:07 +05:00
|
|
|
{currentScreen === 'trash' ||
|
|
|
|
|
currentScreen === 'notebooks' ||
|
|
|
|
|
currentScreen === 'notebook' ? null : (
|
2020-11-04 20:49:21 +05:00
|
|
|
<ActionIcon
|
2020-12-16 11:08:58 +05:00
|
|
|
onPress={async () => {
|
2020-11-04 20:49:21 +05:00
|
|
|
dispatch({type: Actions.SELECTION_MODE, enabled: false});
|
2020-12-16 11:08:58 +05:00
|
|
|
await sleep(100);
|
2020-11-04 20:49:21 +05:00
|
|
|
eSendEvent(eOpenMoveNoteDialog);
|
|
|
|
|
}}
|
|
|
|
|
customStyle={{
|
|
|
|
|
marginLeft: 10,
|
|
|
|
|
}}
|
|
|
|
|
color={colors.heading}
|
|
|
|
|
name="plus"
|
|
|
|
|
size={SIZE.xl}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-01-13 14:47:28 +05:00
|
|
|
|
2020-11-04 20:49:21 +05:00
|
|
|
{currentScreen === 'trash' ? null : (
|
|
|
|
|
<ActionIcon
|
|
|
|
|
customStyle={{
|
|
|
|
|
marginLeft: 10,
|
|
|
|
|
}}
|
|
|
|
|
onPress={async () => {
|
|
|
|
|
eSendEvent(eOpenSimpleDialog, TEMPLATE_DELETE('item'));
|
|
|
|
|
return;
|
|
|
|
|
}}
|
|
|
|
|
color={colors.heading}
|
|
|
|
|
name="delete"
|
|
|
|
|
size={SIZE.xl}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-02-20 14:45:23 +05:00
|
|
|
|
2020-11-04 20:49:21 +05:00
|
|
|
{currentScreen === 'trash' ? (
|
|
|
|
|
<ActionIcon
|
|
|
|
|
customStyle={{
|
|
|
|
|
marginLeft: 10,
|
|
|
|
|
}}
|
|
|
|
|
color={colors.heading}
|
|
|
|
|
onPress={async () => {
|
|
|
|
|
if (selectedItemsList.length > 0) {
|
|
|
|
|
let noteIds = [];
|
|
|
|
|
selectedItemsList.forEach((item) => {
|
|
|
|
|
noteIds.push(item.id);
|
|
|
|
|
});
|
|
|
|
|
await db.trash.restore(...noteIds);
|
2020-12-16 11:40:51 +05:00
|
|
|
dispatch({type: Actions.NOTEBOOKS});
|
|
|
|
|
dispatch({type: Actions.NOTES});
|
2020-11-04 20:49:21 +05:00
|
|
|
dispatch({type: Actions.TRASH});
|
|
|
|
|
dispatch({type: Actions.SELECTION_MODE, enabled: false});
|
|
|
|
|
dispatch({type: Actions.CLEAR_SELECTION});
|
|
|
|
|
ToastEvent.show('Restore complete', 'success');
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
name="delete-restore"
|
|
|
|
|
size={SIZE.xl - 3}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2020-01-13 14:47:28 +05:00
|
|
|
</View>
|
2020-09-07 19:19:20 +05:00
|
|
|
</Animated.View>
|
2020-01-13 14:47:28 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SelectionHeader;
|