2020-01-18 11:41:42 +05:00
|
|
|
import React, {Component} from 'react';
|
2020-01-22 02:50:25 +05:00
|
|
|
import {
|
|
|
|
|
Modal,
|
|
|
|
|
Text,
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
View,
|
|
|
|
|
DeviceEventEmitter,
|
|
|
|
|
} from 'react-native';
|
2019-12-04 19:38:19 +05:00
|
|
|
import Icon from 'react-native-vector-icons/Feather';
|
2020-01-22 02:50:25 +05:00
|
|
|
import {db, DDS} from '../../../App';
|
2020-01-18 11:41:42 +05:00
|
|
|
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
|
2020-01-24 23:13:09 +05:00
|
|
|
import {ACTIONS} from '../../provider/actions';
|
2020-01-18 11:41:42 +05:00
|
|
|
import NavigationService from '../../services/NavigationService';
|
|
|
|
|
import {getElevation, ToastEvent} from '../../utils/utils';
|
|
|
|
|
import {dialogActions, updateEvent} from '../DialogManager';
|
2020-01-25 23:24:01 +05:00
|
|
|
import {eSendEvent} from '../../services/eventManager';
|
|
|
|
|
import {eCloseFullscreenEditor} from '../../services/events';
|
2020-01-17 11:49:31 +05:00
|
|
|
|
|
|
|
|
export class Dialog extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
visible: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_onPress = async () => {
|
|
|
|
|
let {template, item} = this.props;
|
|
|
|
|
|
|
|
|
|
switch (template.action) {
|
|
|
|
|
case dialogActions.ACTION_DELETE: {
|
2020-01-18 18:14:34 +05:00
|
|
|
if (item.type === 'note') {
|
2020-01-31 18:22:20 +05:00
|
|
|
await db.deleteNotes(item.dateCreated);
|
|
|
|
|
|
2020-01-18 18:14:34 +05:00
|
|
|
ToastEvent.show('Note moved to trash', 'success', 3000);
|
|
|
|
|
updateEvent({type: item.type});
|
|
|
|
|
} else if (item.type === 'topic') {
|
|
|
|
|
await db.deleteTopicFromNotebook(notebookID, item.title);
|
|
|
|
|
updateEvent({type: 'notebook'});
|
|
|
|
|
ToastEvent.show('Topic moved to trash', 'success', 3000);
|
|
|
|
|
} else if (item.type === 'notebook') {
|
2020-01-31 18:22:20 +05:00
|
|
|
await db.deleteNotebooks(item.dateCreated);
|
2020-01-18 18:14:34 +05:00
|
|
|
updateEvent({type: item.type});
|
|
|
|
|
ToastEvent.show('Notebook moved to trash', 'success', 3000);
|
|
|
|
|
}
|
2020-01-17 21:05:38 +05:00
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case dialogActions.ACTION_EXIT: {
|
2020-01-17 21:05:38 +05:00
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
NavigationService.goBack();
|
|
|
|
|
|
2020-01-18 00:45:37 +05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case dialogActions.ACTION_EMPTY_TRASH: {
|
|
|
|
|
await db.clearTrash();
|
|
|
|
|
updateEvent({type: ACTIONS.TRASH});
|
|
|
|
|
ToastEvent.show('Trash cleared', 'success', 1000, () => {}, '');
|
|
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
break;
|
|
|
|
|
}
|
2020-01-22 02:50:25 +05:00
|
|
|
case dialogActions.ACTION_EXIT_FULLSCREEN: {
|
|
|
|
|
updateEvent({type: ACTIONS.NOTES});
|
2020-01-25 23:24:01 +05:00
|
|
|
eSendEvent(eCloseFullscreenEditor);
|
2020-01-22 02:50:25 +05:00
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-01-17 11:49:31 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_onClose = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-12-04 19:38:19 +05:00
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
show = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
visible: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
hide = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
visible: false,
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-12-04 19:38:19 +05:00
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
render() {
|
|
|
|
|
const {template, colors} = this.props;
|
|
|
|
|
const {title, paragraph, positiveText, negativeText, icon} = template;
|
|
|
|
|
const {visible} = this.state;
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
visible={visible}
|
|
|
|
|
transparent={true}
|
|
|
|
|
animated
|
|
|
|
|
animationType="fade"
|
|
|
|
|
onRequestClose={() => this.setState({visible: false})}>
|
|
|
|
|
<View
|
2020-01-08 22:47:49 +05:00
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
2020-01-17 11:49:31 +05:00
|
|
|
backgroundColor: 'rgba(0,0,0,0.3)',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
2019-12-04 19:38:19 +05:00
|
|
|
}}>
|
2020-01-17 11:49:31 +05:00
|
|
|
<TouchableOpacity
|
2020-01-22 02:50:25 +05:00
|
|
|
onPress={this.hide}
|
2019-12-04 19:38:19 +05:00
|
|
|
style={{
|
2020-01-17 11:49:31 +05:00
|
|
|
width: '100%',
|
|
|
|
|
height: '100%',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2019-12-04 19:38:19 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2020-01-17 11:49:31 +05:00
|
|
|
...getElevation(5),
|
2020-01-22 02:50:25 +05:00
|
|
|
width: DDS.isTab ? '50%' : '80%',
|
2020-01-17 11:49:31 +05:00
|
|
|
maxHeight: 350,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
backgroundColor: colors.bg,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
paddingVertical: pv,
|
2019-12-04 19:38:19 +05:00
|
|
|
}}>
|
2020-01-17 11:49:31 +05:00
|
|
|
<View
|
2019-12-04 19:38:19 +05:00
|
|
|
style={{
|
2020-01-17 11:49:31 +05:00
|
|
|
flexDirection: 'row',
|
2019-12-04 19:38:19 +05:00
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
}}>
|
2020-01-17 11:49:31 +05:00
|
|
|
{icon ? (
|
|
|
|
|
<Icon name={icon} color={colors.accent} size={SIZE.lg} />
|
|
|
|
|
) : null}
|
|
|
|
|
|
2019-12-04 19:38:19 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
2020-01-17 11:49:31 +05:00
|
|
|
color: colors.accent,
|
|
|
|
|
fontFamily: WEIGHT.bold,
|
|
|
|
|
marginLeft: 5,
|
|
|
|
|
fontSize: SIZE.md,
|
2019-12-04 19:38:19 +05:00
|
|
|
}}>
|
2020-01-17 11:49:31 +05:00
|
|
|
{title}
|
2019-12-04 19:38:19 +05:00
|
|
|
</Text>
|
2020-01-17 11:49:31 +05:00
|
|
|
</View>
|
2019-12-04 19:38:19 +05:00
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
{paragraph ? (
|
2019-12-04 19:38:19 +05:00
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
color: colors.icon,
|
2020-01-17 11:49:31 +05:00
|
|
|
fontFamily: WEIGHT.regular,
|
|
|
|
|
fontSize: SIZE.sm - 2,
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
marginTop: 10,
|
2019-12-04 19:38:19 +05:00
|
|
|
}}>
|
2020-01-17 11:49:31 +05:00
|
|
|
{paragraph}
|
2019-12-04 19:38:19 +05:00
|
|
|
</Text>
|
2020-01-17 11:49:31 +05:00
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
marginTop: 20,
|
|
|
|
|
}}>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={this._onPress}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '48%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
borderColor: colors.accent,
|
|
|
|
|
backgroundColor: colors.accent,
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: 'white',
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
{positiveText}
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
activeOpacity={opacity}
|
|
|
|
|
onPress={this._onClose}
|
|
|
|
|
style={{
|
|
|
|
|
paddingVertical: pv,
|
|
|
|
|
paddingHorizontal: ph,
|
|
|
|
|
borderRadius: 5,
|
|
|
|
|
width: '48%',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
backgroundColor: colors.nav,
|
|
|
|
|
}}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: WEIGHT.medium,
|
|
|
|
|
color: colors.icon,
|
|
|
|
|
fontSize: SIZE.sm,
|
|
|
|
|
}}>
|
|
|
|
|
{negativeText}
|
|
|
|
|
</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
2019-12-04 19:38:19 +05:00
|
|
|
</View>
|
|
|
|
|
</View>
|
2020-01-17 11:49:31 +05:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|