Skip to content

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

fixing hooks for movecopyfilesdialog

Ilian Sapundshiev3081c156688c
diff --git a/app/components/EntryProperties.js b/app/components/EntryProperties.js
index c999d8a39..9e4fca513 100644
--- a/app/components/EntryProperties.js
+++ b/app/components/EntryProperties.js
@@ -18,6 +18,7 @@
*/
import React, { Component } from 'react';
+import uuidv1 from 'uuid';
import marked from 'marked';
import { withStyles } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
@@ -39,6 +40,7 @@ import AppConfig from '../config';
import { Pro } from '../pro';
import TagsSelect from './TagsSelect';
import TransparentBackground from './TransparentBackground';
+import { UUID } from 'builder-util-runtime';
const styles = theme => ({
entryProperties: {
@@ -767,6 +769,7 @@ class EntryProperties extends Component<Props, State> {
editTagForEntry={editTagForEntry}
/>
<MoveCopyFilesDialog
+ key={uuidv1()}
open={isMoveCopyFilesDialogOpened}
onClose={this.toggleMoveCopyFilesDialog}
selectedFiles={[entryPath]}
diff --git a/app/components/FolderContainer.js b/app/components/FolderContainer.js
index 4cd7f09d9..80ab8b33a 100644
--- a/app/components/FolderContainer.js
+++ b/app/components/FolderContainer.js
@@ -184,7 +184,7 @@ class FolderContainer extends React.Component<Props, State> {
pathParts.push(normalizedCurrentPath.substring(PlatformIO.haveObjectStoreSupport() ? 2 : 1));
normalizedCurrentPath = normalizedCurrentPath.substring(0, normalizedCurrentPath.lastIndexOf('/'));
}
- console.log('Path parts : ' + JSON.stringify(pathParts));
+ // console.log('Path parts : ' + JSON.stringify(pathParts));
if (pathParts.length >= 1) {
pathParts = pathParts.slice(1, pathParts.length); // remove current directory
}
diff --git a/app/components/dialogs/MoveCopyFilesDialog.js b/app/components/dialogs/MoveCopyFilesDialog.js
index 6f458fb8e..77b88aa37 100644
--- a/app/components/dialogs/MoveCopyFilesDialog.js
+++ b/app/components/dialogs/MoveCopyFilesDialog.js
@@ -17,7 +17,7 @@
* @flow
*/
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Button from '@material-ui/core/Button';
@@ -46,24 +46,28 @@ import { extractFileName } from '../../utils/paths';
type Props = {
classes: Object,
- open?: boolean,
+ open: boolean,
onClose: () => void,
copyFiles: (files: Array<string>, destination: string) => void,
moveFiles: (files: Array<string>, destination: string) => void,
selectedFiles: Array<string>
};
-const MoveCopyFilesDialog = (props: Props) => { // state = {
- const [inputError, setInputError] = useState(false); // inputError: false,
- const [disableConfirmButton, setDisableConfirmButton] = useState(true); // disableConfirmButton: true,
- const [targetPath, setTargetPath] = useState(''); // targetPath: ''
+const MoveCopyFilesDialog = (props: Props) => {
+ const [inputError, setInputError] = useState(false);
+ const [disableConfirmButton, setDisableConfirmButton] = useState(true);
+ const [targetPath, setTargetPath] = useState('');
+
+ useEffect(() => {
+ handleValidation();
+ });
function handleValidation() {
if (targetPath && targetPath.length > 0) {
- setInputError(false); //this.setState({ inputError: false, disableConfirmButton: false });
+ setInputError(false);
setDisableConfirmButton(false);
} else {
- setInputError(true); // this.setState({ inputError: true, disableConfirmButton: true });
+ setInputError(true);
setDisableConfirmButton(true);
}
}
@@ -71,41 +75,27 @@ const MoveCopyFilesDialog = (props: Props) => { // state = {
function handleCopyFiles() {
if (!disableConfirmButton) {
props.copyFiles(props.selectedFiles, targetPath);
- // this.setState({
- setInputError(false);
- setDisableConfirmButton(true);
- setTargetPath('');
- };
- props.onClose();
+ setInputError(false);
+ setDisableConfirmButton(true);
+ setTargetPath('');
+ }
+ props.onClose();
}
function handleMoveFiles() {
if (!disableConfirmButton) {
props.moveFiles(props.selectedFiles, targetPath);
- // this.setState({
- setInputError(false);
- setDisableConfirmButton(true);
- setTargetPath('');
- };
- props.onClose();
- }
-
- handleInputChange(event: Object) {
- const target = event.target;
- const value = target.type === 'checkbox' ? target.checked : target.value;
- const name = target.name;
-
- this.setState({
- [name]: value
- }, this.handleValidation);
+ setInputError(false);
+ setDisableConfirmButton(true);
+ setTargetPath('');
+ }
+ props.onClose();
}
function selectDirectory() {
if (AppConfig.isElectron) {
PlatformIO.selectDirectoryDialog().then(selectedPaths => {
- setTargetPath(selectedPaths[0]); // this.setState({
- // targetPath: selectedPaths[0],
- handleValidation();
+ setTargetPath(selectedPaths[0]);
return true;
}).catch((err) => {
console.log('selectDirectoryDialog failed with: ' + err);
@@ -144,7 +134,10 @@ const MoveCopyFilesDialog = (props: Props) => { // state = {
placeholder={i18n.t('core:moveCopyToPath')}
fullWidth={true}
data-tid="targetPathInput"
- onChange={e => handleInputChange(e)}
+ onChange={event => {
+ const target = event.target;
+ setTargetPath(target.value);
+ }}
value={targetPath}
endAdornment={
PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb ? undefined :
@@ -193,19 +186,17 @@ const MoveCopyFilesDialog = (props: Props) => { // state = {
);
}
- render() {
- return (
- <GenericDialog
- open={props.open}
- onClose={props.onClose}
- // onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}
- renderTitle={renderTitle}
- renderContent={renderContent}
- renderActions={renderActions}
- />
- );
- }
-}
+ return (
+ <GenericDialog
+ open={props.open}
+ onClose={props.onClose}
+ // onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}
+ renderTitle={renderTitle}
+ renderContent={renderContent}
+ renderActions={renderActions}
+ />
+ );
+};
function mapActionCreatorsToProps(dispatch) {
return bindActionCreators({
diff --git a/app/perspectives/grid-perspective/src/index.js b/app/perspectives/grid-perspective/src/index.js
index dbdb0827c..d1288bf9a 100644
--- a/app/perspectives/grid-perspective/src/index.js
+++ b/app/perspectives/grid-perspective/src/index.js
@@ -18,6 +18,7 @@
*/
import React from 'react';
+import uuidv1 from 'uuid';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import removeMd from 'remove-markdown';
@@ -1021,6 +1022,7 @@ class GridPerspective extends React.Component<Props, State> {
selectedEntries={this.props.selectedEntries}
/>
<MoveCopyFilesDialog
+ key={uuidv1()}
open={this.state.isMoveCopyFilesDialogOpened}
onClose={this.handleCloseDialogs}
selectedFiles={selectedFilePaths}