Skip to content

Commit

Permalink
Merge pull request #35058 from lukemorawski/20354-quick_fix_searchpag…
Browse files Browse the repository at this point in the history
…e_list_refactor

20354 quick fix searchpage list refactor
  • Loading branch information
cristipaval authored Feb 6, 2024
2 parents 13f832c + e45d6e0 commit d5a766c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 271 deletions.
32 changes: 25 additions & 7 deletions src/components/ReferralProgramCTA.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
import Navigation from '@src/libs/Navigation/Navigation';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {DismissedReferralBanners} from '@src/types/onyx/Account';
import Icon from './Icon';
import {Close} from './Icon/Expensicons';
import {PressableWithoutFeedback} from './Pressable';
import Text from './Text';
import Tooltip from './Tooltip';

type ReferralProgramCTAProps = {
type ReferralProgramCTAOnyxProps = {
dismissedReferralBanners: DismissedReferralBanners;
};

type ReferralProgramCTAProps = ReferralProgramCTAOnyxProps & {
referralContentType:
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.MONEY_REQUEST
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.START_CHAT
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.SEND_MONEY
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND;

/** Method to trigger when pressing close button of the banner */
onCloseButtonPress?: () => void;
};

function ReferralProgramCTA({referralContentType, onCloseButtonPress = () => {}}: ReferralProgramCTAProps) {
function ReferralProgramCTA({referralContentType, dismissedReferralBanners}: ReferralProgramCTAProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();

const handleDismissCallToAction = () => {
User.dismissReferralBanner(CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND);
};

if (!referralContentType || dismissedReferralBanners[referralContentType]) {
return null;
}

return (
<PressableWithoutFeedback
onPress={() => {
Expand All @@ -47,7 +60,7 @@ function ReferralProgramCTA({referralContentType, onCloseButtonPress = () => {}}
</Text>
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={onCloseButtonPress}
onPress={handleDismissCallToAction}
onMouseDown={(e) => {
e.preventDefault();
}}
Expand All @@ -67,4 +80,9 @@ function ReferralProgramCTA({referralContentType, onCloseButtonPress = () => {}}
);
}

export default ReferralProgramCTA;
export default withOnyx<ReferralProgramCTAProps, ReferralProgramCTAOnyxProps>({
dismissedReferralBanners: {
key: ONYXKEYS.ACCOUNT,
selector: (data) => data?.dismissedReferralBanners ?? {},
},
})(ReferralProgramCTA);
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
shouldShowTooltips = true,
shouldUseDynamicMaxToRenderPerBatch = false,
rightHandSideComponent,
isLoadingNewOptions = false,
}: BaseSelectionListProps<TItem>,
inputRef: ForwardedRef<RNTextInput>,
) {
Expand Down Expand Up @@ -412,6 +413,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
spellCheck={false}
onSubmitEditing={selectFocusedOption}
blurOnSubmit={!!flattenedSections.allOptions.length}
isLoading={isLoadingNewOptions}
/>
</View>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ type BaseSelectionListProps<TItem extends User | RadioItem> = Partial<ChildrenPr

/** Component to display on the right side of each child */
rightHandSideComponent?: ((item: TItem) => ReactElement<TItem>) | ReactElement | null;

/** Whether to show the loading indicator for new options */
isLoadingNewOptions?: boolean;
};

type ItemLayout = {
Expand Down
227 changes: 0 additions & 227 deletions src/pages/SearchPage.js

This file was deleted.

37 changes: 6 additions & 31 deletions src/pages/SearchPage/SearchPageFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
import React, {useState} from 'react';
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import ReferralProgramCTA from '@components/ReferralProgramCTA';
import useThemeStyles from '@hooks/useThemeStyles';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {DismissedReferralBanners} from '@src/types/onyx/Account';

type SearchPageFooterOnyxProps = {
dismissedReferralBanners: DismissedReferralBanners;
};
function SearchPageFooter({dismissedReferralBanners}: SearchPageFooterOnyxProps) {
const [shouldShowReferralCTA, setShouldShowReferralCTA] = useState(!dismissedReferralBanners[CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND]);
function SearchPageFooter() {
const themeStyles = useThemeStyles();

const closeCallToActionBanner = () => {
setShouldShowReferralCTA(false);
User.dismissReferralBanner(CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND);
};

return (
<>
{shouldShowReferralCTA && (
<View style={[themeStyles.pb5, themeStyles.flexShrink0]}>
<ReferralProgramCTA
referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND}
onCloseButtonPress={closeCallToActionBanner}
/>
</View>
)}
</>
<View style={[themeStyles.flexShrink0]}>
<ReferralProgramCTA referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND} />
</View>
);
}

SearchPageFooter.displayName = 'SearchPageFooter';

export default withOnyx<SearchPageFooterOnyxProps, SearchPageFooterOnyxProps>({
dismissedReferralBanners: {
key: ONYXKEYS.ACCOUNT,
selector: (data) => data?.dismissedReferralBanners ?? {},
},
})(SearchPageFooter);
export default SearchPageFooter;
Loading

0 comments on commit d5a766c

Please sign in to comment.