TagSpaces is an offline, open source, document manager with tagging support
improving drawer visibility in mobile mode
Ilian Sapundshiev69f639ab9359
diff --git a/app/components/FolderContainer.js b/app/components/FolderContainer.jsindex 6a7733560..95b34e45d 100644--- a/app/components/FolderContainer.js+++ b/app/components/FolderContainer.js@@ -188,7 +188,7 @@ type Props = {isDesktopMode: boolean,showNotification: (content: string) => void,openSearchPanel: () => void,- toggleDrawer: () => void,+ showDrawer: () => void,maxSearchResults: number};@@ -424,7 +424,7 @@ class FolderContainer extends React.Component<Props, State> {classes,maxSearchResults,openSearchPanel,- toggleDrawer,+ showDrawer,isDesktopMode,loadParentDirectoryContent} = this.props;@@ -441,7 +441,7 @@ class FolderContainer extends React.Component<Props, State> {{isDesktopMode ? (<LocationMenu />) : (- <Button style={{ marginLeft: -8 }} onClick={toggleDrawer}>+ <Button style={{ marginLeft: -8 }} onClick={showDrawer}><MenuIcon /></Button>)}diff --git a/app/components/LocationManager.js b/app/components/LocationManager.jsindex 384161d3a..06fa54a22 100644--- a/app/components/LocationManager.js+++ b/app/components/LocationManager.js@@ -79,6 +79,7 @@ type Props = {perspectives: Array<Object>,currentLocationId: string,isReadOnlyMode: boolean,+ hideDrawer?: () => void,loadDirectoryContent: (path: string) => void,openLocation: (location: Location) => void,openFileNatively: (path: string) => void,@@ -236,7 +237,7 @@ class LocationManager extends React.Component<Props, State> {.catch(error => {console.log('getDirectoriesTree', error);})- ;+ ;/*** https://codereview.stackexchange.com/questions/47932/recursion-vs-iteration-of-tree-structure@@ -455,6 +456,9 @@ class LocationManager extends React.Component<Props, State> {this.loadSubDirectories(location, 1);this.props.openLocation(location);this.state.locationRootPath = location.paths[0];+ if (this.props.hideDrawer) {+ this.props.hideDrawer();+ }}// const grid = document.querySelector('[data-tid="perspectiveGridFileTable"]');@@ -551,7 +555,7 @@ class LocationManager extends React.Component<Props, State> {<TargetMoveFileBox accepts={[DragItemTypes.FILE]} onDrop={this.handleFileMoveDrop} >{props.children}</TargetMoveFileBox></td>)- ;+ ;// <Tooltip id="tooltip-icon" title={i18n.t('core:moreOperations')} placement="bottom"></Tooltip>renderLocation = (location: Location) => {@@ -581,11 +585,11 @@ class LocationManager extends React.Component<Props, State> {columns={columns}// expandedRowRender={this.expandedRowRender}onExpand={this.onExpand}- // expandIcon={this.CustomExpandIcon}- // expandIconAsCell- /* onRow={(record, index) => ({- onClick: this.onRowClick.bind(null, record, index),- })} */+ // expandIcon={this.CustomExpandIcon}+ // expandIconAsCell+ /* onRow={(record, index) => ({+ onClick: this.onRowClick.bind(null, record, index),+ })} *//>);}return (@@ -609,7 +613,7 @@ class LocationManager extends React.Component<Props, State> {// }}style={{ minWidth: 'auto' }}>- { location.type === locationType.TYPE_CLOUD ?+ {location.type === locationType.TYPE_CLOUD ?(<CloudLocationIcon className={this.props.classes.icon} />) :(<LocationIcon className={this.props.classes.icon} />)}@@ -625,7 +629,7 @@ class LocationManager extends React.Component<Props, State> {{location.name}</Typography></div>- { !isLocationsReadOnly && (+ {!isLocationsReadOnly && (<ListItemSecondaryAction><IconButtonaria-label={i18n.t('core:options')}@@ -658,7 +662,7 @@ class LocationManager extends React.Component<Props, State> {{i18n.t('core:locationManager')}</Typography></div>- { !isLocationsReadOnly && (+ {!isLocationsReadOnly && (<div style={{ width: '100%', textAlign: 'center', marginBottom: 10 }}><Buttondata-tid="createNewLocation"@@ -740,7 +744,7 @@ class LocationManager extends React.Component<Props, State> {</ListItemIcon><ListItemText primary={i18n.t('core:editLocationTitle')} /></MenuItem>- { this.state.selectedLocation && this.props.currentLocationId === this.state.selectedLocation.uuid && (+ {this.state.selectedLocation && this.props.currentLocationId === this.state.selectedLocation.uuid && (<MenuItemdata-tid="indexLocation"onClick={this.indexLocation}diff --git a/app/components/MobileNavigation.js b/app/components/MobileNavigation.jsindex 1a80c7a5b..bc9511317 100644--- a/app/components/MobileNavigation.js+++ b/app/components/MobileNavigation.js@@ -93,7 +93,7 @@ type Props = {openFileNatively: (url: string) => void,openURLExternally: (url: string) => void,switchTheme: () => void,- toggleDrawer: () => void,+ hideDrawer: () => void,isReadOnlyMode: boolean};@@ -133,7 +133,7 @@ class MobileNavigation extends React.Component<Props, State> {openHelpFeedbackPanel,closeAllVerticalPanels,switchTheme,- toggleDrawer,+ hideDrawer,openFileNatively,openURLExternally,} = this.props;@@ -147,9 +147,9 @@ class MobileNavigation extends React.Component<Props, State> {`}</style><div style={{ width: 300, maxWidth: 300, height: 'calc(100% - 60px)' }}>- <LocationManager style={{ display: isLocationManagerPanelOpened ? 'block' : 'none' }} />+ <LocationManager hideDrawer={hideDrawer} style={{ display: isLocationManagerPanelOpened ? 'block' : 'none' }} />{isTagLibraryPanelOpened && <TagLibrary />}- <Search style={{ display: isSearchPanelOpened ? 'block' : 'none' }} />+ <Search hideDrawer={hideDrawer} style={{ display: isSearchPanelOpened ? 'block' : 'none' }} />{isPerspectivesPanelOpened && <PerspectiveManager />}{isHelpFeedbackPanelOpened && <HelpFeedbackPanelopenFileNatively={openFileNatively}@@ -166,7 +166,7 @@ class MobileNavigation extends React.Component<Props, State> {data-tid="settings"onClick={() => {toggleSettingsDialog();- toggleDrawer();+ hideDrawer();}}style={{ marginTop: -15, marginRight: 10 }}>@@ -218,7 +218,7 @@ class MobileNavigation extends React.Component<Props, State> {id="verticalNavButton"onClick={() => {toggleCreateFileDialog();- toggleDrawer();+ hideDrawer();}}style={{ marginTop: -15, marginLeft: 10 }}title={i18n.t('core:createFileTitle')}diff --git a/app/components/Search.js b/app/components/Search.jsindex d95a98396..fdbad4f29 100644--- a/app/components/Search.js+++ b/app/components/Search.js@@ -74,6 +74,7 @@ type Props = {style: Object,searchLocationIndex: (searchQuery: SearchQuery) => void,loadDirectoryContent: (path: string) => void,+ hideDrawer?: () => void,currentDirectory: string,indexedEntriesCount: number,maxSearchResults: number,@@ -251,6 +252,9 @@ class Search extends React.Component<Props, State> {};console.log('Search object: ' + JSON.stringify(searchQuery));this.props.searchLocationIndex(searchQuery);+ if (this.props.hideDrawer) {+ this.props.hideDrawer();+ }};render() {diff --git a/app/components/dialogs/CreateDialog.js b/app/components/dialogs/CreateDialog.jsnew file mode 100644index 000000000..8440a6902--- /dev/null+++ b/app/components/dialogs/CreateDialog.js@@ -0,0 +1,193 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * @flow+ */++import React from 'react';+import { connect } from 'react-redux';+import { bindActionCreators } from 'redux';+import Button from '@material-ui/core/Button';+import DialogActions from '@material-ui/core/DialogActions';+import DialogContent from '@material-ui/core/DialogContent';+import DialogTitle from '@material-ui/core/DialogTitle';+import { withStyles } from '@material-ui/core/styles';+import GenericDialog from './GenericDialog';+import i18n from '../../services/i18n';+import { getKeyBindingObject } from '../../reducers/settings';+import { actions as AppActions } from '../../reducers/app';+import AppConfig from '../../config';+import { extractFileName, normalizePath } from '../../utils/paths'; // extractFileExtension+import PlatformIO from '../../services/platform-io';+import { formatDateTime4Tag } from '../../utils/misc';++const styles = theme => ({+ root: {+ minWidth: 350+ },+});++type Props = {+ open: boolean,+ classes: Object,+ createFileAdvanced: (targetPath: string, fileName: string, content: string, fileType: string) => void,+ onClose: () => void+};++const CreateDialog = (props: Props) => {+ let fileInput; // Object | null;++ function addExistingFile() {+ props.onClose();+ fileInput.click();+ }++ // function loadImageLocal() {+ // props.onClose();+ // navigator.camera.getPicture(onCameraSuccess, onFail, {+ // destinationType: Camera.DestinationType.FILE_URI,+ // sourceType: Camera.PictureSourceType.PHOTOLIBRARY+ // });+ // }++ // function cameraTakePicture() {+ // props.onClose();+ // navigator.camera.getPicture(onCameraSuccess, onFail, {+ // // quality: 50,+ // destinationType: Camera.DestinationType.FILE_URI, // DATA_URL, // Return base64 encoded string+ // // encodingType: Camera.EncodingType.JPEG,+ // mediaType: Camera.MediaType.PICTURE // ALLMEDIA+ // });+ // }++ function handleFileInputChange(selection: Object) {+ // console.log("Selected File: "+JSON.stringify(selection.currentTarget.files[0]));+ const file = selection.currentTarget.files[0];+ const filePath =+ normalizePath(props.directoryPath) ++ AppConfig.dirSeparator ++ decodeURIComponent(file.name);++ const reader = new FileReader();+ reader.onload = event => {+ PlatformIO.getPropertiesPromise(filePath).then((entryProps) => {+ if (entryProps) {+ props.showNotification(+ 'File with the same name already exist, importing skipped!',+ 'warning',+ true+ );+ } else {+ PlatformIO.saveBinaryFilePromise(+ filePath,+ event.currentTarget.result,+ true+ )+ .then(() => {+ props.showNotification(+ 'File ' + filePath + ' successfully imported.',+ 'default',+ true+ );+ props.reflectCreateEntry(filePath, true);+ return true;+ })+ .catch(error => {+ // TODO showAlertDialog("Saving " + filePath + " failed.");+ console.error('Save to file ' + filePath + ' failed ' + error);+ props.showNotification(+ 'Importing file ' + filePath + ' failed.',+ 'error',+ true+ );+ return true;+ });+ }+ return true;+ }).catch((err) => {+ console.log('Error getting properties ' + err);+ });+ };++ if (AppConfig.isCordova) {+ reader.readAsDataURL(file);+ } else {+ reader.readAsArrayBuffer(file);+ }+ }++ // {i18n.t('core:createFileTitle')}+ function renderTitle() {+ return (<DialogTitle>Create new content</DialogTitle>);+ }++ function renderContent() {+ return (+ <DialogContent className={props.classes.root} data-tid="keyboardShortCutsDialog">+ bla+ <input+ style={{ display: 'none' }}+ ref={input => {+ fileInput = input;+ }}+ accept="*"+ type="file"+ onChange={handleFileInputChange}+ />+ </DialogContent>+ );+ }++ function renderActions() {+ return (+ <DialogActions>+ <Button+ data-tid="closeKeyboardDialog"+ onClick={props.onClose}+ color="primary"+ >+ {i18n.t('core:ok')}+ </Button>+ </DialogActions>+ );+ }++ return (+ <GenericDialog+ open={props.open}+ onClose={props.onClose}+ renderTitle={renderTitle}+ renderContent={renderContent}+ // renderActions={renderActions}+ />+ );+};++function mapStateToProps(state) {+ return {+ keyBindings: getKeyBindingObject(state),+ };+}++function mapActionCreatorsToProps(dispatch) {+ return bindActionCreators({+ createFileAdvanced: AppActions.createFileAdvanced,+ }, dispatch);+}++export default connect(mapStateToProps, mapActionCreatorsToProps)(+ withStyles(styles)(CreateDialog)+);diff --git a/app/containers/MainPage.js b/app/containers/MainPage.jsindex f8d98c5ac..036c73a0f 100644--- a/app/containers/MainPage.js+++ b/app/containers/MainPage.js@@ -38,7 +38,7 @@ import FolderContainer from '../components/FolderContainer';import EntryContainer from '../components/EntryContainer';import SettingsDialog from '../components/dialogs/settings/SettingsDialog';import CreateDirectoryDialog from '../components/dialogs/CreateDirectoryDialog';-import CreateFileDialog from '../components/dialogs/CreateFileDialog';+import CreateFileDialog from '../components/dialogs/CreateDialog';import {getDesktopMode,getKeyBindingObject,@@ -258,7 +258,7 @@ const SelectDirectoryAsync = props => (type State = {selectedDirectoryPath: string,- isManagementPanelVisible: boolean, // optionality because of https://github.com/codemix/flow-runtime/issues/149+ isManagementPanelVisible: boolean,mainSplitSize: any,isDrawerOpened: boolean,width: number,@@ -327,6 +327,7 @@ class MainPage extends Component<Props, State> {nextProps.isPerspectivesPanelOpened ||nextProps.isHelpFeedbackPanelOpened) {this.setManagementPanelVisibility(true);+ this.showDrawer();}if (!nextProps.isLocationManagerPanelOpened &&@@ -371,12 +372,30 @@ class MainPage extends Component<Props, State> {setManagementPanelVisibility = isVisible => {this.setState({- isManagementPanelVisible: isVisible+ isManagementPanelVisible: isVisible,+ });+ };++ hideDrawer = () => {+ this.props.closeAllVerticalPanels();+ this.setState({+ isDrawerOpened: false+ });+ };++ showDrawer = () => {+ if (!this.props.isLocationManagerPanelOpened && !this.props.isSearchPanelOpened && !this.props.isTagLibraryPanelOpened) {+ this.props.openLocationManagerPanel();+ }+ this.setState({+ isDrawerOpened: true});};toggleDrawer = () => {- this.setState({ isDrawerOpened: !this.state.isDrawerOpened });+ this.setState({+ isDrawerOpened: !this.state.isDrawerOpened,+ });};skipRelease = () => {@@ -493,13 +512,6 @@ class MainPage extends Component<Props, State> {});};- toggleDrawer = () => {- this.setState({- isDrawerOpened: !this.state.isDrawerOpened- });- };--keyBindingHandlers = {toggleShowHiddenEntries: this.props.toggleShowUnixHiddenEntries,showFolderNavigator: this.props.openLocationManagerPanel,@@ -730,13 +742,13 @@ class MainPage extends Component<Props, State> {<React.Fragment><SwipeableDraweropen={this.state.isDrawerOpened}- onClose={this.toggleDrawer}- onOpen={this.toggleDrawer}+ onClose={this.hideDrawer}+ onOpen={this.showDrawer}hysteresis={0.20}disableBackdropTransition={!AppConfig.isIOS}disableDiscovery={AppConfig.isIOS}>- <MobileNavigation toggleDrawer={this.toggleDrawer} />+ <MobileNavigation hideDrawer={this.hideDrawer} /></SwipeableDrawer><SplitPanesplit="vertical"@@ -757,7 +769,7 @@ class MainPage extends Component<Props, State> {<FolderContainerwindowHeight={this.state.height}windowWidth={this.state.width}- toggleDrawer={this.toggleDrawer}+ showDrawer={this.showDrawer}/><EntryContainer /></SplitPane>