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

261 lines
7.8 KiB
JavaScript
Raw Normal View History

2020-01-17 21:05:38 +05:00
import React, {Component} from 'react';
2019-12-14 19:26:44 +05:00
import {View, Text, TouchableOpacity, Modal} from 'react-native';
import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
2020-02-11 20:33:36 +05:00
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
2020-01-17 21:05:38 +05:00
import {TextInput} from 'react-native-gesture-handler';
2019-12-11 01:10:04 +05:00
import {db} from '../../../App';
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
2020-01-17 21:05:38 +05:00
import {updateEvent} from '../DialogManager';
2020-03-02 13:52:09 +05:00
import Share from 'react-native-share';
2020-03-03 15:25:40 +05:00
import {eSendEvent} from '../../services/eventManager';
import {eOnLoadNote} from '../../services/events';
import {openEditorAnimation} from '../../utils/animations';
2019-12-07 08:41:48 +05:00
2020-01-17 21:05:38 +05:00
export class VaultDialog extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
};
this.password = null;
}
2020-01-17 00:23:16 +05:00
2020-01-17 21:05:38 +05:00
open = () => {
this.setState({
visible: true,
});
};
2020-01-29 17:38:50 +05:00
close = (share = false, item = null) => {
2020-03-02 13:52:09 +05:00
if (share && item) {
let m = `${item.title}\n \n ${item.content.text}`;
Share.open({
title: 'Share note to',
failOnCancel: false,
message: m,
});
}
2020-03-03 15:21:44 +05:00
updateEvent({type: item.type});
2020-03-02 13:52:09 +05:00
this.setState({
visible: false,
});
2020-01-17 21:05:38 +05:00
};
onPress = async () => {
if (this.props.note.locked) {
2020-02-07 20:24:29 +05:00
let n = db.notes.note(this.props.note.id).data;
2020-01-17 21:05:38 +05:00
let item;
if (n.content.cipher) {
try {
2020-02-06 13:08:35 +05:00
item = await db.notes.note(n.id).unlock(password, this.props.perm);
2020-02-02 23:50:55 +05:00
} catch (error) {}
2020-01-17 21:05:38 +05:00
} else {
item = n;
}
if (!this.props.perm) {
2020-03-03 15:25:40 +05:00
eSendEvent(eOnLoadNote, item);
if (!DDS.isTab) {
openEditorAnimation();
}
2020-01-17 21:05:38 +05:00
}
2020-01-29 17:38:50 +05:00
this.close(this.props.shareAfterUnlock, item);
2020-01-17 21:05:38 +05:00
} else {
2020-02-06 13:08:35 +05:00
await db.notes.note(this.props.note.id).lock('password');
2020-03-03 15:25:40 +05:00
this.close(false, this.props.note);
2020-01-17 21:05:38 +05:00
}
};
render() {
const {hasPassword, note, colors} = this.props;
const {visible} = this.state;
return (
<Modal visible={visible} transparent={true} onRequestClose={this.close}>
2019-12-07 08:41:48 +05:00
<View
style={{
2020-01-17 21:05:38 +05:00
width: '100%',
height: '100%',
backgroundColor: colors.night
? 'rgba(255,255,255,0.3)'
: 'rgba(0,0,0,0.3)',
justifyContent: 'center',
alignItems: 'center',
2019-12-07 08:41:48 +05:00
}}>
<View
style={{
2020-01-17 21:05:38 +05:00
...getElevation(5),
width: '80%',
maxHeight: 350,
borderRadius: 5,
backgroundColor: colors.bg,
paddingHorizontal: ph,
paddingVertical: pv,
2019-12-07 08:41:48 +05:00
}}>
2020-01-17 21:05:38 +05:00
<View
2019-12-07 08:41:48 +05:00
style={{
2020-01-17 21:05:38 +05:00
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
2019-12-07 08:41:48 +05:00
}}>
2020-01-17 21:05:38 +05:00
<Icon name="shield" color={colors.accent} size={SIZE.lg} />
<Text
style={{
color: colors.accent,
fontFamily: WEIGHT.bold,
marginLeft: 5,
fontSize: SIZE.md,
}}>
{note.locked ? 'Unlock Note' : 'Lock Note'}
</Text>
</View>
2019-12-07 08:41:48 +05:00
2020-01-17 21:05:38 +05:00
<Text
2020-01-05 18:03:40 +05:00
style={{
2020-01-17 21:05:38 +05:00
color: colors.icon,
2020-01-05 18:03:40 +05:00
fontFamily: WEIGHT.regular,
2020-01-17 21:05:38 +05:00
textAlign: 'center',
fontSize: SIZE.sm - 1,
marginTop: 10,
//marginBottom: hidden ? 20 : 0,
}}>
{hasPassword
? 'Set password for all your locked notes.'
: note.locked
? 'Enter vault password to unlock note.'
: 'Do you want to lock this note?'}
</Text>
2020-01-05 18:03:40 +05:00
2020-01-17 21:05:38 +05:00
{note.locked ? (
2019-12-07 08:41:48 +05:00
<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,
2020-01-17 21:05:38 +05:00
marginTop: 10,
2019-12-07 08:41:48 +05:00
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
}}
2020-01-17 21:05:38 +05:00
onChangeText={value => {
password = value;
}}
secureTextEntry
2019-12-07 08:41:48 +05:00
placeholder="Password"
placeholderTextColor={colors.icon}
/>
2020-01-17 21:05:38 +05:00
) : null}
2019-12-07 08:41:48 +05:00
2020-01-17 21:05:38 +05:00
{!hasPassword ? null : (
<View>
<TextInput
style={{
padding: pv - 5,
borderWidth: 1.5,
borderColor: colors.nav,
paddingHorizontal: ph,
borderRadius: 5,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
}}
onChangeText={value => {}}
placeholder="Password"
placeholderTextColor={colors.icon}
/>
2019-12-07 08:41:48 +05:00
2020-01-17 21:05:38 +05:00
<TextInput
style={{
padding: pv - 5,
borderWidth: 1.5,
borderColor: colors.nav,
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,
borderColor: colors.nav,
paddingHorizontal: ph,
borderRadius: 5,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
marginTop: 10,
}}
onChangeText={value => {}}
placeholder="Hint"
placeholderTextColor={colors.icon}
/>
</View>
)}
2020-01-05 18:03:40 +05:00
2020-01-17 21:05:38 +05:00
<View
2019-12-07 08:41:48 +05:00
style={{
2020-01-17 21:05:38 +05:00
justifyContent: 'space-around',
2019-12-07 08:41:48 +05:00
alignItems: 'center',
2020-01-17 21:05:38 +05:00
flexDirection: 'row',
marginTop: 20,
2019-12-07 08:41:48 +05:00
}}>
2020-01-17 21:05:38 +05:00
<TouchableOpacity
activeOpacity={opacity}
onPress={this.onPress}
2019-12-07 08:41:48 +05:00
style={{
2020-01-17 21:05:38 +05:00
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
width: '45%',
justifyContent: 'center',
alignItems: 'center',
borderColor: colors.accent,
backgroundColor: colors.accent,
borderWidth: 1,
2019-12-07 08:41:48 +05:00
}}>
2020-01-17 21:05:38 +05:00
<Text
style={{
fontFamily: WEIGHT.medium,
color: 'white',
fontSize: SIZE.sm,
}}>
{note.locked ? 'Unlock' : 'Lock'}
</Text>
</TouchableOpacity>
2019-12-07 08:41:48 +05:00
2020-01-17 21:05:38 +05:00
<TouchableOpacity
activeOpacity={opacity}
onPress={this.close}
2019-12-07 08:41:48 +05:00
style={{
2020-01-17 21:05:38 +05:00
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
width: '45%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.nav,
2019-12-07 08:41:48 +05:00
}}>
2020-01-17 21:05:38 +05:00
<Text
style={{
fontFamily: WEIGHT.medium,
color: colors.icon,
fontSize: SIZE.sm,
}}>
Cancel
</Text>
</TouchableOpacity>
</View>
2019-12-07 08:41:48 +05:00
</View>
</View>
2020-01-17 21:05:38 +05:00
</Modal>
);
}
}