feat(archive-name): ask for a name to set for new archives

resolve #13
This commit is contained in:
Mahdi Dibaiee 2015-10-24 19:41:54 +03:30
parent 735ef7fa7b
commit 1833a5e3c1
7 changed files with 98 additions and 22 deletions

View File

@ -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);

View File

@ -1,9 +1,9 @@
import { COMPRESS, DECOMPRESS } from './types';
export function compress(file) {
export function compress(file, name) {
return {
type: COMPRESS,
file
file, name
}
}

View File

@ -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 {
<ErrorDialog />
<CreateDialog />
<SearchDialog />
<CompressDialog />
<Spinner />

View File

@ -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'
}
]
}
}

View File

@ -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'));
}
}
]

View File

@ -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')
});
}

View File

@ -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);