diff --git a/src/components/TrendingTopics.tsx b/src/components/TrendingTopics.tsx index ec0a6a00c1..f20e1f5268 100644 --- a/src/components/TrendingTopics.tsx +++ b/src/components/TrendingTopics.tsx @@ -1,42 +1,20 @@ import React from 'react' import {View} from 'react-native' -import {msg} from '@lingui/macro' -import {useLingui} from '@lingui/react' import {AtUri} from '@atproto/api' import {hasMutedWord} from '@atproto/api/dist/moderation/mutewords' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {makeProfileLink} from '#/lib/routes/links' +import {feedUriToHref} from '#/lib/strings/url-helpers' +// import {Hashtag_Stroke2_Corner0_Rounded as Hashtag} from '#/components/icons/Hashtag' +// import {CloseQuote_Filled_Stroke2_Corner0_Rounded as Quote} from '#/components/icons/Quote' +// import {UserAvatar} from '#/view/com/util/UserAvatar' +import {usePreferencesQuery} from '#/state/queries/preferences' +import type {TrendingTopic} from '#/state/queries/trending/useTrendingTopics' import {atoms as a, useTheme, ViewStyleProp} from '#/alf' import {Link as InternalLink, LinkProps} from '#/components/Link' import {Text} from '#/components/Typography' -import {feedUriToHref} from '#/lib/strings/url-helpers' -import {makeProfileLink} from '#/lib/routes/links' -import {Hashtag_Stroke2_Corner0_Rounded as Hashtag} from '#/components/icons/Hashtag' -import {MagnifyingGlass_Filled_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass' -import {UserAvatar} from '#/view/com/util/UserAvatar' -import {usePreferencesQuery} from '#/state/queries/preferences' -import type {TrendingTopic} from '#/state/queries/trending/useTrendingTopics' - -export function TopicSmall({topic, style}: {topic: string} & ViewStyleProp) { - const t = useTheme() - return ( - - - {topic} - - - ) -} export function TrendingTopic({ topic: raw, @@ -48,41 +26,76 @@ export function TrendingTopic({ if (!topic) return null - const hasAvi = topic.type === 'feed' || topic.type === 'profile' + const isSmall = size === 'small' + // const hasAvi = topic.type === 'feed' || topic.type === 'profile' + // const aviSize = isSmall ? 16 : 20 + // const iconSize = isSmall ? 16 : 20 return ( - + {/* + {topic.type === 'tag' ? ( - + ) : topic.type === 'topic' ? ( - + ) : topic.type === 'feed' ? ( - + ) : ( - + )} + */} {topic.name} @@ -113,43 +126,6 @@ export function TrendingTopicLink({ ) } -export function Link({ - topic, - children, - style, - ...rest -}: { - topic: string -} & Omit) { - const {_} = useLingui() - return ( - - {children} - - ) -} - -// temp -export const TOPICS = [ - '#atproto', - 'South Korea', - 'Wired', - 'Basket Weaving', - 'Coup', - 'Chappel Roan', - 'the juice', - 'Superman', - '#FCF', - 'Open Web', -] - type ParsedTrendingTopic = | { type: 'topic' | 'tag' @@ -180,10 +156,13 @@ export function useTopic(raw: TrendingTopic): ParsedTrendingTopic | undefined { return React.useMemo(() => { const {topic: name, link: uri} = raw - if (hasMutedWord({ - mutedWords, - text: name - })) return + if ( + hasMutedWord({ + mutedWords, + text: name, + }) + ) + return if (!uri.startsWith('at://')) { if (uri.startsWith('/search')) { @@ -226,5 +205,5 @@ export function useTopic(raw: TrendingTopic): ParsedTrendingTopic | undefined { } } } - }, [raw, mutedWords]) + }, [_, raw, mutedWords]) } diff --git a/src/view/shell/desktop/RightNav.tsx b/src/view/shell/desktop/RightNav.tsx index 45e0752693..1732245e38 100644 --- a/src/view/shell/desktop/RightNav.tsx +++ b/src/view/shell/desktop/RightNav.tsx @@ -5,22 +5,14 @@ import {useLingui} from '@lingui/react' import {FEEDBACK_FORM_URL, HELP_DESK_URL} from '#/lib/constants' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {useKawaiiMode} from '#/state/preferences/kawaii' -import { - useTrendingSettings, - useTrendingSettingsApi, -} from '#/state/preferences/trending' import {useSession} from '#/state/session' import {DesktopFeeds} from '#/view/shell/desktop/Feeds' import {DesktopSearch} from '#/view/shell/desktop/Search' +import {SidebarTrendingTopics} from '#/view/shell/desktop/SidebarTrendingTopics' 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' export function DesktopRightNav({routeName}: {routeName: string}) { @@ -65,7 +57,7 @@ export function DesktopRightNav({routeName}: {routeName: string}) { )} - {!isSearchScreen && } + {!isSearchScreen && } {hasSession && ( @@ -113,68 +105,3 @@ export function DesktopRightNav({routeName}: {routeName: string}) { ) } - -function TrendingTopics() { - const t = useTheme() - const {_} = useLingui() - const trendingPrompt = Prompt.usePromptControl() - - const {trendingSidebarHidden} = useTrendingSettings() - const {setTrendingSidebarHidden} = useTrendingSettingsApi() - - return trendingSidebarHidden ? null : ( - <> - - - - - Trending - - - - - - {Trending.TOPICS.slice(0, 8).map(topic => ( - - {({hovered}) => ( - - )} - - ))} - - - setTrendingSidebarHidden(true)} - /> - - - ) -} diff --git a/src/view/shell/desktop/SidebarTrendingTopics.tsx b/src/view/shell/desktop/SidebarTrendingTopics.tsx new file mode 100644 index 0000000000..c62d0c8898 --- /dev/null +++ b/src/view/shell/desktop/SidebarTrendingTopics.tsx @@ -0,0 +1,92 @@ +import {View} from 'react-native' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' + +import { + useTrendingSettings, + useTrendingSettingsApi, +} from '#/state/preferences/trending' +import {useTrendingTopics} from '#/state/queries/trending/useTrendingTopics' +import {atoms as a, useTheme} 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 * as Prompt from '#/components/Prompt' +import {TrendingTopic, TrendingTopicLink} from '#/components/TrendingTopics' +import {Text} from '#/components/Typography' + +export function SidebarTrendingTopics() { + const {trendingSidebarHidden} = useTrendingSettings() + return trendingSidebarHidden ? null : +} + +function Inner() { + const t = useTheme() + const {_} = useLingui() + const trendingPrompt = Prompt.usePromptControl() + const {setTrendingSidebarHidden} = useTrendingSettingsApi() + + const {data: topics, error, isLoading} = useTrendingTopics() + + return ( + <> + + + + + Trending + + + + + + {isLoading ? null : error || !topics ? null : ( + <> + {topics.map(topic => ( + + {({hovered}) => ( + + )} + + ))} + + )} + + + setTrendingSidebarHidden(true)} + /> + + + ) +}