kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
UserIndex: style search input, rework debounced search
rodzic
30b39d739f
commit
022c9f06b3
|
@ -4,13 +4,20 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import { fetchUsers } from 'soapbox/actions/admin';
|
import { fetchUsers } from 'soapbox/actions/admin';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { injectIntl, defineMessages } from 'react-intl';
|
||||||
import AccountContainer from 'soapbox/containers/account_container';
|
import AccountContainer from 'soapbox/containers/account_container';
|
||||||
import Column from 'soapbox/features/ui/components/column';
|
import Column from 'soapbox/features/ui/components/column';
|
||||||
import ScrollableList from 'soapbox/components/scrollable_list';
|
import ScrollableList from 'soapbox/components/scrollable_list';
|
||||||
|
import { SimpleForm, TextInput } from 'soapbox/features/forms';
|
||||||
import { Set as ImmutableSet, OrderedSet as ImmutableOrderedSet, is } from 'immutable';
|
import { Set as ImmutableSet, OrderedSet as ImmutableOrderedSet, is } from 'immutable';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
empty: { id: 'admin.user_index.empty', defaultMessage: 'No users found.' },
|
||||||
|
searchPlaceholder: { id: 'admin.user_index.search_input_placeholder', defaultMessage: 'Who are you looking for?' },
|
||||||
|
});
|
||||||
|
|
||||||
export default @connect()
|
export default @connect()
|
||||||
|
@injectIntl
|
||||||
class UserIndex extends ImmutablePureComponent {
|
class UserIndex extends ImmutablePureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -63,19 +70,13 @@ class UserIndex extends ImmutablePureComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDebounced = debounce(() => {
|
|
||||||
this.refresh();
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
const { filters, query } = this.state;
|
const { filters, query } = this.state;
|
||||||
const filtersChanged = !is(filters, prevState.filters);
|
const filtersChanged = !is(filters, prevState.filters);
|
||||||
const queryChanged = query !== prevState.query;
|
const queryChanged = query !== prevState.query;
|
||||||
|
|
||||||
if (filtersChanged) {
|
if (filtersChanged || queryChanged) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
} else if (queryChanged) {
|
|
||||||
this.refreshDebounced();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +84,16 @@ class UserIndex extends ImmutablePureComponent {
|
||||||
this.fetchNextPage();
|
this.fetchNextPage();
|
||||||
}, 2000, { leading: true });
|
}, 2000, { leading: true });
|
||||||
|
|
||||||
|
updateQuery = debounce(query => {
|
||||||
|
this.setState({ query });
|
||||||
|
}, 900)
|
||||||
|
|
||||||
handleQueryChange = e => {
|
handleQueryChange = e => {
|
||||||
this.setState({ query: e.target.value });
|
this.updateQuery(e.target.value);
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { intl } = this.props;
|
||||||
const { accountIds, isLoading } = this.state;
|
const { accountIds, isLoading } = this.state;
|
||||||
const hasMore = accountIds.count() < this.state.total;
|
const hasMore = accountIds.count() < this.state.total;
|
||||||
|
|
||||||
|
@ -95,14 +101,20 @@ class UserIndex extends ImmutablePureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column>
|
<Column>
|
||||||
<input value={this.state.q} onChange={this.handleQueryChange} />
|
<SimpleForm style={{ paddingBottom: 0 }}>
|
||||||
|
<TextInput
|
||||||
|
value={this.state.q}
|
||||||
|
onChange={this.handleQueryChange}
|
||||||
|
placeholder={intl.formatMessage(messages.searchPlaceholder)}
|
||||||
|
/>
|
||||||
|
</SimpleForm>
|
||||||
<ScrollableList
|
<ScrollableList
|
||||||
scrollKey='user-index'
|
scrollKey='user-index'
|
||||||
hasMore={hasMore}
|
hasMore={hasMore}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
showLoading={showLoading}
|
showLoading={showLoading}
|
||||||
onLoadMore={this.handleLoadMore}
|
onLoadMore={this.handleLoadMore}
|
||||||
emptyMessage={<FormattedMessage id='admin.user_index.empty' defaultMessage='No users found.' />}
|
emptyMessage={intl.formatMessage(messages.empty)}
|
||||||
>
|
>
|
||||||
{accountIds.map(id =>
|
{accountIds.map(id =>
|
||||||
<AccountContainer key={id} id={id} withNote={false} />,
|
<AccountContainer key={id} id={id} withNote={false} />,
|
||||||
|
|
Ładowanie…
Reference in New Issue