mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 22:14:58 +08:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
2847a5355c
@ -242,6 +242,9 @@ class SendAccountData extends GenericEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INITIAL_LOAD_TILES = 20;
|
||||||
|
const LOAD_TILES_STEP_SIZE = 50;
|
||||||
|
|
||||||
class FilteredList extends React.Component {
|
class FilteredList extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
@ -249,31 +252,65 @@ class FilteredList extends React.Component {
|
|||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static filterChildren(children, query) {
|
||||||
|
if (!query) return children;
|
||||||
|
const lcQuery = query.toLowerCase();
|
||||||
|
return children.filter((child) => child.key.toLowerCase().includes(lcQuery));
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
this.onQuery = this.onQuery.bind(this);
|
|
||||||
|
this.state = {
|
||||||
|
filteredChildren: FilteredList.filterChildren(this.props.children, this.props.query),
|
||||||
|
truncateAt: INITIAL_LOAD_TILES,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
onQuery(ev) {
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (this.props.children === nextProps.children && this.props.query === nextProps.query) return;
|
||||||
|
this.setState({
|
||||||
|
filteredChildren: FilteredList.filterChildren(nextProps.children, nextProps.query),
|
||||||
|
truncateAt: INITIAL_LOAD_TILES,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showAll = () => {
|
||||||
|
this.setState({
|
||||||
|
truncateAt: this.state.truncateAt + LOAD_TILES_STEP_SIZE,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
createOverflowElement = (overflowCount: number, totalCount: number) => {
|
||||||
|
return <button className="mx_DevTools_RoomStateExplorer_button" onClick={this.showAll}>
|
||||||
|
{ _t("and %(count)s others...", { count: overflowCount }) }
|
||||||
|
</button>;
|
||||||
|
};
|
||||||
|
|
||||||
|
onQuery = (ev) => {
|
||||||
if (this.props.onChange) this.props.onChange(ev.target.value);
|
if (this.props.onChange) this.props.onChange(ev.target.value);
|
||||||
}
|
};
|
||||||
|
|
||||||
filterChildren() {
|
getChildren = (start: number, end: number) => {
|
||||||
if (this.props.query) {
|
return this.state.filteredChildren.slice(start, end);
|
||||||
const lowerQuery = this.props.query.toLowerCase();
|
};
|
||||||
return this.props.children.filter((child) => child.key.toLowerCase().includes(lowerQuery));
|
|
||||||
}
|
getChildCount = (): number => {
|
||||||
return this.props.children;
|
return this.state.filteredChildren.length;
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const TruncatedList = sdk.getComponent("elements.TruncatedList");
|
||||||
return <div>
|
return <div>
|
||||||
<input size="64"
|
<input size="64"
|
||||||
onChange={this.onQuery}
|
onChange={this.onQuery}
|
||||||
value={this.props.query}
|
value={this.props.query}
|
||||||
placeholder={_t('Filter results')}
|
placeholder={_t('Filter results')}
|
||||||
className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" />
|
className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" />
|
||||||
{ this.filterChildren() }
|
<TruncatedList getChildren={this.getChildren}
|
||||||
|
getChildCount={this.getChildCount}
|
||||||
|
truncateAt={this.state.truncateAt}
|
||||||
|
createOverflowElement={this.createOverflowElement} />
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user