Skip to content

Commit

Permalink
Trending tracking 2 (#7162)
Browse files Browse the repository at this point in the history
* Move

(cherry picked from commit bfb96f4)

* Add to recommeded too

(cherry picked from commit e684488)

---------

Co-authored-by: Dan Abramov <[email protected]>
  • Loading branch information
estrattonbailey and gaearon authored Dec 18, 2024
1 parent a7f763f commit c8e307b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/lib/statsig/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ export type LogEvents = {

'trendingTopics:show': {}
'trendingTopics:hide': {
context: 'sidebar' | 'interstitial' | 'explore'
context:
| 'sidebar'
| 'interstitial'
| 'explore:trending'
| 'explore:recommendations'
}
}
43 changes: 39 additions & 4 deletions src/screens/Search/components/ExploreRecommendations.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React from 'react'
import {View} from 'react-native'
import {Trans} from '@lingui/macro'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {logEvent} from '#/lib/statsig/statsig'
import {isWeb} from '#/platform/detection'
import {useTrendingSettings} from '#/state/preferences/trending'
import {
useTrendingSettings,
useTrendingSettingsApi,
} from '#/state/preferences/trending'
import {
DEFAULT_LIMIT as RECOMMENDATIONS_COUNT,
useTrendingTopics,
} from '#/state/queries/trending/useTrendingTopics'
import {useTrendingConfig} from '#/state/trending-config'
import {atoms as a, useGutters, useTheme} from '#/alf'
import {Button, ButtonIcon} from '#/components/Button'
import {Hashtag_Stroke2_Corner0_Rounded} from '#/components/icons/Hashtag'
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
import * as Prompt from '#/components/Prompt'
import {
TrendingTopic,
TrendingTopicLink,
Expand All @@ -25,17 +34,26 @@ export function ExploreRecommendations() {

function Inner() {
const t = useTheme()
const {_} = useLingui()
const gutters = useGutters([0, 'compact'])
const {data: trending, error, isLoading} = useTrendingTopics()
const noRecs = !isLoading && !error && !trending?.suggested?.length
const {setTrendingDisabled} = useTrendingSettingsApi()
const trendingPrompt = Prompt.usePromptControl()

const onConfirmHide = React.useCallback(() => {
logEvent('trendingTopics:hide', {context: 'explore:recommendations'})
setTrendingDisabled(true)
}, [setTrendingDisabled])

return error || noRecs ? null : (
<>
<View
style={[
a.flex_row,
isWeb
? [a.flex_row, a.px_lg, a.py_lg, a.pt_2xl, a.gap_md]
: [{flexDirection: 'row-reverse'}, a.p_lg, a.pt_2xl, a.gap_md],
? [a.px_lg, a.py_lg, a.pt_2xl, a.gap_md]
: [a.p_lg, a.pt_2xl, a.gap_md],
a.border_b,
t.atoms.border_contrast_low,
]}>
Expand All @@ -54,6 +72,15 @@ function Inner() {
<Trans>Feeds we think you might like.</Trans>
</Text>
</View>
<Button
label={_(msg`Hide trending topics`)}
size="small"
variant="ghost"
color="secondary"
shape="round"
onPress={() => trendingPrompt.open()}>
<ButtonIcon icon={X} />
</Button>
</View>

<View style={[a.pt_md, a.pb_lg]}>
Expand Down Expand Up @@ -90,6 +117,14 @@ function Inner() {
)}
</View>
</View>

<Prompt.Basic
control={trendingPrompt}
title={_(msg`Hide trending topics?`)}
description={_(msg`You can update this later from your settings.`)}
confirmButtonCta={_(msg`Hide`)}
onConfirm={onConfirmHide}
/>
</>
)
}
10 changes: 5 additions & 5 deletions src/screens/Search/components/ExploreTrendingTopics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ function Inner() {
const trendingPrompt = Prompt.usePromptControl()

const onConfirmHide = React.useCallback(() => {
logEvent('trendingTopics:hide', {context: 'explore'})
logEvent('trendingTopics:hide', {context: 'explore:trending'})
setTrendingDisabled(true)
}, [setTrendingDisabled])

return error || noTopics ? null : (
<>
<View
style={[
a.flex_row,
isWeb
? [a.flex_row, a.px_lg, a.py_lg, a.pt_2xl, a.gap_md]
: [{flexDirection: 'row-reverse'}, a.p_lg, a.pt_2xl, a.gap_md],
? [a.px_lg, a.py_lg, a.pt_2xl, a.gap_md]
: [a.p_lg, a.pt_2xl, a.gap_md],
a.border_b,
t.atoms.border_contrast_low,
]}>
Expand All @@ -78,9 +79,8 @@ function Inner() {
<Trans>What people are posting about.</Trans>
</Text>
</View>

<Button
label={_(msg`Hide trending tpoics`)}
label={_(msg`Hide trending topics`)}
size="small"
variant="ghost"
color="secondary"
Expand Down

0 comments on commit c8e307b

Please sign in to comment.