feat ContextMenu: Rename and Delete

This commit is contained in:
Mahdi Dibaiee
2015-09-03 15:02:46 +04:30
parent ee6f5d6ffb
commit 79ae4c1a47
94 changed files with 4211 additions and 2216 deletions

View File

@ -0,0 +1,9 @@
import { ACTIVE_FILE } from 'actions/types';
export default function(state = -1, action) {
if (action.type === ACTIVE_FILE) {
return action.file;
}
return state;
}

View File

@ -1,10 +1,23 @@
import Immutable from 'immutable';
import cwd from './cwd';
import lwd from './lwd';
import files from './files';
import navigation from './navigation';
import activeFile from './active-file';
import menu from './menu';
import dialog from './dialog';
export default function(state = new Immutable.Map(), action) {
console.log('action', action);
return new Immutable.Map({
lwd: lwd(state, action), // last working directory
cwd: cwd(state.get('cwd'), action),
files: files(state.get('files'), action)
files: files(state.get('files'), action),
activeFile: activeFile(state.get('activeFile'), action),
navigation: navigation(state.get('navigation'), action),
fileMenu: menu(state, action, 'fileMenu'),
directoryMenu: menu(state, action, 'directoryMenu'),
renameDialog: dialog(state, action, 'renameDialog'),
deleteDialog: dialog(state, action, 'deleteDialog')
});
}

View File

@ -1,16 +1,22 @@
import { CHANGE_DIRECTORY } from 'actions/types';
import { CHANGE_DIRECTORY, REFRESH } from 'actions/types';
import listFiles from 'actions/list-files';
import { children } from 'api/files';
import store from 'store';
export default function(state = '/', action) {
switch (action.type) {
case CHANGE_DIRECTORY:
children(action.dir).then(files => {
store.dispatch(listFiles(files));
});
return action.dir;
default:
return state;
export default function(state = '', action) {
if (action.type === CHANGE_DIRECTORY) {
children(action.dir).then(files => {
store.dispatch(listFiles(files));
});
return action.dir;
}
if (action.type === REFRESH) {
children(state).then(files => {
store.dispatch(listFiles(files));
});
return state;
}
return state;
}

22
src/js/reducers/dialog.js Normal file
View File

@ -0,0 +1,22 @@
import { DIALOG } from 'actions/types';
import Immutable from 'immutable';
export default function(state = new Immutable.Map({}), action, id) {
if (action.type === DIALOG) {
// action applied to all dialogs
if (!action.id) {
return Object.assign({}, state.get(id), {active: action.active});
}
if (action.id !== id) return state.get(id);
let target = state.get(action.id);
let active = action.active === 'toggle' ? !target.get('active') : action.active;
let style = Object.assign({}, state.style, {left: action.x, top: action.y});
return Object.assign({}, target, { style, active });
} else {
return state.get(id);
}
}

View File

@ -1,10 +1,29 @@
import { LIST_FILES } from 'actions/types';
import { LIST_FILES, RENAME_FILE, DELETE_FILE } from 'actions/types';
import { refresh } from 'actions/files-view';
import { rename, sdcard } from 'api/files';
export default function(state = [], action) {
switch (action.type) {
case LIST_FILES:
return action.files;
default:
return state;
if (action.type === LIST_FILES) {
return action.files;
}
if (action.type === RENAME_FILE) {
let file = state[action.file];
rename(file, action.name).then(refresh);
return state;
}
if (action.type === DELETE_FILE) {
let file = state[action.file];
sdcard().delete((file.path || '') + '/' + file.name);
let copy = state.slice(0);
copy.splice(action.file, 1);
return copy;
}
return state;
}

8
src/js/reducers/lwd.js Normal file
View File

@ -0,0 +1,8 @@
import { CHANGE_DIRECTORY } from 'actions/types';
export default function(state = '', action) {
if (action.type === CHANGE_DIRECTORY) {
return state.get('cwd');
}
return state.get('lwd');
}

22
src/js/reducers/menu.js Normal file
View File

@ -0,0 +1,22 @@
import { MENU } from 'actions/types';
import Immutable from 'immutable';
export default function(state = new Immutable.Map({}), action, id) {
if (action.type === MENU) {
// action applied to all menus
if (!action.id) {
return Object.assign({}, state.get(id), {active: action.active});
}
if (action.id !== id) return state.get(id);
let target = state.get(action.id);
let active = action.active === 'toggle' ? !target.get('active') : action.active;
let style = Object.assign({}, state.style, {left: action.x, top: action.y});
return Object.assign({}, target, { style, active });
} else {
return state.get(id);
}
}

View File

@ -0,0 +1,9 @@
import { NAVIGATION, TOGGLE } from 'actions/types';
export default function(state = false, action) {
if (action.type === NAVIGATION) {
return action.active === TOGGLE ? !state : action.active;
}
return state;
}