Files
notesnook/apps/mobile/src/components/SelectionWrapper/index.js

186 lines
5.0 KiB
JavaScript
Raw Normal View History

2020-09-10 10:35:02 +05:00
import React, {useEffect, useState} from 'react';
import {TouchableOpacity, View} from 'react-native';
2020-02-11 20:33:36 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-09-10 10:35:02 +05:00
import {useTracked} from '../../provider';
2020-12-16 20:01:02 +05:00
import {DDS} from '../../services/DeviceDetection';
2020-11-14 10:06:41 +05:00
import {COLORS_NOTE} from '../../utils/Colors';
2020-12-16 20:01:02 +05:00
import {hexToRGBA, RGB_Linear_Shade} from '../../utils/ColorUtils';
2020-11-14 10:06:41 +05:00
import {SIZE} from '../../utils/SizeUtils';
2020-09-10 10:35:02 +05:00
import {PressableButton} from '../PressableButton';
2020-12-16 20:01:02 +05:00
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
const Filler = ({item, background}) => {
const [state] = useTracked();
const {colors, currentEditingNote} = state;
const color = item.color || 'accent';
return (
<View
style={{
/* backgroundColor: DDS.isLargeTablet()
? currentEditingNote === item.id
? item.type === 'note' && item.color
? COLORS_NOTE[item.color]
: colors.shade
: background
? background
: 'transparent'
: 'transparent', */
position: 'absolute',
width: '110%',
height: '110%',
paddingVertical: '3.5%',
paddingHorizontal: '5%',
alignItems: 'flex-end',
justifyContent: 'flex-end',
}}>
<View
style={{
flexDirection: 'row',
}}>
{item.conflicted ? (
<View
style={{
backgroundColor: hexToRGBA(colors.red, 0.12),
paddingHorizontal: 3,
paddingVertical: 2,
borderRadius: 3,
marginRight: 10,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
}}>
<Icon name="alert-circle" size={SIZE.xxs} color={colors.red} />
<Heading
size={SIZE.xxs}
style={{
color: colors.red,
marginLeft: 5,
}}>
CONFLICTS
</Heading>
</View>
) : null}
{currentEditingNote === item.id ? (
<View
style={{
backgroundColor: hexToRGBA(colors[color], 0.12),
paddingHorizontal: 3,
paddingVertical: 2,
borderRadius: 3,
marginRight: 10,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
}}>
<Icon name="pencil-outline" size={SIZE.xxs} color={colors[color]} />
<Heading
size={SIZE.xxs}
style={{marginLeft: 5}}
color={colors[color]}>
EDITING NOW
</Heading>
</View>
) : null}
</View>
</View>
);
};
2020-02-06 23:38:40 +05:00
2020-03-18 12:31:06 +05:00
const SelectionWrapper = ({
children,
item,
index,
background,
2020-09-09 14:55:59 +05:00
onLongPress,
2020-09-09 22:09:57 +05:00
onPress,
2020-12-16 12:07:34 +05:00
testID,
2020-03-18 12:31:06 +05:00
}) => {
2020-01-17 21:26:01 +05:00
const [state, dispatch] = useTracked();
2020-12-16 20:01:02 +05:00
const {colors, selectionMode, selectedItemsList} = state;
2020-01-31 18:22:20 +05:00
const [selected, setSelected] = useState(false);
useEffect(() => {
let exists = selectedItemsList.filter(
2020-09-09 14:55:59 +05:00
(o) => o.dateCreated === item.dateCreated,
2020-01-31 18:22:20 +05:00
);
if (exists[0]) {
if (!selected) {
setSelected(true);
}
} else {
if (selected) {
setSelected(false);
}
}
}, [selectedItemsList]);
2020-01-17 00:23:16 +05:00
return (
2020-09-09 14:55:59 +05:00
<PressableButton
2020-12-16 20:01:02 +05:00
customColor="transparent"
2020-12-01 22:52:01 +05:00
testID={testID}
2020-09-09 14:55:59 +05:00
onLongPress={onLongPress}
onPress={onPress}
2020-12-16 20:01:02 +05:00
customSelectedColor={colors.nav}
2020-12-06 14:42:46 +05:00
customAlpha={!colors.night ? -0.02 : 0.02}
2020-12-16 20:01:02 +05:00
customOpacity={1}
2020-09-09 14:55:59 +05:00
customStyle={{
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
2020-01-22 02:51:24 +05:00
width: '100%',
paddingHorizontal: 12,
2020-09-18 20:54:31 +05:00
borderRadius: 0,
2020-12-16 20:01:02 +05:00
overflow: 'hidden',
2020-03-18 12:31:06 +05:00
marginTop:
2020-11-14 10:06:41 +05:00
index === 0 && !selectionMode
2020-03-18 12:31:06 +05:00
? 15
2020-11-14 10:06:41 +05:00
: index === 0 && selectionMode
2020-03-18 12:31:06 +05:00
? 30
: 0,
}}>
2020-12-16 20:01:02 +05:00
{item.type === 'note' ? (
<Filler background={background} item={item} />
) : null}
2020-03-18 12:31:06 +05:00
2020-01-22 02:51:24 +05:00
<View
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-12-16 12:07:34 +05:00
{item.title !== 'General' && (
<TouchableOpacity
activeOpacity={1}
onPress={onLongPress}
style={{
justifyContent: 'center',
alignItems: 'center',
height: 70,
}}>
<Icon
size={SIZE.lg}
color={selected ? colors.accent : colors.icon}
name={
selected
? 'check-circle-outline'
: 'checkbox-blank-circle-outline'
}
/>
</TouchableOpacity>
)}
2020-01-22 02:51:24 +05:00
</View>
2020-02-06 23:38:40 +05:00
{children}
2020-09-09 14:55:59 +05:00
</PressableButton>
);
};
export default SelectionWrapper;