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';
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
import {
|
2021-09-13 20:41:05 +00:00
|
|
|
closeServerDropdown,
|
|
|
|
closeSortDropdown,
|
|
|
|
setSearch as setSearchAction,
|
|
|
|
toggleServerDropdown
|
2018-10-23 21:39:48 +00:00
|
|
|
} from '../../../actions/rooms';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../../theme';
|
2019-11-25 20:01:17 +00:00
|
|
|
import EventEmitter from '../../../utils/events';
|
|
|
|
import { KEY_COMMAND, handleCommandOpenServerDropdown } from '../../../commands';
|
|
|
|
import { isTablet } from '../../../utils/deviceInfo';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../../../utils/log';
|
|
|
|
import Header from './Header';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
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-04-30 19:31:51 +00:00
|
|
|
connecting: PropTypes.bool,
|
2020-07-06 20:56:28 +00:00
|
|
|
connected: PropTypes.bool,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2020-07-06 20:56:28 +00:00
|
|
|
server: PropTypes.string,
|
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-03-12 16:23:06 +00:00
|
|
|
setSearch: PropTypes.func
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
componentDidMount() {
|
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:24:39 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommands = ({ event }) => {
|
|
|
|
if (handleCommandOpenServerDropdown(event)) {
|
|
|
|
this.onPress();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onSearchChangeText = text => {
|
2018-10-23 21:39:48 +00:00
|
|
|
const { setSearch } = this.props;
|
|
|
|
setSearch(text.trim());
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
onPress = () => {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.RL_TOGGLE_SERVER_DROPDOWN);
|
2021-09-13 20:41:05 +00:00
|
|
|
const { showServerDropdown, showSortDropdown, close, open, closeSort } = this.props;
|
2018-08-31 16:46:33 +00:00
|
|
|
if (showServerDropdown) {
|
|
|
|
close();
|
|
|
|
} else if (showSortDropdown) {
|
|
|
|
closeSort();
|
|
|
|
setTimeout(() => {
|
|
|
|
open();
|
|
|
|
}, 300);
|
|
|
|
} else {
|
|
|
|
open();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
render() {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { serverName, showServerDropdown, showSearchHeader, connecting, connected, isFetching, theme, server } = this.props;
|
2019-04-30 19:31:51 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
return (
|
|
|
|
<Header
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-08-31 16:46:33 +00:00
|
|
|
serverName={serverName}
|
2020-07-06 20:56:28 +00:00
|
|
|
server={server}
|
2018-08-31 16:46:33 +00:00
|
|
|
showServerDropdown={showServerDropdown}
|
2018-10-23 21:39:48 +00:00
|
|
|
showSearchHeader={showSearchHeader}
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting={connecting}
|
2020-07-06 20:56:28 +00:00
|
|
|
connected={connected}
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching={isFetching}
|
|
|
|
onPress={this.onPress}
|
2020-02-13 19:24:39 +00:00
|
|
|
onSearchChangeText={this.onSearchChangeText}
|
2018-08-31 16:46:33 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
showServerDropdown: state.rooms.showServerDropdown,
|
|
|
|
showSortDropdown: state.rooms.showSortDropdown,
|
|
|
|
showSearchHeader: state.rooms.showSearchHeader,
|
|
|
|
connecting: state.meteor.connecting || state.server.loading,
|
2020-07-06 20:56:28 +00:00
|
|
|
connected: state.meteor.connected,
|
2019-08-07 13:51:34 +00:00
|
|
|
isFetching: state.rooms.isFetching,
|
2020-07-06 20:56:28 +00:00
|
|
|
serverName: state.settings.Site_Name,
|
|
|
|
server: state.server.server
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchtoProps = dispatch => ({
|
|
|
|
close: () => dispatch(closeServerDropdown()),
|
|
|
|
open: () => dispatch(toggleServerDropdown()),
|
|
|
|
closeSort: () => dispatch(closeSortDropdown()),
|
|
|
|
setSearch: searchText => dispatch(setSearchAction(searchText))
|
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchtoProps)(withTheme(RoomsListHeaderView));
|