2018-12-21 10:55:35 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-08-31 16:46:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
2019-02-07 16:13:21 +00:00
|
|
|
import { responsive } from 'react-native-responsive-ui';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
import {
|
|
|
|
toggleServerDropdown, closeServerDropdown, closeSortDropdown, setSearch as setSearchAction
|
|
|
|
} from '../../../actions/rooms';
|
2018-08-31 16:46:33 +00:00
|
|
|
import Header from './Header';
|
|
|
|
|
2019-02-07 16:13:21 +00:00
|
|
|
@responsive
|
2018-08-31 16:46:33 +00:00
|
|
|
@connect(state => ({
|
|
|
|
showServerDropdown: state.rooms.showServerDropdown,
|
|
|
|
showSortDropdown: state.rooms.showSortDropdown,
|
2018-10-23 21:39:48 +00:00
|
|
|
showSearchHeader: state.rooms.showSearchHeader,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: state.rooms.isFetching,
|
2018-08-31 16:46:33 +00:00
|
|
|
serverName: state.settings.Site_Name
|
|
|
|
}), dispatch => ({
|
|
|
|
close: () => dispatch(closeServerDropdown()),
|
|
|
|
open: () => dispatch(toggleServerDropdown()),
|
2018-10-23 21:39:48 +00:00
|
|
|
closeSort: () => dispatch(closeSortDropdown()),
|
|
|
|
setSearch: searchText => dispatch(setSearchAction(searchText))
|
2018-08-31 16:46:33 +00:00
|
|
|
}))
|
2018-12-21 10:55:35 +00:00
|
|
|
export default class RoomsListHeaderView extends PureComponent {
|
2018-08-31 16:46:33 +00:00
|
|
|
static propTypes = {
|
|
|
|
showServerDropdown: PropTypes.bool,
|
|
|
|
showSortDropdown: PropTypes.bool,
|
2018-10-23 21:39:48 +00:00
|
|
|
showSearchHeader: PropTypes.bool,
|
2018-08-31 16:46:33 +00:00
|
|
|
serverName: PropTypes.string,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool,
|
2018-08-31 16:46:33 +00:00
|
|
|
open: PropTypes.func,
|
|
|
|
close: PropTypes.func,
|
2018-10-23 21:39:48 +00:00
|
|
|
closeSort: PropTypes.func,
|
2019-02-07 16:13:21 +00:00
|
|
|
setSearch: PropTypes.func,
|
|
|
|
window: PropTypes.object
|
2018-10-23 21:39:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { showSearchHeader } = this.props;
|
|
|
|
if (showSearchHeader && prevProps.showSearchHeader !== showSearchHeader) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.searchInputRef.focus();
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSearchChangeText = (text) => {
|
|
|
|
const { setSearch } = this.props;
|
|
|
|
setSearch(text.trim());
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onPress = () => {
|
|
|
|
const {
|
|
|
|
showServerDropdown, showSortDropdown, close, open, closeSort
|
|
|
|
} = this.props;
|
|
|
|
if (showServerDropdown) {
|
|
|
|
close();
|
|
|
|
} else if (showSortDropdown) {
|
|
|
|
closeSort();
|
|
|
|
setTimeout(() => {
|
|
|
|
open();
|
|
|
|
}, 300);
|
|
|
|
} else {
|
|
|
|
open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
setSearchInputRef = (ref) => {
|
|
|
|
this.searchInputRef = ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
render() {
|
2019-02-07 16:13:21 +00:00
|
|
|
const {
|
|
|
|
serverName, showServerDropdown, showSearchHeader, isFetching, window: { width }
|
|
|
|
} = this.props;
|
2018-08-31 16:46:33 +00:00
|
|
|
return (
|
|
|
|
<Header
|
|
|
|
serverName={serverName}
|
|
|
|
showServerDropdown={showServerDropdown}
|
2018-10-23 21:39:48 +00:00
|
|
|
showSearchHeader={showSearchHeader}
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching={isFetching}
|
|
|
|
width={width}
|
2018-10-23 21:39:48 +00:00
|
|
|
setSearchInputRef={this.setSearchInputRef}
|
2019-02-07 16:13:21 +00:00
|
|
|
onPress={this.onPress}
|
2018-10-23 21:39:48 +00:00
|
|
|
onSearchChangeText={text => this.onSearchChangeText(text)}
|
2018-08-31 16:46:33 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|