Make trending setting global
This commit is contained in:
@@ -26,8 +26,8 @@ import {Text} from '#/components/Typography'
|
|||||||
|
|
||||||
export function TrendingInterstitial() {
|
export function TrendingInterstitial() {
|
||||||
const {enabled} = useTrendingConfig()
|
const {enabled} = useTrendingConfig()
|
||||||
const {trendingDiscoverHidden} = useTrendingSettings()
|
const {trendingDisabled} = useTrendingSettings()
|
||||||
return !enabled ? null : trendingDiscoverHidden ? null : <Inner />
|
return enabled && !trendingDisabled ? <Inner /> : null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Inner() {
|
export function Inner() {
|
||||||
@@ -35,7 +35,7 @@ export function Inner() {
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const gutters = useGutters(['base'])
|
const gutters = useGutters(['base'])
|
||||||
const trendingPrompt = Prompt.usePromptControl()
|
const trendingPrompt = Prompt.usePromptControl()
|
||||||
const {setTrendingDiscoverHidden} = useTrendingSettingsApi()
|
const {setTrendingDisabled} = useTrendingSettingsApi()
|
||||||
const {data: trending, error, isLoading} = useTrendingTopics()
|
const {data: trending, error, isLoading} = useTrendingTopics()
|
||||||
const noTopics = !isLoading && !error && !trending?.topics?.length
|
const noTopics = !isLoading && !error && !trending?.topics?.length
|
||||||
|
|
||||||
@@ -101,12 +101,12 @@ export function Inner() {
|
|||||||
|
|
||||||
<Prompt.Basic
|
<Prompt.Basic
|
||||||
control={trendingPrompt}
|
control={trendingPrompt}
|
||||||
title={_(msg`Hide trending topics in your feed?`)}
|
title={_(msg`Hide trending topics?`)}
|
||||||
description={_(
|
description={_(
|
||||||
msg`This is a device setting, and will apply to all accounts on this device. You can update this later from your settings.`,
|
msg`This will disable trending topics for all accounts on this device. You can update this later from your settings.`,
|
||||||
)}
|
)}
|
||||||
confirmButtonCta={_(msg`Hide`)}
|
confirmButtonCta={_(msg`Hide`)}
|
||||||
onConfirm={() => setTrendingDiscoverHidden(true)}
|
onConfirm={() => setTrendingDisabled(true)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {View} from 'react-native'
|
|||||||
import {Trans} from '@lingui/macro'
|
import {Trans} from '@lingui/macro'
|
||||||
|
|
||||||
import {isWeb} from '#/platform/detection'
|
import {isWeb} from '#/platform/detection'
|
||||||
|
import {useTrendingSettings} from '#/state/preferences/trending'
|
||||||
import {
|
import {
|
||||||
DEFAULT_LIMIT as TRENDING_TOPICS_COUNT,
|
DEFAULT_LIMIT as TRENDING_TOPICS_COUNT,
|
||||||
useTrendingTopics,
|
useTrendingTopics,
|
||||||
@@ -19,7 +20,8 @@ import {Text} from '#/components/Typography'
|
|||||||
|
|
||||||
export function ExploreTrendingTopics() {
|
export function ExploreTrendingTopics() {
|
||||||
const {enabled} = useTrendingConfig()
|
const {enabled} = useTrendingConfig()
|
||||||
return enabled ? <Inner /> : null
|
const {trendingDisabled} = useTrendingSettings()
|
||||||
|
return enabled && !trendingDisabled ? <Inner /> : null
|
||||||
}
|
}
|
||||||
|
|
||||||
function Inner() {
|
function Inner() {
|
||||||
|
|||||||
@@ -36,9 +36,8 @@ export function ContentAndMediaSettingsScreen({}: Props) {
|
|||||||
const inAppBrowserPref = useInAppBrowser()
|
const inAppBrowserPref = useInAppBrowser()
|
||||||
const setUseInAppBrowser = useSetInAppBrowser()
|
const setUseInAppBrowser = useSetInAppBrowser()
|
||||||
const {enabled: trendingEnabled} = useTrendingConfig()
|
const {enabled: trendingEnabled} = useTrendingConfig()
|
||||||
const {trendingSidebarHidden, trendingDiscoverHidden} = useTrendingSettings()
|
const {trendingDisabled} = useTrendingSettings()
|
||||||
const {setTrendingSidebarHidden, setTrendingDiscoverHidden} =
|
const {setTrendingDisabled} = useTrendingSettingsApi()
|
||||||
useTrendingSettingsApi()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout.Screen>
|
<Layout.Screen>
|
||||||
@@ -117,30 +116,15 @@ export function ContentAndMediaSettingsScreen({}: Props) {
|
|||||||
{trendingEnabled && (
|
{trendingEnabled && (
|
||||||
<>
|
<>
|
||||||
<SettingsList.Divider />
|
<SettingsList.Divider />
|
||||||
{!isNative && (
|
|
||||||
<Toggle.Item
|
|
||||||
name="show_trending_topics_sidebar"
|
|
||||||
label={_(msg`Show trending topics in your sidebar`)}
|
|
||||||
value={!trendingSidebarHidden}
|
|
||||||
onChange={value => setTrendingSidebarHidden(!value)}>
|
|
||||||
<SettingsList.Item>
|
|
||||||
<SettingsList.ItemIcon icon={Graph} />
|
|
||||||
<SettingsList.ItemText>
|
|
||||||
<Trans>Show trending topics in your sidebar</Trans>
|
|
||||||
</SettingsList.ItemText>
|
|
||||||
<Toggle.Platform />
|
|
||||||
</SettingsList.Item>
|
|
||||||
</Toggle.Item>
|
|
||||||
)}
|
|
||||||
<Toggle.Item
|
<Toggle.Item
|
||||||
name="show_trending_topics_discover"
|
name="show_trending_topics"
|
||||||
label={_(msg`Show trending topics in your feed`)}
|
label={_(msg`Enable trending topics`)}
|
||||||
value={!trendingDiscoverHidden}
|
value={!trendingDisabled}
|
||||||
onChange={value => setTrendingDiscoverHidden(!value)}>
|
onChange={value => setTrendingDisabled(!value)}>
|
||||||
<SettingsList.Item>
|
<SettingsList.Item>
|
||||||
<SettingsList.ItemIcon icon={Graph} />
|
<SettingsList.ItemIcon icon={Graph} />
|
||||||
<SettingsList.ItemText>
|
<SettingsList.ItemText>
|
||||||
<Trans>Show trending topics in your feed</Trans>
|
<Trans>Enable trending topics</Trans>
|
||||||
</SettingsList.ItemText>
|
</SettingsList.ItemText>
|
||||||
<Toggle.Platform />
|
<Toggle.Platform />
|
||||||
</SettingsList.Item>
|
</SettingsList.Item>
|
||||||
|
|||||||
@@ -125,12 +125,7 @@ const schema = z.object({
|
|||||||
subtitlesEnabled: z.boolean().optional(),
|
subtitlesEnabled: z.boolean().optional(),
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
mutedThreads: z.array(z.string()),
|
mutedThreads: z.array(z.string()),
|
||||||
|
trendingDisabled: z.boolean().optional(),
|
||||||
/*
|
|
||||||
* Trending
|
|
||||||
*/
|
|
||||||
trendingSidebarHidden: z.boolean().optional(),
|
|
||||||
trendingDiscoverHidden: z.boolean().optional(),
|
|
||||||
})
|
})
|
||||||
export type Schema = z.infer<typeof schema>
|
export type Schema = z.infer<typeof schema>
|
||||||
|
|
||||||
@@ -176,12 +171,7 @@ export const defaults: Schema = {
|
|||||||
kawaii: false,
|
kawaii: false,
|
||||||
hasCheckedForStarterPack: false,
|
hasCheckedForStarterPack: false,
|
||||||
subtitlesEnabled: true,
|
subtitlesEnabled: true,
|
||||||
|
trendingDisabled: false,
|
||||||
/*
|
|
||||||
* Trending
|
|
||||||
*/
|
|
||||||
trendingSidebarHidden: false,
|
|
||||||
trendingDiscoverHidden: false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tryParse(rawData: string): Schema | undefined {
|
export function tryParse(rawData: string): Schema | undefined {
|
||||||
|
|||||||
@@ -3,31 +3,19 @@ import React from 'react'
|
|||||||
import * as persisted from '#/state/persisted'
|
import * as persisted from '#/state/persisted'
|
||||||
|
|
||||||
type StateContext = {
|
type StateContext = {
|
||||||
trendingSidebarHidden: Exclude<
|
trendingDisabled: Exclude<persisted.Schema['trendingDisabled'], undefined>
|
||||||
persisted.Schema['trendingSidebarHidden'],
|
|
||||||
undefined
|
|
||||||
>
|
|
||||||
trendingDiscoverHidden: Exclude<
|
|
||||||
persisted.Schema['trendingDiscoverHidden'],
|
|
||||||
undefined
|
|
||||||
>
|
|
||||||
}
|
}
|
||||||
type ApiContext = {
|
type ApiContext = {
|
||||||
setTrendingSidebarHidden(
|
setTrendingDisabled(
|
||||||
hidden: Exclude<persisted.Schema['trendingSidebarHidden'], undefined>,
|
hidden: Exclude<persisted.Schema['trendingDisabled'], undefined>,
|
||||||
): void
|
|
||||||
setTrendingDiscoverHidden(
|
|
||||||
hidden: Exclude<persisted.Schema['trendingDiscoverHidden'], undefined>,
|
|
||||||
): void
|
): void
|
||||||
}
|
}
|
||||||
|
|
||||||
const StateContext = React.createContext<StateContext>({
|
const StateContext = React.createContext<StateContext>({
|
||||||
trendingSidebarHidden: Boolean(persisted.defaults.trendingSidebarHidden),
|
trendingDisabled: Boolean(persisted.defaults.trendingDisabled),
|
||||||
trendingDiscoverHidden: Boolean(persisted.defaults.trendingDiscoverHidden),
|
|
||||||
})
|
})
|
||||||
const ApiContext = React.createContext<ApiContext>({
|
const ApiContext = React.createContext<ApiContext>({
|
||||||
setTrendingSidebarHidden() {},
|
setTrendingDisabled() {},
|
||||||
setTrendingDiscoverHidden() {},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function usePersistedBooleanValue<T extends keyof persisted.Schema>(key: T) {
|
function usePersistedBooleanValue<T extends keyof persisted.Schema>(key: T) {
|
||||||
@@ -53,21 +41,16 @@ function usePersistedBooleanValue<T extends keyof persisted.Schema>(key: T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
const [trendingSidebarHidden, setTrendingSidebarHidden] =
|
const [trendingDisabled, setTrendingDisabled] =
|
||||||
usePersistedBooleanValue('trendingSidebarHidden')
|
usePersistedBooleanValue('trendingDisabled')
|
||||||
const [trendingDiscoverHidden, setTrendingDiscoverHidden] =
|
|
||||||
usePersistedBooleanValue('trendingDiscoverHidden')
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Context
|
* Context
|
||||||
*/
|
*/
|
||||||
const state = React.useMemo(
|
const state = React.useMemo(() => ({trendingDisabled}), [trendingDisabled])
|
||||||
() => ({trendingSidebarHidden, trendingDiscoverHidden}),
|
|
||||||
[trendingSidebarHidden, trendingDiscoverHidden],
|
|
||||||
)
|
|
||||||
const api = React.useMemo(
|
const api = React.useMemo(
|
||||||
() => ({setTrendingSidebarHidden, setTrendingDiscoverHidden}),
|
() => ({setTrendingDisabled}),
|
||||||
[setTrendingSidebarHidden, setTrendingDiscoverHidden],
|
[setTrendingDisabled],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ let PostFeed = ({
|
|||||||
const showProgressIntersitial =
|
const showProgressIntersitial =
|
||||||
(followProgressGuide || followAndLikeProgressGuide) && !isDesktop
|
(followProgressGuide || followAndLikeProgressGuide) && !isDesktop
|
||||||
|
|
||||||
const {trendingDiscoverHidden} = useTrendingSettings()
|
const {trendingDisabled} = useTrendingSettings()
|
||||||
|
|
||||||
const feedItems: FeedRow[] = React.useMemo(() => {
|
const feedItems: FeedRow[] = React.useMemo(() => {
|
||||||
let feedKind: 'following' | 'discover' | 'profile' | undefined
|
let feedKind: 'following' | 'discover' | 'profile' | undefined
|
||||||
@@ -312,7 +312,7 @@ let PostFeed = ({
|
|||||||
type: 'interstitialProgressGuide',
|
type: 'interstitialProgressGuide',
|
||||||
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
|
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
|
||||||
})
|
})
|
||||||
} else if (sliceIndex === 15 && !trendingDiscoverHidden) {
|
} else if (sliceIndex === 15 && !trendingDisabled) {
|
||||||
arr.push({
|
arr.push({
|
||||||
type: 'interstitialTrending',
|
type: 'interstitialTrending',
|
||||||
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
|
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
|
||||||
@@ -403,7 +403,7 @@ let PostFeed = ({
|
|||||||
feedTab,
|
feedTab,
|
||||||
hasSession,
|
hasSession,
|
||||||
showProgressIntersitial,
|
showProgressIntersitial,
|
||||||
trendingDiscoverHidden,
|
trendingDisabled,
|
||||||
])
|
])
|
||||||
|
|
||||||
// events
|
// events
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ import {Text} from '#/components/Typography'
|
|||||||
|
|
||||||
export function SidebarTrendingTopics() {
|
export function SidebarTrendingTopics() {
|
||||||
const {enabled} = useTrendingConfig()
|
const {enabled} = useTrendingConfig()
|
||||||
const {trendingSidebarHidden} = useTrendingSettings()
|
const {trendingDisabled} = useTrendingSettings()
|
||||||
return !enabled ? null : trendingSidebarHidden ? null : <Inner />
|
return !enabled ? null : trendingDisabled ? null : <Inner />
|
||||||
}
|
}
|
||||||
|
|
||||||
function Inner() {
|
function Inner() {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const trendingPrompt = Prompt.usePromptControl()
|
const trendingPrompt = Prompt.usePromptControl()
|
||||||
const {setTrendingSidebarHidden} = useTrendingSettingsApi()
|
const {setTrendingDisabled} = useTrendingSettingsApi()
|
||||||
const {data: trending, error, isLoading} = useTrendingTopics()
|
const {data: trending, error, isLoading} = useTrendingTopics()
|
||||||
const noTopics = !isLoading && !error && !trending?.topics?.length
|
const noTopics = !isLoading && !error && !trending?.topics?.length
|
||||||
|
|
||||||
@@ -96,10 +96,10 @@ function Inner() {
|
|||||||
control={trendingPrompt}
|
control={trendingPrompt}
|
||||||
title={_(msg`Hide trending topics?`)}
|
title={_(msg`Hide trending topics?`)}
|
||||||
description={_(
|
description={_(
|
||||||
msg`This is a device setting, and will apply to all accounts on this device. You can update this later from your settings.`,
|
msg`This will disable trending topics for all accounts on this device. You can update this later from your settings.`,
|
||||||
)}
|
)}
|
||||||
confirmButtonCta={_(msg`Hide`)}
|
confirmButtonCta={_(msg`Hide`)}
|
||||||
onConfirm={() => setTrendingSidebarHidden(true)}
|
onConfirm={() => setTrendingDisabled(true)}
|
||||||
/>
|
/>
|
||||||
<Divider />
|
<Divider />
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user