2020-05-14 14:50:28 +05:00
|
|
|
import React, {Component} from 'react';
|
|
|
|
|
import {Platform} from 'react-native';
|
|
|
|
|
import {
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
|
|
|
|
openVault,
|
2020-06-03 10:39:47 +05:00
|
|
|
eSendEvent,
|
2020-05-14 14:50:28 +05:00
|
|
|
} from '../../services/eventManager';
|
|
|
|
|
import {
|
|
|
|
|
eCloseActionSheet,
|
|
|
|
|
eCloseAddNotebookDialog,
|
|
|
|
|
eCloseAddTopicDialog,
|
|
|
|
|
eCloseLoginDialog,
|
|
|
|
|
eCloseMoveNoteDialog,
|
|
|
|
|
eCloseSimpleDialog,
|
|
|
|
|
eOnLoadNote,
|
|
|
|
|
eOpenActionSheet,
|
|
|
|
|
eOpenAddNotebookDialog,
|
|
|
|
|
eOpenAddTopicDialog,
|
|
|
|
|
eOpenLoginDialog,
|
|
|
|
|
eOpenMoveNoteDialog,
|
|
|
|
|
eOpenSimpleDialog,
|
|
|
|
|
eOpenPremiumDialog,
|
2020-09-07 12:33:35 +05:00
|
|
|
eClosePremiumDialog,
|
|
|
|
|
eOpenExportDialog
|
2020-05-14 14:50:28 +05:00
|
|
|
} from '../../services/events';
|
|
|
|
|
import {DDS, hexToRGBA} from '../../utils/utils';
|
2020-01-25 23:24:01 +05:00
|
|
|
import ActionSheet from '../ActionSheet';
|
2020-05-14 14:50:28 +05:00
|
|
|
import {ActionSheetComponent} from '../ActionSheetComponent';
|
|
|
|
|
import {AddNotebookDialog} from '../AddNotebookDialog';
|
|
|
|
|
import {AddTopicDialog} from '../AddTopicDialog';
|
|
|
|
|
import {Dialog} from '../Dialog';
|
2020-03-26 13:39:04 +05:00
|
|
|
import MergeEditor from '../MergeEditor';
|
2020-05-14 14:50:28 +05:00
|
|
|
import {VaultDialog} from '../VaultDialog';
|
|
|
|
|
import {moveNoteEvent} from './recievers';
|
|
|
|
|
import {TEMPLATE_DELETE, TEMPLATE_PERMANANT_DELETE} from './templates';
|
2020-05-06 02:26:35 +05:00
|
|
|
import MoveNoteDialog from '../MoveNoteDialog';
|
2020-05-06 02:43:04 +05:00
|
|
|
import LoginDialog from '../LoginDialog';
|
2020-05-14 14:50:28 +05:00
|
|
|
import PremiumDialog from '../Premium/PremiumDialog';
|
2020-09-07 12:33:35 +05:00
|
|
|
import ExportDialog from '../ExportDialog';
|
2020-01-18 00:46:29 +05:00
|
|
|
|
2020-01-16 19:52:45 +05:00
|
|
|
export class DialogManager extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.actionSheet;
|
2020-01-17 21:05:38 +05:00
|
|
|
this.opened = false;
|
2020-01-16 19:52:45 +05:00
|
|
|
this.state = {
|
|
|
|
|
item: {},
|
|
|
|
|
actionSheetData: {
|
|
|
|
|
colors: false,
|
|
|
|
|
tags: false,
|
|
|
|
|
rowItems: [],
|
|
|
|
|
columnItems: [],
|
|
|
|
|
},
|
2020-01-17 11:49:31 +05:00
|
|
|
simpleDialog: {
|
|
|
|
|
title: '',
|
|
|
|
|
paragraph: '',
|
|
|
|
|
positiveText: '',
|
|
|
|
|
negativeText: '',
|
|
|
|
|
action: 0,
|
|
|
|
|
icon: '',
|
|
|
|
|
},
|
2020-01-16 19:52:45 +05:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 21:05:38 +05:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
|
return (
|
|
|
|
|
JSON.stringify(nextProps) !== JSON.stringify(this.props) ||
|
|
|
|
|
nextState !== this.state
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-16 19:52:45 +05:00
|
|
|
_showActionSheet = data => {
|
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
actionSheetData: data,
|
2020-03-15 12:29:27 +05:00
|
|
|
item: data.item ? data.item : {},
|
2020-01-16 19:52:45 +05:00
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
this.actionSheet._setModalVisible();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_hideActionSheet = () => {
|
|
|
|
|
this.actionSheet._setModalVisible();
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-18 18:14:34 +05:00
|
|
|
_showMoveNote = () => {
|
|
|
|
|
this.moveNoteDialog.open();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_hideMoveNote = () => {
|
|
|
|
|
this.moveNoteDialog.close();
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-22 02:50:25 +05:00
|
|
|
loadNote = i => {
|
|
|
|
|
if (i && i.type === 'new') {
|
2020-01-23 23:18:15 +05:00
|
|
|
this.setState({
|
2020-03-15 12:29:27 +05:00
|
|
|
item: {},
|
2020-01-23 23:18:15 +05:00
|
|
|
});
|
2020-01-22 02:50:25 +05:00
|
|
|
} else {
|
|
|
|
|
note = i;
|
|
|
|
|
this.setState({
|
|
|
|
|
item: i,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-17 10:33:52 +05:00
|
|
|
showAddTopic = notebook => {
|
2020-03-17 10:36:52 +05:00
|
|
|
if (notebook) {
|
|
|
|
|
this.setState({
|
|
|
|
|
item: notebook,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 10:33:52 +05:00
|
|
|
this.addTopicsDialog.open();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hideAddTopic = () => {
|
|
|
|
|
this.addTopicsDialog.close();
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-16 19:52:45 +05:00
|
|
|
componentDidMount() {
|
2020-01-25 12:05:20 +05:00
|
|
|
eSubscribeEvent(eOnLoadNote, this.loadNote);
|
2020-01-17 11:49:31 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eSubscribeEvent(eOpenActionSheet, this._showActionSheet);
|
|
|
|
|
eSubscribeEvent(eCloseActionSheet, this._hideSimpleDialog);
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eSubscribeEvent(eOpenSimpleDialog, this._showSimpleDialog);
|
|
|
|
|
eSubscribeEvent(eCloseSimpleDialog, this._hideSimpleDialog);
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eSubscribeEvent(eOpenMoveNoteDialog, this._showMoveNote);
|
|
|
|
|
eSubscribeEvent(eCloseMoveNoteDialog, this._hideMoveNote);
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eSubscribeEvent(eOpenAddNotebookDialog, this.showAddNotebook);
|
|
|
|
|
eSubscribeEvent(eCloseAddNotebookDialog, this.hideAddNotebook);
|
2020-01-23 23:18:15 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eSubscribeEvent(eOpenAddTopicDialog, this.showAddTopic);
|
|
|
|
|
eSubscribeEvent(eCloseAddTopicDialog, this.hideAddTopic);
|
|
|
|
|
|
|
|
|
|
eSubscribeEvent(eOpenLoginDialog, this.showLoginDialog);
|
|
|
|
|
eSubscribeEvent(eCloseLoginDialog, this.hideLoginDialog);
|
2020-05-14 14:50:28 +05:00
|
|
|
|
|
|
|
|
eSubscribeEvent(eOpenPremiumDialog, this.showPremiumDialog);
|
|
|
|
|
eSubscribeEvent(eClosePremiumDialog, this.hidePremiumDialog);
|
2020-01-16 19:52:45 +05:00
|
|
|
}
|
2020-01-23 23:18:15 +05:00
|
|
|
|
2020-01-16 19:52:45 +05:00
|
|
|
componentWillUnmount() {
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOnLoadNote, this.loadNote);
|
2020-01-22 02:50:25 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOpenActionSheet, this._showActionSheet);
|
|
|
|
|
eUnSubscribeEvent(eCloseActionSheet, this._hideSimpleDialog);
|
2020-01-17 11:49:31 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOpenSimpleDialog, this._showSimpleDialog);
|
|
|
|
|
eUnSubscribeEvent(eCloseSimpleDialog, this._hideSimpleDialog);
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOpenMoveNoteDialog, this._showMoveNote);
|
|
|
|
|
eUnSubscribeEvent(eCloseMoveNoteDialog, this._hideMoveNote);
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOpenAddNotebookDialog, this.showAddNotebook);
|
|
|
|
|
eUnSubscribeEvent(eCloseAddNotebookDialog, this.hideAddNotebook);
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOpenAddTopicDialog, this.showAddTopic);
|
|
|
|
|
eUnSubscribeEvent(eCloseAddTopicDialog, this.hideAddTopic);
|
2020-01-23 23:18:15 +05:00
|
|
|
|
2020-01-25 12:05:20 +05:00
|
|
|
eUnSubscribeEvent(eOpenLoginDialog, this.showLoginDialog);
|
|
|
|
|
eUnSubscribeEvent(eCloseLoginDialog, this.hideLoginDialog);
|
2020-05-14 14:50:28 +05:00
|
|
|
|
|
|
|
|
eUnSubscribeEvent(eOpenPremiumDialog, this.showPremiumDialog);
|
|
|
|
|
eUnSubscribeEvent(eClosePremiumDialog, this.hidePremiumDialog);
|
2020-01-18 18:14:34 +05:00
|
|
|
}
|
|
|
|
|
|
2020-05-14 14:50:28 +05:00
|
|
|
showPremiumDialog = () => {
|
|
|
|
|
this.premiumDialog.open();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hidePremiumDialog = () => {
|
|
|
|
|
this.premiumDialog.close();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2020-01-23 23:18:15 +05:00
|
|
|
showLoginDialog = () => {
|
2020-09-14 13:14:07 +05:00
|
|
|
//this.loginDialog.open();
|
2020-01-23 23:18:15 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hideLoginDialog = () => {
|
2020-09-14 13:14:07 +05:00
|
|
|
//this.loginDialog.close();
|
2020-01-23 23:18:15 +05:00
|
|
|
};
|
|
|
|
|
|
2020-01-20 15:32:32 +05:00
|
|
|
showAddNotebook = data => {
|
2020-09-14 16:46:21 +05:00
|
|
|
/* this.setState(
|
2020-01-18 18:14:34 +05:00
|
|
|
{
|
2020-01-20 15:32:32 +05:00
|
|
|
item: data.item ? data.item : {},
|
2020-01-18 18:14:34 +05:00
|
|
|
},
|
|
|
|
|
() => {
|
2020-01-20 15:32:32 +05:00
|
|
|
this.addNotebooksDialog.open();
|
2020-01-18 18:14:34 +05:00
|
|
|
},
|
2020-09-14 16:46:21 +05:00
|
|
|
); */
|
2020-01-20 15:32:32 +05:00
|
|
|
};
|
|
|
|
|
hideAddNotebook = () => {
|
2020-09-14 16:46:21 +05:00
|
|
|
//this.addNotebooksDialog.close();
|
2020-01-20 15:32:32 +05:00
|
|
|
};
|
2020-01-18 18:14:34 +05:00
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
_showSimpleDialog = data => {
|
|
|
|
|
this.setState(
|
|
|
|
|
{
|
|
|
|
|
simpleDialog: data,
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
this.simpleDialog.show();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
_hideSimpleDialog = data => {
|
|
|
|
|
this.simpleDialog.hide();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onActionSheetHide = () => {
|
|
|
|
|
if (this.show) {
|
2020-01-18 18:14:34 +05:00
|
|
|
switch (this.show) {
|
|
|
|
|
case 'delete': {
|
2020-03-14 12:13:00 +05:00
|
|
|
if (this.state.item.locked) {
|
|
|
|
|
openVault(this.state.item, true, true, false, false, false, true);
|
|
|
|
|
} else {
|
|
|
|
|
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
|
|
|
|
|
}
|
2020-01-19 21:31:26 +05:00
|
|
|
break;
|
2020-01-18 18:14:34 +05:00
|
|
|
}
|
2020-03-04 11:58:44 +05:00
|
|
|
case 'permanant_delete': {
|
|
|
|
|
this._showSimpleDialog(TEMPLATE_PERMANANT_DELETE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-03-10 23:19:16 +05:00
|
|
|
case 'novault': {
|
2020-04-18 13:49:24 +05:00
|
|
|
openVault(this.state.item, false);
|
2020-04-18 14:03:05 +05:00
|
|
|
break;
|
2020-03-10 23:19:16 +05:00
|
|
|
}
|
2020-04-18 14:03:05 +05:00
|
|
|
case 'locked': {
|
2020-04-18 13:49:24 +05:00
|
|
|
openVault(this.state.item, true, true);
|
2020-01-19 21:31:26 +05:00
|
|
|
break;
|
2020-01-18 18:14:34 +05:00
|
|
|
}
|
2020-04-18 13:49:24 +05:00
|
|
|
case 'unlock': {
|
|
|
|
|
openVault(this.state.item, true, true, true, false, false);
|
2020-04-18 14:03:05 +05:00
|
|
|
break;
|
2020-01-29 17:38:50 +05:00
|
|
|
}
|
2020-01-18 18:14:34 +05:00
|
|
|
case 'notebook': {
|
2020-01-20 15:32:32 +05:00
|
|
|
this.showAddNotebook({item: this.state.item});
|
2020-01-19 21:31:26 +05:00
|
|
|
break;
|
2020-01-18 18:14:34 +05:00
|
|
|
}
|
|
|
|
|
case 'topic': {
|
2020-03-17 10:33:52 +05:00
|
|
|
this.showAddTopic();
|
2020-01-19 21:31:26 +05:00
|
|
|
break;
|
2020-01-18 18:14:34 +05:00
|
|
|
}
|
2020-02-22 20:00:57 +05:00
|
|
|
case 'movenote': {
|
|
|
|
|
moveNoteEvent();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-06-03 10:39:47 +05:00
|
|
|
case "premium": {
|
|
|
|
|
eSendEvent(eOpenPremiumDialog);
|
|
|
|
|
}
|
2020-09-07 12:33:35 +05:00
|
|
|
case "export": {
|
|
|
|
|
eSendEvent(eOpenExportDialog,[this.state.item]);
|
|
|
|
|
}
|
2020-01-17 11:49:31 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.show = null;
|
|
|
|
|
};
|
2020-09-10 10:35:02 +05:00
|
|
|
|
2020-01-17 11:49:31 +05:00
|
|
|
|
2020-01-16 19:52:45 +05:00
|
|
|
render() {
|
2020-01-17 21:05:38 +05:00
|
|
|
let {colors} = this.props;
|
2020-03-10 23:19:16 +05:00
|
|
|
let {actionSheetData, item, simpleDialog} = this.state;
|
2020-01-16 19:52:45 +05:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ActionSheet
|
|
|
|
|
ref={ref => (this.actionSheet = ref)}
|
2020-01-24 18:48:33 +05:00
|
|
|
containerStyle={{
|
2020-01-16 19:52:45 +05:00
|
|
|
backgroundColor: colors.bg,
|
2020-01-24 18:48:33 +05:00
|
|
|
width: DDS.isTab ? 500 : '100%',
|
|
|
|
|
alignSelf: DDS.isTab ? 'flex-end' : 'center',
|
|
|
|
|
marginRight: DDS.isTab ? 12 : null,
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
marginBottom: DDS.isTab ? 50 : 0,
|
2020-01-16 19:52:45 +05:00
|
|
|
}}
|
2020-01-24 18:48:33 +05:00
|
|
|
extraScroll={DDS.isTab ? 50 : 0}
|
2020-02-22 13:02:16 +05:00
|
|
|
indicatorColor={
|
|
|
|
|
Platform.ios
|
|
|
|
|
? hexToRGBA(colors.accent + '19')
|
|
|
|
|
: hexToRGBA(colors.shade)
|
|
|
|
|
}
|
2020-05-07 02:06:51 +05:00
|
|
|
delayActionSheetDraw={true}
|
|
|
|
|
delayActionSheetDrawTime={10}
|
2020-01-24 18:48:33 +05:00
|
|
|
footerAlwaysVisible={DDS.isTab}
|
2020-01-27 23:48:51 +05:00
|
|
|
footerHeight={DDS.isTab ? 20 : 10}
|
2020-01-24 18:48:33 +05:00
|
|
|
footerStyle={
|
|
|
|
|
DDS.isTab
|
|
|
|
|
? {
|
|
|
|
|
borderRadius: 10,
|
2020-01-24 23:13:09 +05:00
|
|
|
backgroundColor: colors.bg,
|
2020-01-24 18:48:33 +05:00
|
|
|
}
|
|
|
|
|
: null
|
|
|
|
|
}
|
2020-09-09 22:09:57 +05:00
|
|
|
initialOffsetFromBottom={1}
|
2020-01-16 19:52:45 +05:00
|
|
|
bounceOnOpen={true}
|
|
|
|
|
gestureEnabled={true}
|
|
|
|
|
onClose={() => {
|
2020-01-17 11:49:31 +05:00
|
|
|
this.onActionSheetHide();
|
2020-01-16 19:52:45 +05:00
|
|
|
}}>
|
|
|
|
|
<ActionSheetComponent
|
|
|
|
|
item={item}
|
|
|
|
|
setWillRefresh={value => {
|
|
|
|
|
this.willRefresh = true;
|
|
|
|
|
}}
|
|
|
|
|
hasColors={actionSheetData.colors}
|
|
|
|
|
hasTags={actionSheetData.colors}
|
|
|
|
|
overlayColor={
|
|
|
|
|
colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)'
|
|
|
|
|
}
|
|
|
|
|
rowItems={actionSheetData.rowItems}
|
|
|
|
|
columnItems={actionSheetData.columnItems}
|
|
|
|
|
close={value => {
|
|
|
|
|
if (value) {
|
|
|
|
|
this.show = value;
|
|
|
|
|
}
|
|
|
|
|
this.actionSheet._setModalVisible();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</ActionSheet>
|
2020-01-17 11:49:31 +05:00
|
|
|
|
|
|
|
|
<Dialog
|
|
|
|
|
ref={ref => (this.simpleDialog = ref)}
|
|
|
|
|
item={item}
|
|
|
|
|
colors={colors}
|
|
|
|
|
template={simpleDialog}
|
|
|
|
|
/>
|
2020-01-17 21:05:38 +05:00
|
|
|
|
2020-03-10 23:19:16 +05:00
|
|
|
<VaultDialog colors={colors} />
|
2020-05-06 02:26:35 +05:00
|
|
|
|
2020-01-18 18:14:34 +05:00
|
|
|
<MoveNoteDialog
|
|
|
|
|
ref={ref => (this.moveNoteDialog = ref)}
|
|
|
|
|
colors={colors}
|
2020-05-14 14:50:28 +05:00
|
|
|
/>
|
2020-01-18 18:14:34 +05:00
|
|
|
|
|
|
|
|
<AddTopicDialog
|
|
|
|
|
ref={ref => (this.addTopicsDialog = ref)}
|
2020-02-03 00:18:40 +05:00
|
|
|
toEdit={item.type === 'topic' ? item : null}
|
2020-01-18 18:14:34 +05:00
|
|
|
notebookID={
|
|
|
|
|
actionSheetData.extraData
|
|
|
|
|
? actionSheetData.extraData.notebookID
|
2020-02-06 13:08:35 +05:00
|
|
|
: item.id
|
2020-01-18 18:14:34 +05:00
|
|
|
}
|
|
|
|
|
colors={colors}
|
|
|
|
|
/>
|
|
|
|
|
<AddNotebookDialog
|
|
|
|
|
ref={ref => (this.addNotebooksDialog = ref)}
|
|
|
|
|
toEdit={item}
|
|
|
|
|
colors={colors}
|
|
|
|
|
/>
|
2020-05-14 14:50:28 +05:00
|
|
|
<PremiumDialog ref={ref => this.premiumDialog = ref} colors={colors} />
|
2020-01-23 23:18:15 +05:00
|
|
|
|
2020-05-14 14:50:28 +05:00
|
|
|
<LoginDialog colors={colors} ref={ref => (this.loginDialog = ref)} />
|
2020-03-26 13:39:04 +05:00
|
|
|
|
|
|
|
|
<MergeEditor />
|
2020-09-07 12:33:35 +05:00
|
|
|
|
|
|
|
|
<ExportDialog/>
|
2020-01-16 19:52:45 +05:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|