2020-01-31 18:22:20 +05:00
|
|
|
import React, {useEffect, useState} from 'react';
|
|
|
|
|
import {TouchableWithoutFeedback, View} from 'react-native';
|
2020-02-11 20:33:36 +05:00
|
|
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
2020-01-31 18:22:20 +05:00
|
|
|
import {SIZE} from '../../common/common';
|
2020-01-24 23:13:09 +05:00
|
|
|
import {useTracked} from '../../provider';
|
|
|
|
|
import {ACTIONS} from '../../provider/actions';
|
2020-02-06 23:38:40 +05:00
|
|
|
import Animated from 'react-native-reanimated';
|
|
|
|
|
|
2020-01-25 00:02:13 +05:00
|
|
|
const SelectionWrapper = ({children, item, currentEditingNote, index}) => {
|
2020-01-17 21:26:01 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
|
|
|
|
const {colors, selectionMode, selectedItemsList} = state;
|
2020-01-31 18:22:20 +05:00
|
|
|
const [selected, setSelected] = useState(false);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
let exists = selectedItemsList.filter(
|
|
|
|
|
o => o.dateCreated === item.dateCreated,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (exists[0]) {
|
|
|
|
|
if (!selected) {
|
|
|
|
|
setSelected(true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (selected) {
|
|
|
|
|
setSelected(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [selectedItemsList]);
|
2020-01-17 00:23:16 +05:00
|
|
|
|
2020-01-13 17:33:41 +05:00
|
|
|
return (
|
2020-02-06 13:08:35 +05:00
|
|
|
<View
|
2020-01-13 17:33:41 +05:00
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
2020-01-22 02:51:24 +05:00
|
|
|
width: '100%',
|
|
|
|
|
paddingHorizontal: 12,
|
2020-01-24 19:36:58 +05:00
|
|
|
backgroundColor:
|
|
|
|
|
currentEditingNote === item.dateCreated
|
|
|
|
|
? colors.shade
|
|
|
|
|
: 'transparent',
|
2020-01-13 17:33:41 +05:00
|
|
|
}}>
|
2020-01-22 02:51:24 +05:00
|
|
|
<View
|
2020-01-13 17:33:41 +05:00
|
|
|
style={{
|
|
|
|
|
display: selectionMode ? 'flex' : 'none',
|
2020-01-17 00:23:16 +05:00
|
|
|
opacity: selectionMode ? 1 : 0,
|
2020-01-31 18:40:56 +05:00
|
|
|
width: '10%',
|
|
|
|
|
height: 70,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingRight: 8,
|
2020-01-13 17:33:41 +05:00
|
|
|
}}>
|
2020-01-31 18:22:20 +05:00
|
|
|
<TouchableWithoutFeedback
|
|
|
|
|
onPress={() => {
|
|
|
|
|
dispatch({type: ACTIONS.SELECTED_ITEMS, item: item});
|
|
|
|
|
}}
|
2020-01-13 17:33:41 +05:00
|
|
|
style={{
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-02-11 20:33:36 +05:00
|
|
|
<Icon
|
2020-02-20 12:17:05 +05:00
|
|
|
size={SIZE.lg}
|
2020-02-11 20:33:36 +05:00
|
|
|
color={colors.accent}
|
|
|
|
|
name={
|
|
|
|
|
selected
|
|
|
|
|
? 'check-circle-outline'
|
|
|
|
|
: 'checkbox-blank-circle-outline'
|
|
|
|
|
}
|
|
|
|
|
/>
|
2020-01-31 18:22:20 +05:00
|
|
|
</TouchableWithoutFeedback>
|
2020-01-22 02:51:24 +05:00
|
|
|
</View>
|
2020-02-06 23:38:40 +05:00
|
|
|
|
2020-01-13 17:33:41 +05:00
|
|
|
{children}
|
2020-02-06 13:08:35 +05:00
|
|
|
</View>
|
2020-01-13 17:33:41 +05:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SelectionWrapper;
|