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) { function changeTo(dir) {
dir = (0, _utils.normalize)(dir);
(0, _apiFiles.children)(dir, true).then(function (files) { (0, _apiFiles.children)(dir, true).then(function (files) {
_store2['default'].dispatch((0, _actionsFilesView.listFiles)(files)); _store2['default'].dispatch((0, _actionsFilesView.listFiles)(files));
}, _utils.reportError); }, _utils.reportError);

View File

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

Binary file not shown.

View File

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

View File

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

View File

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