mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
add 'clear search' dialog to AccordionList and implement functionality in SearchBar
This commit is contained in:
parent
f57125184d
commit
ea40181805
@ -9,21 +9,49 @@ let AccordionList = React.createClass({
|
|||||||
className: React.PropTypes.string,
|
className: React.PropTypes.string,
|
||||||
children: React.PropTypes.arrayOf(React.PropTypes.element).isRequired,
|
children: React.PropTypes.arrayOf(React.PropTypes.element).isRequired,
|
||||||
loadingElement: React.PropTypes.element,
|
loadingElement: React.PropTypes.element,
|
||||||
count: React.PropTypes.number
|
count: React.PropTypes.number,
|
||||||
|
itemList: React.PropTypes.arrayOf(React.PropTypes.object),
|
||||||
|
search: React.PropTypes.string,
|
||||||
|
searchFor: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearSearch() {
|
||||||
|
this.props.searchFor('');
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { search } = this.props;
|
||||||
|
|
||||||
if(this.props.itemList && this.props.itemList.length > 0) {
|
if(this.props.itemList && this.props.itemList.length > 0) {
|
||||||
return (
|
return (
|
||||||
<div className={this.props.className}>
|
<div className={this.props.className}>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if(this.props.count === 0) {
|
} else if(this.props.count === 0 && !search) {
|
||||||
return (
|
return (
|
||||||
<div className="ascribe-accordion-list-placeholder">
|
<div className="ascribe-accordion-list-placeholder">
|
||||||
<p className="text-center">{getLangText('We could not find any works related to you...')}</p>
|
<p className="text-center">
|
||||||
<p className="text-center">{getLangText('To register one, click')} <a href="register_piece">{getLangText('here')}</a>!</p>
|
{getLangText('We could not find any works related to you...')}
|
||||||
|
</p>
|
||||||
|
<p className="text-center">
|
||||||
|
{getLangText('To register one, click')}
|
||||||
|
<a href="register_piece">{getLangText('here')}</a>!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if(this.props.count === 0 && search) {
|
||||||
|
return (
|
||||||
|
<div className="ascribe-accordion-list-placeholder">
|
||||||
|
<p className="text-center">
|
||||||
|
{getLangText('We could not find any works related to you...')}
|
||||||
|
</p>
|
||||||
|
<p className="text-center">
|
||||||
|
{getLangText('You\'re filtering by the search keyword: \'%s\' ', search)}
|
||||||
|
</p>
|
||||||
|
<p className="text-center">
|
||||||
|
<button className="btn btn-sm btn-default" onClick={this.clearSearch}>{getLangText('Clear search')}</button>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,6 +178,7 @@ let PieceList = React.createClass({
|
|||||||
orderBy={this.state.orderBy}
|
orderBy={this.state.orderBy}
|
||||||
orderAsc={this.state.orderAsc}
|
orderAsc={this.state.orderAsc}
|
||||||
search={this.state.search}
|
search={this.state.search}
|
||||||
|
searchFor={this.searchFor}
|
||||||
page={this.state.page}
|
page={this.state.page}
|
||||||
pageSize={this.state.pageSize}
|
pageSize={this.state.pageSize}
|
||||||
loadingElement={loadingElement}>
|
loadingElement={loadingElement}>
|
||||||
|
@ -68,6 +68,19 @@ const SearchBar = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
/**
|
||||||
|
* This enables the `PieceListStore` to override the state
|
||||||
|
* of that component in case someone is changing the `searchQuery` on
|
||||||
|
* another component.
|
||||||
|
*
|
||||||
|
* Like how it's being done in the 'Clear search' dialog.
|
||||||
|
*/
|
||||||
|
if(this.props.searchQuery !== nextProps.searchQuery) {
|
||||||
|
this.setState({ searchQuery: nextProps.searchQuery });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
startTimer(searchQuery) {
|
startTimer(searchQuery) {
|
||||||
const { timer } = this.state;
|
const { timer } = this.state;
|
||||||
const { threshold } = this.props;
|
const { threshold } = this.props;
|
||||||
@ -114,6 +127,7 @@ const SearchBar = React.createClass({
|
|||||||
<span className={className}>
|
<span className={className}>
|
||||||
<Input
|
<Input
|
||||||
type='text'
|
type='text'
|
||||||
|
value={this.state.searchQuery}
|
||||||
placeholder={getLangText('Search%s', '...')}
|
placeholder={getLangText('Search%s', '...')}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
addonAfter={searchIcon} />
|
addonAfter={searchIcon} />
|
||||||
|
Loading…
Reference in New Issue
Block a user