From 55b573a35a5a920b790c4acfd77ef936341852d2 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 11 Dec 2024 17:55:58 -0600 Subject: [PATCH] Add persisted option to hide trending from sidebar --- src/state/persisted/schema.ts | 1 + src/view/shell/desktop/RightNav.tsx | 117 ++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 32 deletions(-) diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index f70d774630..2554d8041b 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -125,6 +125,7 @@ const schema = z.object({ subtitlesEnabled: z.boolean().optional(), /** @deprecated */ mutedThreads: z.array(z.string()), + hideSidebarTrendingTopics: z.boolean().optional(), }) export type Schema = z.infer diff --git a/src/view/shell/desktop/RightNav.tsx b/src/view/shell/desktop/RightNav.tsx index 052275e204..8f8d5052c3 100644 --- a/src/view/shell/desktop/RightNav.tsx +++ b/src/view/shell/desktop/RightNav.tsx @@ -1,18 +1,23 @@ +import React from 'react' import {View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {FEEDBACK_FORM_URL, HELP_DESK_URL} from '#/lib/constants' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' +import * as persisted from '#/state/persisted' import {useKawaiiMode} from '#/state/preferences/kawaii' import {useSession} from '#/state/session' import {DesktopFeeds} from '#/view/shell/desktop/Feeds' import {DesktopSearch} from '#/view/shell/desktop/Search' import {atoms as a, useGutters, useTheme, web} from '#/alf' +import {Button, ButtonIcon} from '#/components/Button' import {Divider} from '#/components/Divider' +import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' import {Trending2_Stroke2_Corner2_Rounded as Graph} from '#/components/icons/Trending2' import {InlineLinkText} from '#/components/Link' import {ProgressGuideList} from '#/components/ProgressGuide/List' +import * as Prompt from '#/components/Prompt' import * as Trending from '#/components/TrendingTopics' import {Text} from '#/components/Typography' @@ -58,38 +63,7 @@ export function DesktopRightNav({routeName}: {routeName: string}) { )} - {!isSearchScreen && ( - <> - - - - - Trending - - - - - {Trending.TOPICS.slice(0, 8).map(topic => ( - - {({hovered}) => ( - - )} - - ))} - - - - - )} + {!isSearchScreen && } {hasSession && ( @@ -137,3 +111,82 @@ export function DesktopRightNav({routeName}: {routeName: string}) { ) } + +function TrendingTopics() { + const t = useTheme() + const {_} = useLingui() + const trendingPrompt = Prompt.usePromptControl() + + const [showTrending, setShowTrending] = React.useState( + () => !persisted.get('hideSidebarTrendingTopics'), + ) + + const onConfirmHideTrending = React.useCallback(() => { + setShowTrending(false) + persisted.write('hideSidebarTrendingTopics', true) + }, [setShowTrending]) + + // persisted.write('hideSidebarTrendingTopics', undefined) + + React.useEffect(() => { + return persisted.onUpdate('hideSidebarTrendingTopics', value => { + setShowTrending(!value) + }) + }, [setShowTrending]) + + return showTrending ? ( + <> + + + + + Trending + + + + + + {Trending.TOPICS.slice(0, 8).map(topic => ( + + {({hovered}) => ( + + )} + + ))} + + + + + + ) : null +}