From ccf24e513b29816598f7891167390e89653b47ff Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 16 Sep 2015 19:20:25 +0430 Subject: [PATCH] Don't allow dialogs' inputs to be empty, show an error in that case --- build/main.js | 29 +++++++++++++++++++++++++---- src/js/dialogs.js | 29 +++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/build/main.js b/build/main.js index b1ef892..06c51d3 100644 --- a/build/main.js +++ b/build/main.js @@ -31593,6 +31593,7 @@ var _store = require('store'); var _store2 = _interopRequireDefault(_store); var INVALID_NAME = 'Please enter a valid name.'; +var INVALID_SEARCH = 'You can\'t leave the input empty'; exports['default'] = { createDialog: { @@ -31604,7 +31605,12 @@ exports['default'] = { action: function action() { var input = _react2['default'].findDOMNode(this.refs.input); - if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME }); + if (!input.value) { + this.props.dispatch((0, _actionsDialog.hideAll)()); + this.props.dispatch((0, _actionsFile.active)()); + this.props.dispatch((0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME })); + return; + } var cwd = _store2['default'].getState().get('cwd'); var path = cwd + '/' + input.value; @@ -31619,7 +31625,12 @@ exports['default'] = { action: function action() { var input = _react2['default'].findDOMNode(this.refs.input); - if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME }); + if (!input.value) { + this.props.dispatch((0, _actionsDialog.hideAll)()); + this.props.dispatch((0, _actionsFile.active)()); + this.props.dispatch((0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME })); + return; + } var cwd = _store2['default'].getState().get('cwd'); var path = cwd + '/' + input.value; @@ -31654,7 +31665,12 @@ exports['default'] = { action: function action() { var input = _react2['default'].findDOMNode(this.refs.input); - if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME }); + if (!input.value) { + this.props.dispatch((0, _actionsDialog.hideAll)()); + this.props.dispatch((0, _actionsFile.active)()); + this.props.dispatch((0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME })); + return; + } var activeFile = _store2['default'].getState().get('activeFile'); this.props.dispatch((0, _actionsFile.rename)(activeFile, input.value)); @@ -31705,7 +31721,12 @@ exports['default'] = { action: function action() { var input = _react2['default'].findDOMNode(this.refs.input); - if (!input.value) (0, _actionsDialog.show)('errorDialog', { description: INVALID_NAME }); + if (!input.value) { + this.props.dispatch((0, _actionsDialog.hideAll)()); + this.props.dispatch((0, _actionsFile.active)()); + this.props.dispatch((0, _actionsDialog.show)('errorDialog', { description: INVALID_SEARCH })); + return; + } var action = (0, _actionsFilesView.search)(input.value); this.props.dispatch(action); diff --git a/src/js/dialogs.js b/src/js/dialogs.js index 624c4e2..608a4c2 100644 --- a/src/js/dialogs.js +++ b/src/js/dialogs.js @@ -5,6 +5,7 @@ import { search } from 'actions/files-view'; import store, { bind } from 'store'; const INVALID_NAME = 'Please enter a valid name.'; +const INVALID_SEARCH = 'You can\'t leave the input empty'; export default { createDialog: { @@ -17,7 +18,12 @@ export default { action() { let input = React.findDOMNode(this.refs.input); - if (!input.value) show('errorDialog', {description: INVALID_NAME}); + if (!input.value) { + this.props.dispatch(hideAll()); + this.props.dispatch(active()); + this.props.dispatch(show('errorDialog', {description: INVALID_NAME})); + return; + } let cwd = store.getState().get('cwd'); let path = cwd + '/' + input.value; @@ -33,7 +39,12 @@ export default { action() { let input = React.findDOMNode(this.refs.input); - if (!input.value) show('errorDialog', {description: INVALID_NAME}); + if (!input.value) { + this.props.dispatch(hideAll()); + this.props.dispatch(active()); + this.props.dispatch(show('errorDialog', {description: INVALID_NAME})); + return; + } let cwd = store.getState().get('cwd'); let path = cwd + '/' + input.value; @@ -72,7 +83,12 @@ export default { action() { let input = React.findDOMNode(this.refs.input); - if (!input.value) show('errorDialog', {description: INVALID_NAME}); + if (!input.value) { + this.props.dispatch(hideAll()); + this.props.dispatch(active()); + this.props.dispatch(show('errorDialog', {description: INVALID_NAME})); + return; + } let activeFile = store.getState().get('activeFile'); this.props.dispatch(rename(activeFile, input.value)) @@ -129,7 +145,12 @@ export default { action() { let input = React.findDOMNode(this.refs.input); - if (!input.value) show('errorDialog', {description: INVALID_NAME}); + if (!input.value) { + this.props.dispatch(hideAll()); + this.props.dispatch(active()); + this.props.dispatch(show('errorDialog', {description: INVALID_SEARCH})); + return; + } let action = search(input.value); this.props.dispatch(action);