vn-verdnaturachat/app/views/RoomsListView/Header/index.js

90 lines
2.4 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { toggleServerDropdown, closeServerDropdown, setSearch } 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';
import { events, logEvent } from '../../../utils/log';
import Header from './Header';
class RoomsListHeaderView extends PureComponent {
static propTypes = {
showServerDropdown: PropTypes.bool,
showSearchHeader: PropTypes.bool,
serverName: PropTypes.string,
connecting: PropTypes.bool,
connected: PropTypes.bool,
isFetching: PropTypes.bool,
2019-12-04 16:39:53 +00:00
theme: PropTypes.string,
server: PropTypes.string
};
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();
}
};
2019-11-25 20:01:17 +00:00
onSearchChangeText = text => {
const { dispatch } = this.props;
dispatch(setSearch(text.trim()));
};
onPress = () => {
[NEW] Log events from RoomsList, SideDrawer and Profile (#2190) * Create method to track user event to isolate the logic to improve future refactoring * Track Onboarding view * Track NewServer view * Refactor track method due to firebase already send the current screen * Track default login and all the oAuth options * Track default sign up in RegisterView * Change trackUserEvent signature and update all the files * Track the remaining login services * track add server, change server and search * Track SidebarView and refactor to use react-navigation * Track profile events and handle exceptions * Track create channel flux * Track send message to user via NewMessageView * Track create direct message flux * Handle failure of create channel and group in the saga * Track create discussion flux * Track navigate to directory and its actions * Track read, favorite and hide a channel, handling its errors * Track all channels sorting and grouping * Resolve requests to improve the importing logs and events * Remove unused events file * Leave a bugsnag breadcrumb when logging an event * Move all logEvent to the top of code block and log remaining fail events * Move all the non-logic-dependent logEvent to the top of code block * Improve the logging of sidebar events * Improve events from onboarding and newserver * Improve events from login and register view, and log enter with apple * Improve NewMessageView events * Improve CreateChannel events * Improve CreateDiscussion and SelectedUsers create group events * Improve RoomsList events and log trivial events * Improve ProfileView events * Remove single line function body for the sidebarNavigate * Navigate to Status and AdminPanel View using the defined sidebarNavigate method Co-authored-by: Diego Mello <diegolmello@gmail.com>
2020-07-30 13:26:17 +00:00
logEvent(events.RL_TOGGLE_SERVER_DROPDOWN);
const { showServerDropdown, dispatch } = this.props;
if (showServerDropdown) {
dispatch(closeServerDropdown());
} else {
dispatch(toggleServerDropdown());
}
};
render() {
const { serverName, showServerDropdown, showSearchHeader, connecting, connected, isFetching, theme, server } = this.props;
return (
<Header
2019-12-04 16:39:53 +00:00
theme={theme}
serverName={serverName}
server={server}
showServerDropdown={showServerDropdown}
showSearchHeader={showSearchHeader}
connecting={connecting}
connected={connected}
isFetching={isFetching}
onPress={this.onPress}
2020-02-13 19:24:39 +00:00
onSearchChangeText={this.onSearchChangeText}
/>
);
}
}
const mapStateToProps = state => ({
showServerDropdown: state.rooms.showServerDropdown,
showSearchHeader: state.rooms.showSearchHeader,
connecting: state.meteor.connecting || state.server.loading,
connected: state.meteor.connected,
isFetching: state.rooms.isFetching,
serverName: state.settings.Site_Name,
server: state.server.server
});
export default connect(mapStateToProps)(withTheme(RoomsListHeaderView));