Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'NewChatSelector' page to TypeScript... #38441

Merged
merged 6 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/TabSelector/TabSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ function TabSelector({state, navigation, onTabPress = () => {}, position}: TabSe
TabSelector.displayName = 'TabSelector';

export default TabSelector;

export type { TabSelectorProps }
7 changes: 5 additions & 2 deletions src/libs/Navigation/OnyxTabNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type {MaterialTopTabNavigationEventMap} from '@react-navigation/material-top-tabs';
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs';
import type {EventMapCore, NavigationState, ScreenListeners} from '@react-navigation/native';
import React from 'react';
import React, { ReactNode } from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Tab from '@userActions/Tab';
import ONYXKEYS from '@src/ONYXKEYS';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {defaultScreenOptions} from './OnyxTabNavigatorConfig';
import { TabSelectorProps } from '@components/TabSelector/TabSelector';

type OnyxTabNavigatorOnyxProps = {
selectedTab: OnyxEntry<string>;
Expand All @@ -24,6 +25,8 @@ type OnyxTabNavigatorProps = OnyxTabNavigatorOnyxProps &
/** A function triggered when a tab has been selected */
onTabSelected?: (newIouType: string) => void;

tabBar: (props: TabSelectorProps) => ReactNode

screenListeners?: ScreenListeners<NavigationState, MaterialTopTabNavigationEventMap>;
};

Expand All @@ -32,7 +35,7 @@ export const TopTab = createMaterialTopTabNavigator();

// This takes all the same props as MaterialTopTabsNavigator: https://reactnavigation.org/docs/material-top-tab-navigator/#props,
// except ID is now required, and it gets a `selectedTab` from Onyx
function OnyxTabNavigator({id, selectedTab = '', children, onTabSelected = () => {}, screenListeners, ...rest}: OnyxTabNavigatorProps) {
function OnyxTabNavigator({id, selectedTab = '', children, onTabSelected = () => {}, screenListeners, tabBar, ...rest}: OnyxTabNavigatorProps) {
return (
<TopTab.Navigator
/* eslint-disable-next-line react/jsx-props-no-spreading */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
import {useNavigation} from '@react-navigation/native';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import TabSelector from '@components/TabSelector/TabSelector';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import compose from '@libs/compose';
import OnyxTabNavigator, {TopTab} from '@libs/Navigation/OnyxTabNavigator';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import NewChatPage from './NewChatPage';
import WorkspaceNewRoomPage from './workspace/WorkspaceNewRoomPage';
import useLocalize from '@hooks/useLocalize';

const propTypes = {
...windowDimensionsPropTypes,

...withLocalizePropTypes,
};

const defaultProps = {
betas: [],
personalDetails: {},
reports: {},
};

function NewChatSelectorPage(props) {
const navigation = useNavigation();

function NewChatSelectorPage() {
const {translate} = useLocalize();
return (
<ScreenWrapper
<ScreenWrapper
shouldEnableKeyboardAvoidingView={false}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a space added? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied and pasted last changes. Maybe this caused some issues. I'll fix them.

includeSafeAreaPaddingBottom={false}
shouldShowOfflineIndicator={false}
shouldEnableMaxHeight
testID={NewChatSelectorPage.displayName}
>
<HeaderWithBackButton
title={props.translate('sidebarScreen.fabNewChat')}
onBackButtonPress={navigation.goBack}
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied and pasted last changes. Maybe this caused some issues. I'll fix them.

<HeaderWithBackButton title={translate('sidebarScreen.fabNewChat')} />
<OnyxTabNavigator
id={CONST.TAB.NEW_CHAT_TAB_ID}
tabBar={TabSelector}
tabBar={({state, navigation, position}) => (
<TabSelector
state={state}
navigation={navigation}
position={position}
/>
)}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tabBar={({state, navigation, position}) => (
<TabSelector
state={state}
navigation={navigation}
position={position}
/>
)}
tabBar={TabSelector}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Will do it.

<TopTab.Screen
name={CONST.TAB.NEW_CHAT}
// @ts-expect-error TODO: 'isGroupChat' is declared here.
component={NewChatPage}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this ts expect error, instead let's make isGroupChat optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

/>
<TopTab.Screen
Expand All @@ -57,14 +44,6 @@ function NewChatSelectorPage(props) {
);
}

NewChatSelectorPage.propTypes = propTypes;
NewChatSelectorPage.defaultProps = defaultProps;
NewChatSelectorPage.displayName = 'NewChatSelectorPage';

export default compose(
withLocalize,
withWindowDimensions,
withOnyx({
betas: {key: ONYXKEYS.BETAS},
}),
)(NewChatSelectorPage);
export default NewChatSelectorPage
Loading