Skip to content

TagSpaces is an offline, open source, document manager with tagging support

resetState and fixes

Stanimir Marinovd137998e2a29
diff --git a/app/components/VerticalNavigation.js b/app/components/VerticalNavigation.js
index adabc0699..4a3c2a6fe 100644
--- a/app/components/VerticalNavigation.js
+++ b/app/components/VerticalNavigation.js
@@ -20,6 +20,7 @@
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
+import uuidv1 from 'uuid';
import IconButton from '@material-ui/core/IconButton';
import NewFileIcon from '@material-ui/icons/Add';
import LocationsIcon from '@material-ui/icons/WorkOutline';
@@ -99,7 +100,8 @@ type State = {
isTagLibraryVisible?: boolean,
isSearchVisible?: boolean,
isPerspectiveManagerVisible?: boolean,
- isManagementPanelVisible?: boolean // evtl. redux migration
+ isManagementPanelVisible?: boolean, // evtl. redux migration
+ CreateFileDialogKey: string
};
class VerticalNavigation extends React.Component<Props, State> {
@@ -109,6 +111,7 @@ class VerticalNavigation extends React.Component<Props, State> {
isSearchVisible: false,
isPerspectiveManagerVisible: false,
isManagementPanelVisible: true,
+ CreateFileDialogKey: uuidv1(),
};
componentWillReceiveProps(nextProps: Props) {
@@ -225,6 +228,12 @@ class VerticalNavigation extends React.Component<Props, State> {
});
};
+ resetState = (dialogKey) => {
+ this.setState({
+ [dialogKey]: uuidv1()
+ });
+ };
+
render() {
return (
<div>
@@ -256,8 +265,11 @@ class VerticalNavigation extends React.Component<Props, State> {
onClose={this.props.toggleSettingsDialog}
/>
<CreateFileDialog
+ key={this.state.CreateFileDialogKey}
+ resetState={this.resetState}
open={this.props.isCreateFileDialogOpened}
selectedDirectoryPath={this.state.selectedDirectoryPath || this.props.currentDirectory}
+ chooseDirectoryPath={this.chooseDirectoryPath}
onClose={this.props.toggleCreateFileDialog}
/>
<SelectDirectoryDialog
diff --git a/app/components/dialogs/CreateFileDialog.js b/app/components/dialogs/CreateFileDialog.js
index 561a4a5a5..08a343fde 100644
--- a/app/components/dialogs/CreateFileDialog.js
+++ b/app/components/dialogs/CreateFileDialog.js
@@ -37,11 +37,10 @@ import InputLabel from '@material-ui/core/InputLabel';
import InputAdornment from '@material-ui/core/InputAdornment';
import GenericDialog, { onEnterKeyHandler } from './GenericDialog';
import i18n from '../../services/i18n';
-import { type Tag } from '../../reducers/taglibrary';
import { formatDateTime4Tag } from '../../utils/misc';
import AppConfig from '../../config';
import TaggingActions from '../../reducers/tagging-actions';
-import { actions as AppActions, getDirectoryPath } from '../../reducers/app';
+import { actions as AppActions } from '../../reducers/app';
import PlatformIO from '../../services/platform-io';
const styles = theme => ({
@@ -71,9 +70,11 @@ type Props = {
onClose: () => void,
showSelectDirectoryDialog: () => void,
selectedDirectoryPath?: string,
- createDirectory: (directoryPath: string) => void,
+ // createDirectory: (directoryPath: string) => void,
+ chooseDirectoryPath: (directoryPath: string) => void,
createFileAdvanced: (targetPath: string, fileName: string, content: string, fileType: string) => void,
- allTags: Array<Tag>
+ // allTags: Array<Tag>,
+ resetState: () => void
};
type State = {
@@ -82,9 +83,9 @@ type State = {
fileName?: string,
fileContent?: string,
fileType?: string,
- suggestionTags?: Array<Tag>,
- newlyAddedTags?: Array,
- allTags?: Array
+ // suggestionTags?: Array<Tag>,
+ // newlyAddedTags?: Array
+ // allTags?: Array
};
class CreateFileDialog extends React.Component<Props, State> {
@@ -97,9 +98,9 @@ class CreateFileDialog extends React.Component<Props, State> {
fileName: 'new note ' + AppConfig.beginTagContainer + formatDateTime4Tag(new Date(), true) + AppConfig.endTagContainer,
fileContent: '',
fileType: 'txt',
- suggestionTags: [],
- newlyAddedTags: [],
- allTags: []
+ // suggestionTags: [],
+ // newlyAddedTags: [],
+ // allTags: []
};
/* componentWillReceiveProps = (nextProps: any) => {
@@ -151,7 +152,17 @@ class CreateFileDialog extends React.Component<Props, State> {
}
openFolderChooser = () => {
- this.props.showSelectDirectoryDialog();
+ if (AppConfig.isElectron) {
+ PlatformIO.selectDirectoryDialog().then(selectedPaths => {
+ this.props.chooseDirectoryPath(selectedPaths[0]);
+ this.handleValidation();
+ return true;
+ }).catch((err) => {
+ console.log('selectDirectoryDialog failed with: ' + err);
+ });
+ } else {
+ this.props.showSelectDirectoryDialog();
+ }
};
showSelectDirectoryDialog = () => {
@@ -160,7 +171,7 @@ class CreateFileDialog extends React.Component<Props, State> {
});
};
- onAddTag = (tag) => {
+ /* onAddTag = (tag) => {
const { newlyAddedTags } = this.state;
newlyAddedTags.push(tag);
this.setState({ newlyAddedTags });
@@ -170,21 +181,23 @@ class CreateFileDialog extends React.Component<Props, State> {
const { newlyAddedTags } = this.state;
const modifiedTags = newlyAddedTags.filter(addedTag => addedTag.title !== tag.title);
this.setState({ newlyAddedTags: modifiedTags });
- };
+ }; */
onConfirm = () => {
if (!this.state.disableConfirmButton) {
const { fileName, fileContent, fileType } = this.state;
this.props.createFileAdvanced(this.props.selectedDirectoryPath, fileName, fileContent, fileType);
this.props.onClose();
+ this.props.chooseDirectoryPath(undefined);
+ this.props.resetState('CreateFileDialogKey');
}
};
- addedTags = (tags) => {
+ /* addedTags = (tags) => {
this.setState({
suggestionTags: tags,
});
- };
+ }; */
handleKeyPress = (event: any) => {
if (event.key === 'Enter' || event.keyCode === 13) {
@@ -303,6 +316,8 @@ class CreateFileDialog extends React.Component<Props, State> {
onClick={() => {
// this.setState({ newlyAddedTags: [] });
this.props.onClose();
+ this.props.chooseDirectoryPath(undefined);
+ this.props.resetState('CreateFileDialogKey');
}}
color="primary"
>
@@ -323,7 +338,11 @@ class CreateFileDialog extends React.Component<Props, State> {
return (
<GenericDialog
open={this.props.open}
- onClose={this.props.onClose}
+ onClose={() => {
+ this.props.chooseDirectoryPath(undefined);
+ this.props.resetState('CreateFileDialogKey');
+ this.props.onClose();
+ }}
onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}
renderTitle={this.renderTitle}
renderContent={this.renderContent}
@@ -333,12 +352,6 @@ class CreateFileDialog extends React.Component<Props, State> {
}
}
-function mapStateToProps(state) {
- return {
- selectedDirectoryPath: getDirectoryPath(state),
- };
-}
-
function mapActionCreatorsToProps(dispatch) {
return bindActionCreators({
createFileAdvanced: AppActions.createFileAdvanced,
@@ -347,4 +360,4 @@ function mapActionCreatorsToProps(dispatch) {
}, dispatch);
}
-export default connect(mapStateToProps, mapActionCreatorsToProps)(withStyles(styles)(CreateFileDialog));
+export default connect(undefined, mapActionCreatorsToProps)(withStyles(styles)(CreateFileDialog));