Fix directories with nested files not showing

Fix cwd showing "/sdcard/sdcard" directories
This commit is contained in:
Mahdi Dibaiee 2015-09-15 17:57:43 +04:30
parent 6e52ca6246
commit d52fe9f9bc
6 changed files with 14 additions and 16 deletions

View File

@ -31995,6 +31995,7 @@ exports['default'] = function (state, action) {
};
function changeTo(dir) {
dir = (0, _utils.normalize)(dir);
(0, _apiFiles.children)(dir, true).then(function (files) {
_store2['default'].dispatch((0, _actionsFilesView.listFiles)(files));
}, _utils.reportError);

View File

@ -41,24 +41,22 @@ function shimDirectory(directory) {
return;
}
var parts = this.result.name.replace('/sdcard/', '').split('/');
var normalized = this.result.name.replace('/sdcard/', '');
var parts = normalized.split('/');
// immediate children files
if (parts.slice(0, -1).join('/') === current) {
console.log('constructing file');
var file = new File([this.result], parts[parts.length - 1], {
type: this.result.type
});
console.log('defining path');
Object.defineProperty(file, 'path', {
value: parts.slice(0, -1).join('/') + '/'
});
children.push(file);
// Directories
} else if (parts.slice(0, -2).join('/') === current) {
var path = parts.slice(0, -2).join('/') + '/';
var name = parts[parts.length - 2];
} else if (normalized.indexOf(current) === 0) {
var name = normalized.slice(current.length).replace(/^\//, '').split('/')[0];
var exists = children.some(function(child) {
return child.name === name
@ -67,7 +65,7 @@ function shimDirectory(directory) {
if (!exists) {
var dir = Object.assign({}, directory);
dir.name = name;
dir.path = path;
dir.path = current + '/';
children.push(dir);
}
}

Binary file not shown.

View File

@ -5,5 +5,5 @@ export default function changedir(dir) {
return {
type: CHANGE_DIRECTORY,
dir
};
}
}

View File

@ -1,7 +1,7 @@
import { CHANGE_DIRECTORY, REFRESH, SETTINGS } from 'actions/types';
import { children, CACHE } from 'api/files';
import store from 'store';
import { reportError } from 'utils';
import { reportError, normalize } from 'utils';
import { listFiles } from 'actions/files-view';
export default function(state = '', action) {
@ -25,6 +25,7 @@ export default function(state = '', action) {
}
function changeTo(dir) {
dir = normalize(dir);
children(dir, true).then(files => {
store.dispatch(listFiles(files));
}, reportError)

View File

@ -41,24 +41,22 @@ function shimDirectory(directory) {
return;
}
var parts = this.result.name.replace('/sdcard/', '').split('/');
var normalized = this.result.name.replace('/sdcard/', '');
var parts = normalized.split('/');
// immediate children files
if (parts.slice(0, -1).join('/') === current) {
console.log('constructing file');
var file = new File([this.result], parts[parts.length - 1], {
type: this.result.type
});
console.log('defining path');
Object.defineProperty(file, 'path', {
value: parts.slice(0, -1).join('/') + '/'
});
children.push(file);
// Directories
} else if (parts.slice(0, -2).join('/') === current) {
var path = parts.slice(0, -2).join('/') + '/';
var name = parts[parts.length - 2];
} else if (normalized.indexOf(current) === 0) {
var name = normalized.slice(current.length).replace(/^\//, '').split('/')[0];
var exists = children.some(function(child) {
return child.name === name
@ -67,7 +65,7 @@ function shimDirectory(directory) {
if (!exists) {
var dir = Object.assign({}, directory);
dir.name = name;
dir.path = path;
dir.path = current + '/';
children.push(dir);
}
}