fix search.ux: While searching, show the search term in place of breadcrumb (resolve #8)

fix search: Navigating to search result's folders should exit search mode
This commit is contained in:
Mahdi Dibaiee
2015-09-26 20:53:34 +03:30
parent 92b5fa2fee
commit cb30112c40
4 changed files with 101 additions and 66 deletions

View File

@ -3,45 +3,55 @@ import { connect } from 'react-redux';
import changedir from 'actions/changedir';
import { bind } from 'store';
// TODO: Fix history not working when clicking on sdcard
@connect(props)
export default class Breadcrumb extends Component {
render() {
let directories = this.props.cwd.split('/').filter(a => a);
directories.unshift('sdcard');
let els = [];
let els = directories.map((dir, index, arr) => {
let path = arr.slice(1, index + 1).join('/');
if (this.props.search) {
console.log('search');
els = [
<span key='000'>Search: {this.props.search}</span>
]
} else {
els.unshift(<span onClick={this.goUp} className='icon-up' key='000'></span>);
return (
<span key={index} onClick={bind(changedir(path))}>
<i>/</i>{dir}
</span>
);
});
let lastDirectories = this.props.lwd.split('/').filter(a => a);
if (lastDirectories.length > directories.length - 1) {
lastDirectories.splice(0, directories.length - 1);
let directories = this.props.cwd.split('/').filter(a => a);
directories.unshift('sdcard');
let history = lastDirectories.map((dir, index, arr) => {
let current = directories.slice(1).concat(arr.slice(0, index + 1));
let path = current.join('/').replace(/^\//, ''); // remove starting slash
els = els.concat(directories.map((dir, index, arr) => {
let path = arr.slice(1, index + 1).join('/');
return (
<span key={directories.length + index} className='history' onClick={bind(changedir(path))}>
<span key={index} onClick={bind(changedir(path))}>
<i>/</i>{dir}
</span>
)
});
);
}));
els = els.concat(history);
let lastDirectories = this.props.lwd.split('/').filter(a => a);
if (lastDirectories.length > directories.length - 1) {
lastDirectories.splice(0, directories.length - 1);
let history = lastDirectories.map((dir, index, arr) => {
let current = directories.slice(1).concat(arr.slice(0, index + 1));
let path = current.join('/').replace(/^\//, ''); // remove starting slash
return (
<span key={directories.length + index} className='history' onClick={bind(changedir(path))}>
<i>/</i>{dir}
</span>
)
});
els = els.concat(history);
}
}
return (
<div className='breadcrumb'>
<div>
<span onClick={this.goUp} className='icon-up'></span>
{els}
</div>
</div>
@ -61,6 +71,7 @@ export default class Breadcrumb extends Component {
function props(state) {
return {
lwd: state.get('lwd'), // last working directory
cwd: state.get('cwd')
cwd: state.get('cwd'),
search: state.get('search')
}
}

View File

@ -1,4 +1,4 @@
import { SEARCH } from 'actions/types';
import { SEARCH, CHANGE_DIRECTORY, REFRESH } from 'actions/types';
import store from 'store';
import { reportError } from 'utils';
import { listFiles } from 'actions/files-view';
@ -12,6 +12,10 @@ export default function(state = '', action) {
return action.keywords;
}
if (action.type === CHANGE_DIRECTORY || action.type === REFRESH) {
return '';
}
return state;
}
@ -28,7 +32,7 @@ function search(keywords) {
// We don't want to show all the currently visible files from the
// first iteration
let once = true;
children('/', true).then(function showResults(files) {
children('', true).then(function showResults(files) {
if (!store.getState().get('search')) return;
let current = once ? [] : store.getState().get('files');