mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Isolate SearchBar from PieceListToolbar and start implement threshold logic
This commit is contained in:
parent
1c48b8b828
commit
02eafaa80c
@ -3,14 +3,11 @@
|
|||||||
import alt from '../alt';
|
import alt from '../alt';
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
|
|
||||||
import ActionQueue from '../utils/action_queue_utils';
|
|
||||||
|
|
||||||
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
||||||
|
|
||||||
class PieceListActions extends ActionQueue {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
|
class PieceListActions {
|
||||||
|
constructor() {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
'updatePieceList',
|
'updatePieceList',
|
||||||
'updatePieceListRequestActions',
|
'updatePieceListRequestActions',
|
||||||
@ -35,7 +32,6 @@ class PieceListActions extends ActionQueue {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// afterwards, we can load the list
|
// afterwards, we can load the list
|
||||||
|
|
||||||
return Q.Promise((resolve, reject) => {
|
return Q.Promise((resolve, reject) => {
|
||||||
PieceListFetcher
|
PieceListFetcher
|
||||||
.fetch(page, pageSize, search, orderBy, orderAsc, filterBy)
|
.fetch(page, pageSize, search, orderBy, orderAsc, filterBy)
|
||||||
|
@ -4,13 +4,10 @@ import React from 'react';
|
|||||||
|
|
||||||
import PieceListToolbarFilterWidget from './piece_list_toolbar_filter_widget';
|
import PieceListToolbarFilterWidget from './piece_list_toolbar_filter_widget';
|
||||||
import PieceListToolbarOrderWidget from './piece_list_toolbar_order_widget';
|
import PieceListToolbarOrderWidget from './piece_list_toolbar_order_widget';
|
||||||
|
import SearchBar from '../search_bar';
|
||||||
|
|
||||||
import Input from 'react-bootstrap/lib/Input';
|
|
||||||
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
|
|
||||||
import { getLangText } from '../../utils/lang_utils';
|
|
||||||
|
|
||||||
let PieceListToolbar = React.createClass({
|
let PieceListToolbar = React.createClass({
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
className: React.PropTypes.string,
|
className: React.PropTypes.string,
|
||||||
searchFor: React.PropTypes.func,
|
searchFor: React.PropTypes.func,
|
||||||
@ -39,11 +36,6 @@ let PieceListToolbar = React.createClass({
|
|||||||
])
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
searchFor() {
|
|
||||||
let searchTerm = this.refs.search.getInputDOMNode().value;
|
|
||||||
this.props.searchFor(searchTerm);
|
|
||||||
},
|
|
||||||
|
|
||||||
getFilterWidget(){
|
getFilterWidget(){
|
||||||
if (this.props.filterParams){
|
if (this.props.filterParams){
|
||||||
return (
|
return (
|
||||||
@ -55,6 +47,7 @@ let PieceListToolbar = React.createClass({
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getOrderWidget(){
|
getOrderWidget(){
|
||||||
if (this.props.orderParams){
|
if (this.props.orderParams){
|
||||||
return (
|
return (
|
||||||
@ -68,24 +61,20 @@ let PieceListToolbar = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let searchIcon = <Glyphicon glyph='search' className="filter-glyph"/>;
|
const { className, children, searchFor } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={this.props.className}>
|
<div className={className}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-xs-12 col-sm-10 col-md-8 col-lg-8 col-sm-offset-1 col-md-offset-2 col-lg-offset-2">
|
<div className="col-xs-12 col-sm-10 col-md-8 col-lg-8 col-sm-offset-1 col-md-offset-2 col-lg-offset-2">
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<span className="pull-left">
|
<span className="pull-left">
|
||||||
{this.props.children}
|
{children}
|
||||||
</span>
|
|
||||||
<span className="pull-right search-bar ascribe-input-glyph">
|
|
||||||
<Input
|
|
||||||
type='text'
|
|
||||||
ref="search"
|
|
||||||
placeholder={getLangText('Search%s', '...')}
|
|
||||||
onChange={this.searchFor}
|
|
||||||
addonAfter={searchIcon} />
|
|
||||||
</span>
|
</span>
|
||||||
|
<SearchBar
|
||||||
|
className="pull-right search-bar ascribe-input-glyph"
|
||||||
|
searchFor={searchFor}
|
||||||
|
threshold={1000}/>
|
||||||
<span className="pull-right">
|
<span className="pull-right">
|
||||||
{this.getOrderWidget()}
|
{this.getOrderWidget()}
|
||||||
{this.getFilterWidget()}
|
{this.getFilterWidget()}
|
||||||
|
68
js/components/search_bar.js
Normal file
68
js/components/search_bar.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import React from 'react/addons';
|
||||||
|
|
||||||
|
import Input from 'react-bootstrap/lib/Input';
|
||||||
|
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
|
||||||
|
import { getLangText } from '../utils/lang_utils';
|
||||||
|
|
||||||
|
|
||||||
|
const { func, string, number } = React.PropTypes;
|
||||||
|
const { update } = React.addons;
|
||||||
|
|
||||||
|
const SearchBar = React.createClass({
|
||||||
|
propTypes: {
|
||||||
|
searchFor: func.isRequired,
|
||||||
|
className: string,
|
||||||
|
|
||||||
|
// in milliseconds
|
||||||
|
threshold: number.isRequired
|
||||||
|
},
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
timers: [],
|
||||||
|
currentSearchQuery: ''
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
startTimers(searchQuery) {
|
||||||
|
const { timers } = this.state;
|
||||||
|
const { threshold } = this.props;
|
||||||
|
const timer = {
|
||||||
|
searchQuery,
|
||||||
|
cb: setTimeout(this.evaluateTimer, threshold)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const newTimers = update(timers, {$push: [timer]});
|
||||||
|
this.setState({ timers: newTimers });
|
||||||
|
},
|
||||||
|
|
||||||
|
evaluateTimer() {
|
||||||
|
console.log(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleChange({ target: { value }}) {
|
||||||
|
this.startTimers(value);
|
||||||
|
this.setState({ currentSearchQuery: value });
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const searchIcon = <Glyphicon glyph='search' className="filter-glyph"/>;
|
||||||
|
const { className } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={className}>
|
||||||
|
<Input
|
||||||
|
type='text'
|
||||||
|
placeholder={getLangText('Search%s', '...')}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
addonAfter={searchIcon} />
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export default SearchBar;
|
@ -1,18 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
|
|
||||||
class ActionQueue {
|
|
||||||
constructor() {
|
|
||||||
let actionClass = this.constructor.prototype;
|
|
||||||
let actionClassPropertyNames = Object.getOwnPropertyNames(actionClass);
|
|
||||||
|
|
||||||
this.constructor = actionClass.constructor;
|
|
||||||
|
|
||||||
for(let i = 1; i < actionClassPropertyNames.length; i++) {
|
|
||||||
let methodName = actionClassPropertyNames[i];
|
|
||||||
actionClass[methodName] = () => console.log('hello');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ActionQueue;
|
|
Loading…
Reference in New Issue
Block a user