fix compatibility: fix getting an empty error due to corrupted path properties

fix compatibility: switch navigation drawer to `display: block` if there is no flexbox support
This commit is contained in:
Mahdi Dibaiee
2015-09-14 02:18:19 +04:30
parent 8a3c5de65d
commit ceb8cd3b21
7 changed files with 82 additions and 38 deletions

View File

@ -17,7 +17,7 @@ let ROOT_CACHE;
export async function root() {
if (ROOT_CACHE) return ROOT_CACHE;
ROOT_CACHE = await sdcard().getRoot();
ROOT_CACHE = shimDirectory(await sdcard().getRoot());
window.root = ROOT_CACHE;
return ROOT_CACHE;
}
@ -32,6 +32,9 @@ export async function getFile(dir = '/') {
export async function children(dir, gatherInfo) {
let parent = shimDirectory(await getFile(dir));
if (!parent.path) {
parent.path = dir.slice(0, dir.lastIndexOf('/') + 1);
}
let childs = await parent.getFilesAndDirectories();
if (gatherInfo) {
@ -39,7 +42,7 @@ export async function children(dir, gatherInfo) {
if (type(child) === 'Directory') {
let subchildren;
try {
subchildren = await child.getFilesAndDirectories();
subchildren = await shimDirectory(child).getFilesAndDirectories();
} catch(e) {
subchildren = [];
}
@ -80,7 +83,9 @@ export async function createFile(...args) {
export async function createDirectory(...args) {
let parent = await root();
return parent.createDirectory(...args);
return parent.createDirectory(...args).then(() => {
return createFile(args[0] + '/.empty');
});
}
export async function remove(file, deep) {
@ -108,11 +113,13 @@ export async function copy(file, newPath) {
if (type(target) === 'Directory') {
await parent.createDirectory(newPath);
let childs = await target.getFilesAndDirectories();
let childs = await shimDirectory(target).getFilesAndDirectories();
for (let child of childs) {
if (type(child) === 'File') {
child.path = oldPath + '/';
Object.defineProperty(child, 'path', {
value: oldPath + '/'
});
}
await copy(child, newPath + '/' + child.name);

View File

@ -39,6 +39,6 @@ export default class Directory extends Component {
peek() {
let file = store.getState().get('files')[this.props.index];
store.dispatch(changedir(file.path.slice(1) + file.name));
store.dispatch(changedir(file.path.replace(/^\//, '') + file.name));
}
}

View File

@ -10,8 +10,14 @@ export default class Navigation extends Component {
render() {
let { settings } = this.props;
let noFlex = typeof getComputedStyle(document.body)['flex-flow'] === 'undefined';
let style = noFlex ? {display: 'block'} : {};
return (
<nav className={this.props.active ? 'active' : ''} onChange={this.onChange.bind(this)}>
<nav className={this.props.active ? 'active' : ''}
onChange={this.onChange.bind(this)}
style={style}>
<i onTouchStart={this.hide} />
<p>Filter</p>

View File

@ -16,7 +16,8 @@ export default {
let input = React.findDOMNode(this.refs.input);
let cwd = store.getState().get('cwd');
let action = create(cwd + '/' + input.value);
let path = cwd + '/' + input.value;
let action = create(path.replace(/^\//, ''));
this.props.dispatch(action);
this.props.dispatch(hideAll());
this.props.dispatch(active());
@ -28,7 +29,8 @@ export default {
let input = React.findDOMNode(this.refs.input);
let cwd = store.getState().get('cwd');
let action = create(cwd + '/' + input.value, true);
let path = cwd + '/' + input.value;
let action = create(path.replace(/^\//, ''), true);
this.props.dispatch(action);
this.props.dispatch(hideAll());
this.props.dispatch(active());