about summary refs log tree commit diff
path: root/src/screens/Search/modules/ExploreInterestsCard.tsx
blob: a2c6ff36db35c4f2ed2638010a94b1b426a2cd23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import {useState} from 'react'
import {View} from 'react-native'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {Nux, useSaveNux} from '#/state/queries/nuxs'
import {usePreferencesQuery} from '#/state/queries/preferences'
import {useInterestsDisplayNames} from '#/screens/Onboarding/state'
import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
import {Link} from '#/components/Link'
import * as Prompt from '#/components/Prompt'
import {Text} from '#/components/Typography'

export function ExploreInterestsCard() {
  const t = useTheme()
  const {_} = useLingui()
  const {data: preferences} = usePreferencesQuery()
  const interestsDisplayNames = useInterestsDisplayNames()
  const {mutateAsync: saveNux} = useSaveNux()
  const trendingPrompt = Prompt.usePromptControl()
  const [closing, setClosing] = useState(false)

  const onClose = () => {
    trendingPrompt.open()
  }
  const onConfirmClose = () => {
    setClosing(true)
    // if this fails, they can try again later
    saveNux({
      id: Nux.ExploreInterestsCard,
      completed: true,
      data: undefined,
    }).catch(() => {})
  }

  return closing ? null : (
    <>
      <Prompt.Basic
        control={trendingPrompt}
        title={_(msg`Your interests`)}
        description={_(
          msg`You can adjust your interests at any time from your "Content and media" settings.`,
        )}
        confirmButtonCta={_(
          msg({
            message: `Copy that!`,
            comment: `Confirm button text. Can be a short cheeky phrase that means "OK" e.g. "Copy that!"`,
          }),
        )}
        onConfirm={onConfirmClose}
      />

      <View style={[a.p_lg, a.pb_2xs]}>
        <View
          style={[
            a.p_lg,
            a.rounded_md,
            a.border,
            a.gap_sm,
            t.atoms.border_contrast_medium,
            t.atoms.bg_contrast_25,
          ]}>
          <Text style={[a.text_md, a.font_bold, a.leading_tight]}>
            <Trans>Your interests</Trans>
          </Text>

          {preferences?.interests?.tags &&
          preferences.interests.tags.length > 0 ? (
            <View style={[a.flex_row, a.flex_wrap, {gap: 6}]}>
              {preferences.interests.tags.map(tag => (
                <View
                  key={tag}
                  style={[
                    a.justify_center,
                    a.align_center,
                    a.rounded_full,
                    a.border,
                    t.atoms.border_contrast_medium,
                    a.px_lg,
                    {height: 32},
                  ]}>
                  <Text style={[a.text_sm, t.atoms.text_contrast_medium]}>
                    {interestsDisplayNames[tag]}
                  </Text>
                </View>
              ))}
            </View>
          ) : null}

          <Text style={[a.text_sm, a.leading_snug, a.pb_xs]}>
            <Trans>
              Your selected interests help us serve you content you care about.
            </Trans>
          </Text>

          <Link
            label={_(msg`Edit interests`)}
            to="/settings/interests"
            size="small"
            variant="solid"
            color="primary"
            style={[a.justify_center]}>
            <ButtonText>
              <Trans>Edit interests</Trans>
            </ButtonText>
          </Link>

          <Button
            label={_(msg`Hide this card`)}
            size="small"
            variant="solid"
            color="secondary"
            shape="round"
            onPress={onClose}
            style={[
              a.absolute,
              {top: a.pt_xs.paddingTop, right: a.pr_xs.paddingRight},
            ]}>
            <ButtonIcon icon={X} />
          </Button>
        </View>
      </View>
    </>
  )
}