2018-12-21 10:55:35 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-08-31 16:46:33 +00:00
|
|
|
import { connect } from 'react-redux';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { Dispatch } from 'redux';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2022-01-14 22:06:55 +00:00
|
|
|
import { toggleServerDropdown, closeServerDropdown, setSearch } from '../../../actions/rooms';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../../../lib/methods/helpers/events';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { KEY_COMMAND, handleCommandOpenServerDropdown, IKeyCommandEvent } from '../../../commands';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { isTablet } from '../../../lib/methods/helpers';
|
|
|
|
import { events, logEvent } from '../../../lib/methods/helpers/log';
|
2021-09-13 20:41:05 +00:00
|
|
|
import Header from './Header';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { IApplicationState } from '../../../definitions';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
interface IRoomsListHeaderViewProps {
|
|
|
|
showServerDropdown: boolean;
|
|
|
|
showSearchHeader: boolean;
|
|
|
|
serverName: string;
|
|
|
|
connecting: boolean;
|
|
|
|
connected: boolean;
|
|
|
|
isFetching: boolean;
|
|
|
|
server: string;
|
|
|
|
dispatch: Dispatch;
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
class RoomsListHeaderView extends PureComponent<IRoomsListHeaderViewProps, any> {
|
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
|
2022-02-25 18:59:39 +00:00
|
|
|
handleCommands = ({ event }: { event: IKeyCommandEvent }) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
if (handleCommandOpenServerDropdown(event)) {
|
|
|
|
this.onPress();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
onSearchChangeText = (text: string) => {
|
2022-01-14 22:06:55 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(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);
|
2022-01-14 22:06:55 +00:00
|
|
|
const { showServerDropdown, dispatch } = this.props;
|
2018-08-31 16:46:33 +00:00
|
|
|
if (showServerDropdown) {
|
2022-01-14 22:06:55 +00:00
|
|
|
dispatch(closeServerDropdown());
|
2018-08-31 16:46:33 +00:00
|
|
|
} else {
|
2022-01-14 22:06:55 +00:00
|
|
|
dispatch(toggleServerDropdown());
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
render() {
|
2022-03-17 19:25:31 +00:00
|
|
|
const { serverName, showServerDropdown, showSearchHeader, connecting, connected, isFetching, server } = this.props;
|
2019-04-30 19:31:51 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
return (
|
|
|
|
<Header
|
|
|
|
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
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2019-08-07 13:51:34 +00:00
|
|
|
showServerDropdown: state.rooms.showServerDropdown,
|
|
|
|
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,
|
2022-02-25 18:59:39 +00:00
|
|
|
serverName: state.settings.Site_Name as string,
|
2020-07-06 20:56:28 +00:00
|
|
|
server: state.server.server
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2022-07-06 13:23:02 +00:00
|
|
|
export default connect(mapStateToProps)(RoomsListHeaderView);
|