From 7f521b4ab6c727f02ef6b09cfbb444c8df8c007a Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Fri, 10 Jan 2020 18:47:28 +0500 Subject: [PATCH] ui: remove EditorMenu for mobile devices --- apps/mobile/src/views/Editor/index.js | 188 +++++++++++++++++--------- 1 file changed, 127 insertions(+), 61 deletions(-) diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js index 10f007f76..cf3d9d735 100755 --- a/apps/mobile/src/views/Editor/index.js +++ b/apps/mobile/src/views/Editor/index.js @@ -15,7 +15,7 @@ import {SIZE, WEIGHT} from '../../common/common'; import WebView from 'react-native-webview'; import Icon from 'react-native-vector-icons/Feather'; import {db} from '../../../App'; -import {SideMenuEvent} from '../../utils/utils'; +import {SideMenuEvent, getElevation, ToastEvent} from '../../utils/utils'; import {Dialog} from '../../components/Dialog'; import {DDS} from '../../../App'; import * as Animatable from 'react-native-animatable'; @@ -23,6 +23,10 @@ import SideMenu from 'react-native-side-menu'; import {EditorMenu} from '../../components/EditorMenu'; import {AnimatedSafeAreaView} from '../Home'; import {useAppContext} from '../../provider/useAppContext'; +import ActionSheet from '../../components/ActionSheet'; +import {ActionSheetComponent} from '../../components/ActionSheetComponent'; +import {VaultDialog} from '../../components/VaultDialog'; +import NavigationService from '../../services/NavigationService'; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; @@ -43,6 +47,9 @@ const Editor = ({navigation}) => { const [dialog, setDialog] = useState(false); const [isOpen, setOpen] = useState(false); const [sidebar, setSidebar] = useState(DDS.isTab ? true : false); + const [vaultDialog, setVaultDialog] = useState(false); + const [unlock, setUnlock] = useState(false); + const [visible, setVisible] = useState(false); const [noteProps, setNoteProps] = useState({ tags: [], locked: false, @@ -55,6 +62,8 @@ const Editor = ({navigation}) => { let updateInterval = null; let lastTextChange = 0; let menuTimer = null; + let willRefresh = false; + // FUNCTIONS const post = value => EditorWebView.postMessage(value); @@ -106,6 +115,7 @@ const Editor = ({navigation}) => { locked: note.locked, }; setNoteProps({...props}); + post(JSON.stringify(note.content.delta)); setTimeout(() => { title = note.title; @@ -121,6 +131,30 @@ const Editor = ({navigation}) => { title = value; }; + const onMenuHide = () => { + if (show) { + console.log(show); + if (show === 'lock') { + if (unlock) { + setUnlock(false); + } + setVaultDialog(true); + } else if (show === 'unlock') { + setUnlock(true); + setVaultDialog(true); + } else if (show == 'delete') { + setVisible(true); + } + } + }; + + const deleteItem = async () => { + await db.deleteNotes([note]); + ToastEvent.show('Note moved to trash', 'success', 3000); + setVisible(false); + navigation.goBack(); + }; + const _renderEditor = () => { return ( { width: '100%', alignSelf: 'center', height: 50, + marginTop: Platform.OS == 'ios' ? 0 : StatusBar.currentHeight, }}> { placeholder="Untitled Note" ref={ref => (titleRef = ref)} placeholderTextColor={colors.icon} - defaultValue={title} + defaultValue={note && note.title ? note.title : title} style={{ width: '75%', fontFamily: WEIGHT.bold, @@ -181,7 +216,9 @@ const Editor = ({navigation}) => { { - DDS.isTab ? setSidebar(!sidebar) : setOpen(!isOpen); + DDS.isTab + ? setSidebar(!sidebar) + : ActionSheet._setModalVisible(); }} style={{ width: '12.5%', @@ -190,9 +227,9 @@ const Editor = ({navigation}) => { alignItems: 'flex-end', }}> @@ -273,6 +310,8 @@ const Editor = ({navigation}) => { }, []); useEffect(() => { + SideMenuEvent.close(); + SideMenuEvent.disable(); return () => { DDS.isTab ? SideMenuEvent.open() : null; SideMenuEvent.enable(); @@ -312,6 +351,7 @@ const Editor = ({navigation}) => { }, 1000); }} /> + {_renderEditor()} { backgroundColor: colors.bg, flex: 1, }}> - + { + setDialog(false); + }} + positivePress={() => { + navigation.goBack(); + setDialog(false); + }} + /> + + {_renderEditor()} + + + { + setVisible(false); + }} + /> + + { + let props = {...noteProps}; + props.locked = locked; + note.locked = locked; + setNoteProps(props); + setVaultDialog(false); + setUnlock(false); + }} + note={note} + timestamp={timestamp} + perm={true} + openedToUnlock={unlock} + visible={vaultDialog} + /> + { - if (noteProps.locked) { - db.lockNote(timestamp, 'password'); - } - clearTimeout(menuTimer); - menuTimer = null; - menuTimer = setTimeout(() => { - setOpen(args); - }, 500); - }} - menu={ - { - setNoteProps(props); - console.log(props, noteProps); - if (props.locked) { - saveNote(noteProps, true); - } - }} - update={item => { - note = item; - updateEditor(); - }} - /> - }> - - { - setDialog(false); - }} - positivePress={() => { - navigation.goBack(); - setDialog(false); - }} - /> + initialOffsetFromBottom={0.99} + elevation={5} + overlayColor={ + colors.night ? 'rgba(225,225,225,0.1)' : 'rgba(0,0,0,0.3)' + } + indicatorColor={colors.shade} + onClose={() => { + onMenuHide(); + if (willRefresh) { + note = db.getNote(timestamp); - {_renderEditor()} - - + updateEditor(); + } + }} + children={ + { + willRefresh = true; + }} + hasColors={true} + hasTags={true} + rowItems={['Add to', 'Share', 'Export', 'Delete']} + columnItems={['Dark Mode', 'Add to Vault', 'Pin', 'Favorite']} + close={value => { + if (value) { + show = value; + } + ActionSheet._setModalVisible(); + }} + /> + } + /> ); };