Chore: Evaluate AdminPanelView - TypeScript (#4162)
This commit is contained in:
parent
67073a1d75
commit
5970d29ee7
|
@ -198,7 +198,7 @@ const AdminPanelStackNavigator = () => {
|
||||||
return (
|
return (
|
||||||
<AdminPanelStack.Navigator
|
<AdminPanelStack.Navigator
|
||||||
screenOptions={{ ...defaultHeader, ...themedHeader(theme), ...StackAnimation } as StackNavigationOptions}>
|
screenOptions={{ ...defaultHeader, ...themedHeader(theme), ...StackAnimation } as StackNavigationOptions}>
|
||||||
<AdminPanelStack.Screen name='AdminPanelView' component={AdminPanelView} options={AdminPanelView.navigationOptions} />
|
<AdminPanelStack.Screen name='AdminPanelView' component={AdminPanelView} />
|
||||||
</AdminPanelStack.Navigator>
|
</AdminPanelStack.Navigator>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -196,11 +196,7 @@ const ModalStackNavigator = React.memo(({ navigation }: INavigation) => {
|
||||||
options={props => ProfileView.navigationOptions!({ ...props, isMasterDetail: true })}
|
options={props => ProfileView.navigationOptions!({ ...props, isMasterDetail: true })}
|
||||||
/>
|
/>
|
||||||
<ModalStack.Screen name='DisplayPrefsView' component={DisplayPrefsView} />
|
<ModalStack.Screen name='DisplayPrefsView' component={DisplayPrefsView} />
|
||||||
<ModalStack.Screen
|
<ModalStack.Screen name='AdminPanelView' component={AdminPanelView} />
|
||||||
name='AdminPanelView'
|
|
||||||
component={AdminPanelView}
|
|
||||||
options={props => AdminPanelView.navigationOptions!({ ...props, isMasterDetail: true })}
|
|
||||||
/>
|
|
||||||
<ModalStack.Screen name='NewMessageView' component={NewMessageView} options={NewMessageView.navigationOptions} />
|
<ModalStack.Screen name='NewMessageView' component={NewMessageView} options={NewMessageView.navigationOptions} />
|
||||||
<ModalStack.Screen name='SelectedUsersViewCreateChannel' component={SelectedUsersView} />
|
<ModalStack.Screen name='SelectedUsersViewCreateChannel' component={SelectedUsersView} />
|
||||||
<ModalStack.Screen name='CreateChannelView' component={CreateChannelView} options={CreateChannelView.navigationOptions} />
|
<ModalStack.Screen name='CreateChannelView' component={CreateChannelView} options={CreateChannelView.navigationOptions} />
|
||||||
|
|
|
@ -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 { WebView } from 'react-native-webview';
|
||||||
import { connect } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { DrawerScreenProps } from '@react-navigation/drawer';
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
import { StackNavigationOptions } from '@react-navigation/stack';
|
|
||||||
|
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import StatusBar from '../../containers/StatusBar';
|
import StatusBar from '../../containers/StatusBar';
|
||||||
import * as HeaderButton from '../../containers/HeaderButton';
|
import * as HeaderButton from '../../containers/HeaderButton';
|
||||||
import { withTheme } from '../../theme';
|
|
||||||
import { getUserSelector } from '../../selectors/login';
|
import { getUserSelector } from '../../selectors/login';
|
||||||
import SafeAreaView from '../../containers/SafeAreaView';
|
import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
import { AdminPanelStackParamList } from '../../stacks/types';
|
import { AdminPanelStackParamList } from '../../stacks/types';
|
||||||
|
import { IApplicationState } from '../../definitions';
|
||||||
|
|
||||||
interface IAdminPanelViewProps {
|
const AdminPanelView = () => {
|
||||||
baseUrl: string;
|
const navigation = useNavigation<StackNavigationProp<AdminPanelStackParamList, 'AdminPanelView'>>();
|
||||||
token: string;
|
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 {
|
useEffect(() => {
|
||||||
navigation: DrawerScreenProps<AdminPanelStackParamList, 'AdminPanelView'>;
|
navigation.setOptions({
|
||||||
isMasterDetail: boolean;
|
headerLeft: isMasterDetail ? undefined : () => <HeaderButton.Drawer navigation={navigation} />,
|
||||||
}
|
title: I18n.t('Admin_Panel')
|
||||||
|
});
|
||||||
|
}, [isMasterDetail, navigation]);
|
||||||
|
|
||||||
class AdminPanelView extends React.Component<IAdminPanelViewProps, any> {
|
if (!baseUrl) {
|
||||||
static navigationOptions = ({ navigation, isMasterDetail }: INavigationOptions): StackNavigationOptions => ({
|
return null;
|
||||||
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>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const mapStateToProps = (state: any) => ({
|
return (
|
||||||
baseUrl: state.server.server,
|
<SafeAreaView>
|
||||||
token: getUserSelector(state).token
|
<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;
|
||||||
|
|
Loading…
Reference in New Issue