2019-12-14 19:26:44 +05:00
|
|
|
import React, {useState} from 'react';
|
|
|
|
|
import {View, Text, TouchableOpacity, Modal} from 'react-native';
|
|
|
|
|
import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
|
2019-12-07 08:41:48 +05:00
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
|
|
|
|
import {FlatList, TextInput} from 'react-native-gesture-handler';
|
|
|
|
|
import {useForceUpdate} from '../../views/ListsEditor';
|
2019-12-11 01:10:04 +05:00
|
|
|
import {db} from '../../../App';
|
2019-12-14 19:26:44 +05:00
|
|
|
import {useAppContext} from '../../provider/useAppContext';
|
2020-01-05 18:03:40 +05:00
|
|
|
import {getElevation} from '../../utils/utils';
|
|
|
|
|
import NavigationService from '../../services/NavigationService';
|
2019-12-07 08:41:48 +05:00
|
|
|
|
|
|
|
|
let refs = [];
|
|
|
|
|
|
2020-01-05 18:03:40 +05:00
|
|
|
export const VaultDialog = ({
|
|
|
|
|
openedToUnlock = false,
|
|
|
|
|
visible,
|
|
|
|
|
hasPassword = false,
|
|
|
|
|
note,
|
|
|
|
|
close = () => {},
|
|
|
|
|
perm = false,
|
|
|
|
|
timestamp = null,
|
|
|
|
|
}) => {
|
2019-12-14 19:26:44 +05:00
|
|
|
const {colors} = useAppContext();
|
2019-12-07 08:41:48 +05:00
|
|
|
const [hidden, setHidden] = useState(false);
|
2020-01-05 18:03:40 +05:00
|
|
|
let password = null;
|
2019-12-07 08:41:48 +05:00
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
visible={visible}
|
|
|
|
|
transparent={true}
|
|
|
|
|
onRequestClose={() => (refs = [])}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
backgroundColor: 'rgba(255,255,255,0.3)',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2020-01-05 18:03:40 +05:00
|
|
|
...getElevation(5),
|
2019-12-07 08:41:48 +05:00
|
|
|
width: '80%',
|
|
|
|
|
maxHeight: 350,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
}}>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
|
|
|
|
<Icon name="shield" color={colors.accent} size={SIZE.lg} />
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.accent,
|
2020-01-05 18:03:40 +05:00
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
marginLeft: 5,
|
|
|
|
|
fontSize: SIZE.md,
|
2019-12-07 08:41:48 +05:00
|
|
|
}}>
|
2020-01-05 18:03:40 +05:00
|
|
|
{openedToUnlock ? 'Unlock Note' : 'Lock Note'}
|
2019-12-07 08:41:48 +05:00
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
fontSize: SIZE.sm - 1,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
marginBottom: hidden ? 20 : 0,
|
|
|
|
|
}}>
|
2020-01-05 18:03:40 +05:00
|
|
|
{hasPassword
|
2019-12-07 08:41:48 +05:00
|
|
|
? 'Set password for all your locked notes.'
|
2020-01-05 18:03:40 +05:00
|
|
|
: openedToUnlock
|
|
|
|
|
? 'Enter vault password to unlock note.'
|
2019-12-07 08:41:48 +05:00
|
|
|
: 'Do you want to lock this note?'}
|
|
|
|
|
</Text>
|
|
|
|
|
|
2020-01-05 18:03:40 +05:00
|
|
|
{openedToUnlock ? (
|
|
|
|
|
<TextInput
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderWidth: 1.5,
|
|
|
|
|
borderColor: colors.nav,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={value => {
|
|
|
|
|
password = value;
|
|
|
|
|
}}
|
|
|
|
|
secureTextEntry
|
|
|
|
|
placeholder="Password"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
{!hasPassword ? null : (
|
2019-12-07 08:41:48 +05:00
|
|
|
<View>
|
|
|
|
|
<TextInput
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderWidth: 1.5,
|
2019-12-07 12:05:15 +05:00
|
|
|
borderColor: colors.nav,
|
2019-12-07 08:41:48 +05:00
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={value => {}}
|
|
|
|
|
placeholder="Password"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<TextInput
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderWidth: 1.5,
|
2019-12-07 12:05:15 +05:00
|
|
|
borderColor: colors.nav,
|
2019-12-07 08:41:48 +05:00
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={value => {}}
|
|
|
|
|
placeholder="Confirm password"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
<TextInput
|
|
|
|
|
style={{
|
|
|
|
|
padding: pv - 5,
|
|
|
|
|
borderWidth: 1.5,
|
2019-12-07 12:05:15 +05:00
|
|
|
borderColor: colors.nav,
|
2019-12-07 08:41:48 +05:00
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
}}
|
|
|
|
|
onChangeText={value => {}}
|
|
|
|
|
placeholder="Hint"
|
|
|
|
|
placeholderTextColor={colors.icon}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'space-around',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
}}>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
2020-01-05 18:03:40 +05:00
|
|
|
onPress={async () => {
|
|
|
|
|
if (openedToUnlock) {
|
|
|
|
|
console.log(note.dateCreated, password, perm);
|
|
|
|
|
let n = db.getNote(note.dateCreated);
|
|
|
|
|
let item;
|
|
|
|
|
if (n.content.cipher) {
|
|
|
|
|
console.log(n.content.cipher);
|
|
|
|
|
|
|
|
|
|
item = await db.unlockNote(n.dateCreated, password, perm);
|
|
|
|
|
console.log(item);
|
|
|
|
|
} else {
|
|
|
|
|
item = n;
|
|
|
|
|
}
|
|
|
|
|
if (!perm) {
|
|
|
|
|
NavigationService.navigate('Editor', {
|
|
|
|
|
note: item,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
close(item, false);
|
|
|
|
|
} else {
|
|
|
|
|
await db.lockNote(note.dateCreated, 'password');
|
|
|
|
|
|
|
|
|
|
close(null, true);
|
|
|
|
|
}
|
|
|
|
|
}}
|
2019-12-07 08:41:48 +05:00
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '45%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
2020-01-05 18:03:40 +05:00
|
|
|
{openedToUnlock ? 'Unlock' : 'Lock'}
|
2019-12-07 08:41:48 +05:00
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={() => {
|
|
|
|
|
close();
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '45%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2019-12-07 12:05:15 +05:00
|
|
|
backgroundColor: colors.nav,
|
2019-12-07 08:41:48 +05:00
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|