Chore: Evaluate AdminPanelView - TypeScript (#4162)

This commit is contained in:
Reinaldo Neto 2022-05-11 13:33:27 -03:00 committed by GitHub
parent 67073a1d75
commit 5970d29ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 47 deletions

View File

@ -198,7 +198,7 @@ const AdminPanelStackNavigator = () => {
return (
<AdminPanelStack.Navigator
screenOptions={{ ...defaultHeader, ...themedHeader(theme), ...StackAnimation } as StackNavigationOptions}>
<AdminPanelStack.Screen name='AdminPanelView' component={AdminPanelView} options={AdminPanelView.navigationOptions} />
<AdminPanelStack.Screen name='AdminPanelView' component={AdminPanelView} />
</AdminPanelStack.Navigator>
);
};

View File

@ -196,11 +196,7 @@ const ModalStackNavigator = React.memo(({ navigation }: INavigation) => {
options={props => ProfileView.navigationOptions!({ ...props, isMasterDetail: true })}
/>
<ModalStack.Screen name='DisplayPrefsView' component={DisplayPrefsView} />
<ModalStack.Screen
name='AdminPanelView'
component={AdminPanelView}
options={props => AdminPanelView.navigationOptions!({ ...props, isMasterDetail: true })}
/>
<ModalStack.Screen name='AdminPanelView' component={AdminPanelView} />
<ModalStack.Screen name='NewMessageView' component={NewMessageView} options={NewMessageView.navigationOptions} />
<ModalStack.Screen name='SelectedUsersViewCreateChannel' component={SelectedUsersView} />
<ModalStack.Screen name='CreateChannelView' component={CreateChannelView} options={CreateChannelView.navigationOptions} />

View File

@ -1,55 +1,45 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useNavigation } from '@react-navigation/native';
import { WebView } from 'react-native-webview';
import { connect } from 'react-redux';
import { DrawerScreenProps } from '@react-navigation/drawer';
import { StackNavigationOptions } from '@react-navigation/stack';
import { useSelector } from 'react-redux';
import { StackNavigationProp } from '@react-navigation/stack';
import I18n from '../../i18n';
import StatusBar from '../../containers/StatusBar';
import * as HeaderButton from '../../containers/HeaderButton';
import { withTheme } from '../../theme';
import { getUserSelector } from '../../selectors/login';
import SafeAreaView from '../../containers/SafeAreaView';
import { AdminPanelStackParamList } from '../../stacks/types';
import { IApplicationState } from '../../definitions';
interface IAdminPanelViewProps {
baseUrl: string;
token: string;
}
const AdminPanelView = () => {
const navigation = useNavigation<StackNavigationProp<AdminPanelStackParamList, 'AdminPanelView'>>();
const baseUrl = useSelector((state: IApplicationState) => state.server.server);
const token = useSelector((state: IApplicationState) => getUserSelector(state).token);
const isMasterDetail = useSelector((state: IApplicationState) => state.app.isMasterDetail);
interface INavigationOptions {
navigation: DrawerScreenProps<AdminPanelStackParamList, 'AdminPanelView'>;
isMasterDetail: boolean;
}
useEffect(() => {
navigation.setOptions({
headerLeft: isMasterDetail ? undefined : () => <HeaderButton.Drawer navigation={navigation} />,
title: I18n.t('Admin_Panel')
});
}, [isMasterDetail, navigation]);
class AdminPanelView extends React.Component<IAdminPanelViewProps, any> {
static navigationOptions = ({ navigation, isMasterDetail }: INavigationOptions): StackNavigationOptions => ({
headerLeft: isMasterDetail ? undefined : () => <HeaderButton.Drawer navigation={navigation} />,
title: I18n.t('Admin_Panel')
});
render() {
const { baseUrl, token } = this.props;
if (!baseUrl) {
return null;
}
return (
<SafeAreaView>
<StatusBar />
<WebView
// https://github.com/react-native-community/react-native-webview/issues/1311
onMessage={() => {}}
source={{ uri: `${baseUrl}/admin/info?layout=embedded` }}
injectedJavaScript={`Meteor.loginWithToken('${token}', function() { })`}
/>
</SafeAreaView>
);
if (!baseUrl) {
return null;
}
}
const mapStateToProps = (state: any) => ({
baseUrl: state.server.server,
token: getUserSelector(state).token
});
return (
<SafeAreaView>
<StatusBar />
<WebView
// https://github.com/react-native-community/react-native-webview/issues/1311
onMessage={() => {}}
source={{ uri: `${baseUrl}/admin/info?layout=embedded` }}
injectedJavaScript={`Meteor.loginWithToken('${token}', function() { })`}
/>
</SafeAreaView>
);
};
export default connect(mapStateToProps)(withTheme(AdminPanelView));
export default AdminPanelView;