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 'SettingsAppDownloadLinks' page to TypeScript #25175 #35890

Merged
merged 7 commits into from
Feb 19, 2024
Merged
Changes from 4 commits
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
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
import React from 'react';
import React, {useRef} from 'react';
import {ScrollView} from 'react-native';
import _ from 'underscore';
import type {View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItem from '@components/MenuItem';
import type {MenuItemProps} from '@components/MenuItem';
import ScreenWrapper from '@components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import * as Link from '@userActions/Link';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ROUTES from '@src/ROUTES';

const propTypes = {
...withLocalizePropTypes,
...windowDimensionsPropTypes,
type DownloadMenuItem = MenuItemProps & {
translationKey: TranslationPaths;
openAppDownloadLink: () => void;
downloadLink: string;
};

function AppDownloadLinksPage(props) {
function AppDownloadLinksPage() {
const styles = useThemeStyles();
let popoverAnchor;
const {translate} = useLocalize();
const popoverAnchor = useRef<View>(null);

const menuItems = [
const menuItems: DownloadMenuItem[] = [
{
translationKey: 'initialSettingsPage.appDownloadLinks.android.label',
icon: Expensicons.Android,
iconRight: Expensicons.NewWindow,
action: () => {
openAppDownloadLink: () => {
Link.openExternalLink(CONST.APP_DOWNLOAD_LINKS.ANDROID);
},
link: CONST.APP_DOWNLOAD_LINKS.ANDROID,
downloadLink: CONST.APP_DOWNLOAD_LINKS.ANDROID,
icon: Expensicons.Android,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for renaming? action > openAppDownloadLink, link > downloadLink

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was following my understanding of the Style document in the Naming Conventions->Event Handlers section found here. I then adjusted link to downloadLink to be more descriptive. Please let me know if 'action' and 'link' are preferred to the more descriptive names.

Copy link
Contributor

Choose a reason for hiding this comment

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

original names are fine to me

iconRight: Expensicons.NewWindow,
},
{
translationKey: 'initialSettingsPage.appDownloadLinks.ios.label',
icon: Expensicons.Apple,
iconRight: Expensicons.NewWindow,
action: () => {
openAppDownloadLink: () => {
Link.openExternalLink(CONST.APP_DOWNLOAD_LINKS.IOS, true);
},
link: CONST.APP_DOWNLOAD_LINKS.IOS,
downloadLink: CONST.APP_DOWNLOAD_LINKS.IOS,
icon: Expensicons.Apple,
iconRight: Expensicons.NewWindow,
},
{
translationKey: 'initialSettingsPage.appDownloadLinks.desktop.label',
icon: Expensicons.Monitor,
iconRight: Expensicons.NewWindow,
action: () => {
openAppDownloadLink: () => {
Link.openExternalLink(CONST.APP_DOWNLOAD_LINKS.DESKTOP);
},
link: CONST.APP_DOWNLOAD_LINKS.DESKTOP,
downloadLink: CONST.APP_DOWNLOAD_LINKS.DESKTOP,
icon: Expensicons.Monitor,
iconRight: Expensicons.NewWindow,
},
];

return (
<ScreenWrapper testID={AppDownloadLinksPage.displayName}>
<HeaderWithBackButton
title={props.translate('initialSettingsPage.aboutPage.appDownloadLinks')}
onBackButtonPress={() => Navigation.goBack()}
title={translate('initialSettingsPage.aboutPage.appDownloadLinks')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_ABOUT)}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My logic when I was working on the change was to make the navigation destination explicit. Now that I look at it there's no benefit to this. Navigation.goBack() works as intended here and removing the explicit destination makes the code more reusable if we ever want to present the AppDownloadLinks page from another screen in the future. If approved I will amend to remove ROUTES.SETTINGS_ABOUT as an argument and will then also be able to remove the ROUTES import statement above as this was the only use of ROUTES.

Copy link
Contributor

Choose a reason for hiding this comment

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

Keep original logic if possible.

<ScrollView style={[styles.mt3]}>
{_.map(menuItems, (item) => (
{menuItems.map((item: DownloadMenuItem) => (
<MenuItem
key={item.translationKey}
onPress={() => item.action()}
onSecondaryInteraction={(e) => ReportActionContextMenu.showContextMenu(CONST.CONTEXT_MENU_TYPES.LINK, e, item.link, popoverAnchor)}
onKeyDown={(event) => {
event.target.blur();
}}
ref={(el) => (popoverAnchor = el)}
title={props.translate(item.translationKey)}
onPress={item.openAppDownloadLink}
onSecondaryInteraction={(e) => ReportActionContextMenu.showContextMenu(CONST.CONTEXT_MENU_TYPES.LINK, e, item.downloadLink, popoverAnchor.current)}
ref={popoverAnchor}
title={translate(item.translationKey)}
icon={item.icon}
iconRight={item.iconRight}
shouldBlockSelection
Expand All @@ -81,7 +81,6 @@ function AppDownloadLinksPage(props) {
);
}

AppDownloadLinksPage.propTypes = propTypes;
AppDownloadLinksPage.displayName = 'AppDownloadLinksPage';

export default compose(withWindowDimensions, withLocalize)(AppDownloadLinksPage);
export default AppDownloadLinksPage;
Loading