Chore: Migrate DirectoryView to Typescript (#3379)

* [improve] - migrate the view: DirectoryView to typescript

* [improve] - migrate the view: removing unnecessary variables

* minor changes

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Alex Junior 2021-09-15 17:37:21 -03:00 committed by GitHub
parent 308be2d2f4
commit 5bc74c6c68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 43 deletions

View File

@ -25,14 +25,14 @@ interface IDirectoryItem {
rightLabel: string; rightLabel: string;
rid: string; rid: string;
theme: string; theme: string;
teamMain: boolean; teamMain?: boolean;
} }
const DirectoryItemLabel = React.memo(({ text, theme }: IDirectoryItemLabel) => { const DirectoryItemLabel = React.memo(({ text, theme }: IDirectoryItemLabel) => {
if (!text) { if (!text) {
return null; return null;
} }
return <Text style={[styles.directoryItemLabel, { color: themes[theme].auxiliaryText }]}>{text}</Text>; return <Text style={[styles.directoryItemLabel, { color: themes[theme!].auxiliaryText }]}>{text}</Text>;
}); });
const DirectoryItem = ({ const DirectoryItem = ({
@ -47,7 +47,7 @@ const DirectoryItem = ({
rid, rid,
theme, theme,
teamMain teamMain
}: IDirectoryItem) => ( }: IDirectoryItem): JSX.Element => (
<Touch onPress={onPress} style={{ backgroundColor: themes[theme].backgroundColor }} testID={testID} theme={theme}> <Touch onPress={onPress} style={{ backgroundColor: themes[theme].backgroundColor }} testID={testID} theme={theme}>
<View style={[styles.directoryItemContainer, styles.directoryItemButton, style]}> <View style={[styles.directoryItemContainer, styles.directoryItemButton, style]}>
<Avatar text={avatar} size={30} type={type} rid={rid} style={styles.directoryItemAvatar} /> <Avatar text={avatar} size={30} type={type} rid={rid} style={styles.directoryItemAvatar} />

View File

@ -85,6 +85,7 @@ export default {
// DIRECTORY VIEW // DIRECTORY VIEW
DIRECTORY_SEARCH_USERS: 'directory_search_users', DIRECTORY_SEARCH_USERS: 'directory_search_users',
DIRECTORY_SEARCH_CHANNELS: 'directory_search_channels', DIRECTORY_SEARCH_CHANNELS: 'directory_search_channels',
DIRECTORY_SEARCH_TEAMS: 'directory_search_teams',
// NEW MESSAGE VIEW // NEW MESSAGE VIEW
NEW_MSG_CREATE_CHANNEL: 'new_msg_create_channel', NEW_MSG_CREATE_CHANNEL: 'new_msg_create_channel',

View File

@ -1,6 +1,5 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Animated, Easing, Switch, Text, TouchableWithoutFeedback, View } from 'react-native'; import { Animated, Easing, Switch, Text, TouchableWithoutFeedback, View } from 'react-native';
import PropTypes from 'prop-types';
import Touch from '../../utils/touch'; import Touch from '../../utils/touch';
import { CustomIcon } from '../../lib/Icons'; import { CustomIcon } from '../../lib/Icons';
@ -16,18 +15,20 @@ const ANIMATION_PROPS = {
useNativeDriver: true useNativeDriver: true
}; };
export default class DirectoryOptions extends PureComponent { interface IDirectoryOptionsProps {
static propTypes = { type: string;
type: PropTypes.string, globalUsers: boolean;
globalUsers: PropTypes.bool, isFederationEnabled: boolean;
isFederationEnabled: PropTypes.bool, close: Function;
close: PropTypes.func, changeType: Function;
changeType: PropTypes.func, toggleWorkspace(): void;
toggleWorkspace: PropTypes.func, theme: string;
theme: PropTypes.string }
};
constructor(props) { export default class DirectoryOptions extends PureComponent<IDirectoryOptionsProps, any> {
private animatedValue: Animated.Value;
constructor(props: IDirectoryOptionsProps) {
super(props); super(props);
this.animatedValue = new Animated.Value(0); this.animatedValue = new Animated.Value(0);
} }
@ -47,7 +48,7 @@ export default class DirectoryOptions extends PureComponent {
}).start(() => close()); }).start(() => close());
}; };
renderItem = itemType => { renderItem = (itemType: string) => {
const { changeType, type: propType, theme } = this.props; const { changeType, type: propType, theme } = this.props;
let text = 'Users'; let text = 'Users';
let icon = 'user'; let icon = 'user';

View File

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import { FlatList, Text, View } from 'react-native'; import { FlatList, Text, View } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
@ -24,9 +23,22 @@ import { goRoom } from '../../utils/goRoom';
import styles from './styles'; import styles from './styles';
import Options from './Options'; import Options from './Options';
class DirectoryView extends React.Component { interface IDirectoryViewProps {
static navigationOptions = ({ navigation, isMasterDetail }) => { navigation: object;
const options = { baseUrl: string;
isFederationEnabled: boolean;
user: {
id: string;
token: string;
};
theme: string;
directoryDefaultView: string;
isMasterDetail: boolean;
}
class DirectoryView extends React.Component<IDirectoryViewProps, any> {
static navigationOptions = ({ navigation, isMasterDetail }: any) => {
const options: any = {
title: I18n.t('Directory') title: I18n.t('Directory')
}; };
if (isMasterDetail) { if (isMasterDetail) {
@ -35,20 +47,7 @@ class DirectoryView extends React.Component {
return options; return options;
}; };
static propTypes = { constructor(props: IDirectoryViewProps) {
navigation: PropTypes.object,
baseUrl: PropTypes.string,
isFederationEnabled: PropTypes.bool,
user: PropTypes.shape({
id: PropTypes.string,
token: PropTypes.string
}),
theme: PropTypes.string,
directoryDefaultView: PropTypes.string,
isMasterDetail: PropTypes.bool
};
constructor(props) {
super(props); super(props);
this.state = { this.state = {
data: [], data: [],
@ -65,7 +64,7 @@ class DirectoryView extends React.Component {
this.load({}); this.load({});
} }
onSearchChangeText = text => { onSearchChangeText = (text: string) => {
this.setState({ text }, this.search); this.setState({ text }, this.search);
}; };
@ -115,7 +114,7 @@ class DirectoryView extends React.Component {
this.load({ newSearch: true }); this.load({ newSearch: true });
}; };
changeType = type => { changeType = (type: string) => {
this.setState({ type, data: [] }, () => this.search()); this.setState({ type, data: [] }, () => this.search());
if (type === 'users') { if (type === 'users') {
@ -129,17 +128,17 @@ class DirectoryView extends React.Component {
toggleWorkspace = () => { toggleWorkspace = () => {
this.setState( this.setState(
({ globalUsers }) => ({ globalUsers: !globalUsers, data: [] }), ({ globalUsers }: any) => ({ globalUsers: !globalUsers, data: [] }),
() => this.search() () => this.search()
); );
}; };
toggleDropdown = () => { toggleDropdown = () => {
this.setState(({ showOptionsDropdown }) => ({ showOptionsDropdown: !showOptionsDropdown })); this.setState(({ showOptionsDropdown }: any) => ({ showOptionsDropdown: !showOptionsDropdown }));
}; };
goRoom = item => { goRoom = (item: any) => {
const { navigation, isMasterDetail } = this.props; const { navigation, isMasterDetail }: any = this.props;
if (isMasterDetail) { if (isMasterDetail) {
navigation.navigate('DrawerNavigator'); navigation.navigate('DrawerNavigator');
} else { } else {
@ -148,7 +147,7 @@ class DirectoryView extends React.Component {
goRoom({ item, isMasterDetail }); goRoom({ item, isMasterDetail });
}; };
onPressItem = async item => { onPressItem = async (item: any) => {
const { type } = this.state; const { type } = this.state;
if (type === 'users') { if (type === 'users') {
const result = await RocketChat.createDirectMessage(item.username); const result = await RocketChat.createDirectMessage(item.username);
@ -215,7 +214,7 @@ class DirectoryView extends React.Component {
); );
}; };
renderItem = ({ item, index }) => { renderItem = ({ item, index }: any) => {
const { data, type } = this.state; const { data, type } = this.state;
const { baseUrl, user, theme } = this.props; const { baseUrl, user, theme } = this.props;
@ -308,7 +307,7 @@ class DirectoryView extends React.Component {
}; };
} }
const mapStateToProps = state => ({ const mapStateToProps = (state: any) => ({
baseUrl: state.server.server, baseUrl: state.server.server,
user: getUserSelector(state), user: getUserSelector(state),
isFederationEnabled: state.settings.FEDERATION_Enabled, isFederationEnabled: state.settings.FEDERATION_Enabled,

View File

@ -35,6 +35,7 @@ export default StyleSheet.create({
top: 0 top: 0
}, },
backdrop: { backdrop: {
// @ts-ignore
...StyleSheet.absoluteFill ...StyleSheet.absoluteFill
}, },
dropdownContainerHeader: { dropdownContainerHeader: {