From 1833a5e3c119dbd3c744c861e162115261e20ae7 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sat, 24 Oct 2015 19:41:54 +0330 Subject: [PATCH] feat(archive-name): ask for a name to set for new archives resolve #13 --- build/main.js | 59 +++++++++++++++++++++++++++++++------- src/js/actions/compress.js | 4 +-- src/js/components/root.js | 2 ++ src/js/dialogs.js | 40 +++++++++++++++++++++++++- src/js/menus.js | 10 +++---- src/js/reducers/all.js | 3 +- src/js/reducers/files.js | 2 +- 7 files changed, 98 insertions(+), 22 deletions(-) diff --git a/build/main.js b/build/main.js index 7f7cd68..5bb13b6 100644 --- a/build/main.js +++ b/build/main.js @@ -40551,10 +40551,10 @@ exports.decompress = decompress; var _types = require('./types'); -function compress(file) { +function compress(file, name) { return { type: _types.COMPRESS, - file: file + file: file, name: name }; } @@ -42394,6 +42394,9 @@ var CreateDialog = (0, _reactRedux.connect)(function (state) { var SearchDialog = (0, _reactRedux.connect)(function (state) { return state.get('searchDialog'); })(_componentsDialog2['default']); +var CompressDialog = (0, _reactRedux.connect)(function (state) { + return state.get('compressDialog'); +})(_componentsDialog2['default']); var Root = (function (_Component) { _inherits(Root, _Component); @@ -42423,6 +42426,7 @@ var Root = (function (_Component) { _react2['default'].createElement(ErrorDialog, null), _react2['default'].createElement(CreateDialog, null), _react2['default'].createElement(SearchDialog, null), + _react2['default'].createElement(CompressDialog, null), _react2['default'].createElement(_componentsSpinner2['default'], null), _react2['default'].createElement('div', { className: 'swipe-instruction tour-item' }), _react2['default'].createElement( @@ -42691,6 +42695,8 @@ var _actionsFile = require('actions/file'); var _actionsFilesView = require('actions/files-view'); +var _actionsCompress = require('actions/compress'); + var _store = require('store'); var _store2 = _interopRequireDefault(_store); @@ -42838,11 +42844,43 @@ exports['default'] = { }, className: 'success' }] + }, + compressDialog: { + title: 'Archive', + description: 'Enter your desired archive name', + input: true, + buttons: [{ + text: 'Cancel', + action: function action() { + var input = _react2['default'].findDOMNode(this.refs.input); + this.props.dispatch((0, _actionsDialog.hideAll)()); + input.value = ''; + } + }, { + text: 'Create', + action: function action() { + var input = _react2['default'].findDOMNode(this.refs.input); + + 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, _actionsCompress.compress)(activeFile, input.value)); + this.props.dispatch((0, _actionsDialog.hideAll)()); + this.props.dispatch((0, _actionsFile.active)()); + input.value = ''; + }, + className: 'success' + }] } }; module.exports = exports['default']; -},{"actions/dialog":262,"actions/file":263,"actions/files-view":264,"react":250,"store":"store"}],286:[function(require,module,exports){ +},{"actions/compress":261,"actions/dialog":262,"actions/file":263,"actions/files-view":264,"react":250,"store":"store"}],286:[function(require,module,exports){ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } @@ -42966,9 +43004,8 @@ var entryMenu = { }, { name: 'Archive', action: function action() { - var active = _store2['default'].getState().get('activeFile'); - - _store2['default'].dispatch((0, _actionsCompress.compress)(active)); + _store2['default'].dispatch((0, _actionsMenu.hideAll)()); + _store2['default'].dispatch((0, _actionsDialog.show)('compressDialog')); } }] }; @@ -43044,9 +43081,8 @@ var moreMenu = { }, { name: 'Archive', action: function action() { - var active = _store2['default'].getState().get('activeFile'); - - _store2['default'].dispatch((0, _actionsCompress.compress)(active)); + _store2['default'].dispatch((0, _actionsMenu.hideAll)()); + _store2['default'].dispatch((0, _actionsDialog.show)('compressDialog')); } }] }; @@ -43162,7 +43198,8 @@ exports['default'] = function (state, action) { deleteDialog: (0, _dialog2['default'])(state, action, 'deleteDialog'), errorDialog: (0, _dialog2['default'])(state, action, 'errorDialog'), createDialog: (0, _dialog2['default'])(state, action, 'createDialog'), - searchDialog: (0, _dialog2['default'])(state, action, 'searchDialog') + searchDialog: (0, _dialog2['default'])(state, action, 'searchDialog'), + compressDialog: (0, _dialog2['default'])(state, action, 'compressDialog') }); }; @@ -43408,7 +43445,7 @@ exports['default'] = function (state, action) { var blob = new Blob([buffer], { type: 'application/zip' }); var cwd = _store2['default'].getState().get('cwd'); - var path = (0, _utils.normalize)(cwd + '/archive.zip'); + var path = (0, _utils.normalize)(cwd + '/' + action.name); return (0, _apiFiles.writeFile)(path, blob); }).then(boundRefresh)['catch'](_utils.reportError); diff --git a/src/js/actions/compress.js b/src/js/actions/compress.js index 5619ed1..8ca2fdf 100644 --- a/src/js/actions/compress.js +++ b/src/js/actions/compress.js @@ -1,9 +1,9 @@ import { COMPRESS, DECOMPRESS } from './types'; -export function compress(file) { +export function compress(file, name) { return { type: COMPRESS, - file + file, name } } diff --git a/src/js/components/root.js b/src/js/components/root.js index 67a7f83..3eeb459 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -27,6 +27,7 @@ let DeleteDialog = connect(state => state.get('deleteDialog'))(Dialog); let ErrorDialog = connect(state => state.get('errorDialog'))(Dialog); let CreateDialog = connect(state => state.get('createDialog'))(Dialog); let SearchDialog = connect(state => state.get('searchDialog'))(Dialog); +let CompressDialog = connect(state => state.get('compressDialog'))(Dialog); export default class Root extends Component { render() { @@ -47,6 +48,7 @@ export default class Root extends Component { + diff --git a/src/js/dialogs.js b/src/js/dialogs.js index 608a4c2..3537f91 100644 --- a/src/js/dialogs.js +++ b/src/js/dialogs.js @@ -2,6 +2,7 @@ import React from 'react'; import { hide, hideAll, show } from 'actions/dialog'; import { rename, remove, create, active } from 'actions/file'; import { search } from 'actions/files-view'; +import { compress } from 'actions/compress'; import store, { bind } from 'store'; const INVALID_NAME = 'Please enter a valid name.'; @@ -148,7 +149,8 @@ export default { if (!input.value) { this.props.dispatch(hideAll()); this.props.dispatch(active()); - this.props.dispatch(show('errorDialog', {description: INVALID_SEARCH})); + this.props.dispatch(show('errorDialog', + {description: INVALID_SEARCH})); return; } @@ -160,5 +162,41 @@ export default { className: 'success' } ] + }, + compressDialog: { + title: 'Archive', + description: 'Enter your desired archive name', + input: true, + buttons: [ + { + text: 'Cancel', + action() { + let input = React.findDOMNode(this.refs.input); + this.props.dispatch(hideAll()); + input.value = ''; + } + }, + { + text: 'Create', + action() { + let input = React.findDOMNode(this.refs.input); + + 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(compress(activeFile, input.value)) + this.props.dispatch(hideAll()); + this.props.dispatch(active()); + input.value = ''; + }, + className: 'success' + } + ] } } diff --git a/src/js/menus.js b/src/js/menus.js index 63dcaf0..bdd1749 100644 --- a/src/js/menus.js +++ b/src/js/menus.js @@ -83,9 +83,8 @@ const entryMenu = { { name: 'Archive', action() { - let active = store.getState().get('activeFile'); - - store.dispatch(compress(active)); + store.dispatch(hideAll()); + store.dispatch(show('compressDialog')); } } ] @@ -168,9 +167,8 @@ const moreMenu = { { name: 'Archive', action() { - let active = store.getState().get('activeFile'); - - store.dispatch(compress(active)); + store.dispatch(hideAll()); + store.dispatch(show('compressDialog')); } } ] diff --git a/src/js/reducers/all.js b/src/js/reducers/all.js index 4ead10e..00e8e45 100644 --- a/src/js/reducers/all.js +++ b/src/js/reducers/all.js @@ -32,6 +32,7 @@ export default function(state = new Immutable.Map(), action) { deleteDialog: dialog(state, action, 'deleteDialog'), errorDialog: dialog(state, action, 'errorDialog'), createDialog: dialog(state, action, 'createDialog'), - searchDialog: dialog(state, action, 'searchDialog') + searchDialog: dialog(state, action, 'searchDialog'), + compressDialog: dialog(state, action, 'compressDialog') }); } diff --git a/src/js/reducers/files.js b/src/js/reducers/files.js index de07092..8c1f60b 100644 --- a/src/js/reducers/files.js +++ b/src/js/reducers/files.js @@ -118,7 +118,7 @@ export default function(state = [], action) { let blob = new Blob([buffer], { type: 'application/zip' }); let cwd = store.getState().get('cwd'); - let path = normalize(cwd + '/archive.zip'); + let path = normalize(cwd + '/' + action.name); return writeFile(path, blob); }).then(boundRefresh).catch(reportError);