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

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