2020-12-16 14:57:58 +05:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
|
import { View } from 'react-native';
|
|
|
|
|
import Animated, { Easing, useValue } from 'react-native-reanimated';
|
|
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
|
|
import { useTracked } from '../../provider';
|
|
|
|
|
import { Actions } from '../../provider/Actions';
|
|
|
|
|
import { eSendEvent, ToastEvent } from '../../services/EventManager';
|
|
|
|
|
import { db } from '../../utils/DB';
|
2020-12-16 13:12:35 +05:00
|
|
|
import {
|
|
|
|
|
eOpenMoveNoteDialog,
|
|
|
|
|
eOpenSimpleDialog,
|
2020-12-16 14:57:58 +05:00
|
|
|
refreshNotesPage
|
2020-12-16 13:12:35 +05:00
|
|
|
} from '../../utils/Events';
|
2020-12-16 14:57:58 +05:00
|
|
|
import { SIZE } from '../../utils/SizeUtils';
|
|
|
|
|
import { sleep } from '../../utils/TimeUtils';
|
|
|
|
|
import { ActionIcon } from '../ActionIcon';
|
|
|
|
|
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-12-16 13:12:35 +05:00
|
|
|
{currentScreen === 'favorites' ? (
|
|
|
|
|
<ActionIcon
|
|
|
|
|
onPress={async () => {
|
|
|
|
|
if (selectedItemsList.length > 0) {
|
|
|
|
|
selectedItemsList.forEach((item) => {
|
|
|
|
|
db.notes.note(item.id).favorite();
|
|
|
|
|
});
|
|
|
|
|
dispatch({type: Actions.FAVORITES});
|
|
|
|
|
eSendEvent(refreshNotesPage);
|
|
|
|
|
dispatch({type: Actions.NOTES});
|
|
|
|
|
dispatch({type: Actions.SELECTION_MODE, enabled: false});
|
|
|
|
|
dispatch({type: Actions.CLEAR_SELECTION});
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
customStyle={{
|
|
|
|
|
marginLeft: 10,
|
|
|
|
|
}}
|
|
|
|
|
color={colors.heading}
|
|
|
|
|
name="star-off"
|
|
|
|
|
size={SIZE.xl}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
|
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;
|