diff options
Diffstat (limited to 'src/screens/Onboarding/StepTopicalFeeds.tsx')
-rw-r--r-- | src/screens/Onboarding/StepTopicalFeeds.tsx | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/screens/Onboarding/StepTopicalFeeds.tsx b/src/screens/Onboarding/StepTopicalFeeds.tsx new file mode 100644 index 000000000..516c18e6e --- /dev/null +++ b/src/screens/Onboarding/StepTopicalFeeds.tsx @@ -0,0 +1,113 @@ +import React from 'react' +import {View} from 'react-native' +import {useLingui} from '@lingui/react' +import {msg, Trans} from '@lingui/macro' + +import {atoms as a} from '#/alf' +import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRight} from '#/components/icons/Chevron' +import {ListMagnifyingGlass_Stroke2_Corner0_Rounded as ListMagnifyingGlass} from '#/components/icons/ListMagnifyingGlass' +import {Button, ButtonIcon, ButtonText} from '#/components/Button' +import * as Toggle from '#/components/forms/Toggle' +import {Loader} from '#/components/Loader' +import {useAnalytics} from '#/lib/analytics/analytics' + +import {Context} from '#/screens/Onboarding/state' +import { + Title, + Description, + OnboardingControls, +} from '#/screens/Onboarding/Layout' +import {FeedCard} from '#/screens/Onboarding/StepAlgoFeeds/FeedCard' +import {INTEREST_TO_DISPLAY_NAME} from '#/screens/Onboarding/StepInterests/data' +import {aggregateInterestItems} from '#/screens/Onboarding/util' +import {IconCircle} from '#/screens/Onboarding/IconCircle' + +export function StepTopicalFeeds() { + const {_} = useLingui() + const {track} = useAnalytics() + const {state, dispatch} = React.useContext(Context) + const [selectedFeedUris, setSelectedFeedUris] = React.useState<string[]>([]) + const [saving, setSaving] = React.useState(false) + const suggestedFeedUris = React.useMemo(() => { + return aggregateInterestItems( + state.interestsStepResults.selectedInterests, + state.interestsStepResults.apiResponse.suggestedFeedUris, + state.interestsStepResults.apiResponse.suggestedFeedUris.default, + ).slice(0, 10) + }, [state.interestsStepResults]) + + const interestsText = React.useMemo(() => { + const i = state.interestsStepResults.selectedInterests.map( + i => INTEREST_TO_DISPLAY_NAME[i], + ) + return i.join(', ') + }, [state.interestsStepResults.selectedInterests]) + + const saveFeeds = React.useCallback(async () => { + setSaving(true) + + dispatch({type: 'setTopicalFeedsStepResults', feedUris: selectedFeedUris}) + + setSaving(false) + dispatch({type: 'next'}) + track('OnboardingV2:StepTopicalFeeds:End', { + selectedFeeds: selectedFeedUris, + selectedFeedsLength: selectedFeedUris.length, + }) + }, [selectedFeedUris, dispatch, track]) + + React.useEffect(() => { + track('OnboardingV2:StepTopicalFeeds:Start') + }, [track]) + + return ( + <View style={[a.align_start]}> + <IconCircle icon={ListMagnifyingGlass} style={[a.mb_2xl]} /> + + <Title> + <Trans>Feeds can be topical as well!</Trans> + </Title> + <Description> + {state.interestsStepResults.selectedInterests.length ? ( + <Trans> + Here are some topical feeds based on your interests: {interestsText} + . You can choose to follow as many as you like. + </Trans> + ) : ( + <Trans> + Here are some popular topical feeds. You can choose to follow as + many as you like. + </Trans> + )} + </Description> + + <View style={[a.w_full, a.pb_2xl, a.pt_2xl]}> + <Toggle.Group + values={selectedFeedUris} + onChange={setSelectedFeedUris} + label={_(msg`Select topical feeds to follow from the list below`)}> + <View style={[a.gap_md]}> + {suggestedFeedUris.map(uri => ( + <FeedCard key={uri} config={{default: false, uri}} /> + ))} + </View> + </Toggle.Group> + </View> + + <OnboardingControls.Portal> + <Button + key={state.activeStep} // remove focus state on nav + variant="gradient" + color="gradient_sky" + size="large" + label={_(msg`Continue to next step`)} + onPress={saveFeeds}> + <ButtonText> + <Trans>Continue</Trans> + </ButtonText> + <ButtonIcon icon={saving ? Loader : ChevronRight} position="right" /> + </Button> + </OnboardingControls.Portal> + </View> + ) +} |