Rocket.Chat.ReactNative/app/views/RoomsListView/Header/index.tsx

89 lines
2.5 KiB
TypeScript
Raw Normal View History

import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { Dispatch } from 'redux';
import { toggleServerDropdown, closeServerDropdown, setSearch } from '../../../actions/rooms';
import EventEmitter from '../../../lib/methods/helpers/events';
import { KEY_COMMAND, handleCommandOpenServerDropdown, IKeyCommandEvent } from '../../../commands';
import { isTablet } from '../../../lib/methods/helpers';
import { events, logEvent } from '../../../lib/methods/helpers/log';
import Header from './Header';
import { IApplicationState } from '../../../definitions';
interface IRoomsListHeaderViewProps {
showServerDropdown: boolean;
showSearchHeader: boolean;
serverName: string;
connecting: boolean;
connected: boolean;
isFetching: boolean;
server: string;
dispatch: Dispatch;
}
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
handleCommands = ({ event }: { event: IKeyCommandEvent }) => {
2019-11-25 20:01:17 +00:00
if (handleCommandOpenServerDropdown(event)) {
this.onPress();
}
};
2019-11-25 20:01:17 +00:00
onSearchChangeText = (text: string) => {
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, server } = this.props;
return (
<Header
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: IApplicationState) => ({
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 as string,
server: state.server.server
});
export default connect(mapStateToProps)(RoomsListHeaderView);