Skip to content

Commit

Permalink
Handle hide/show of sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Dec 18, 2024
1 parent dd6509c commit e9fce7a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/view/shell/desktop/RightNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import {View} from 'react-native'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/core'

import {FEEDBACK_FORM_URL, HELP_DESK_URL} from '#/lib/constants'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
Expand All @@ -15,13 +17,33 @@ import {InlineLinkText} from '#/components/Link'
import {ProgressGuideList} from '#/components/ProgressGuide/List'
import {Text} from '#/components/Typography'

function useWebQueryParams() {
const navigation = useNavigation()
const [params, setParams] = React.useState<Record<string, string>>({})

React.useEffect(() => {
return navigation.addListener('state', e => {
try {
const {state} = e.data
const lastRoute = state.routes[state.routes.length - 1]
const {params} = lastRoute
setParams(params)
} catch (e) {}
})
}, [navigation, setParams])

return params
}

export function DesktopRightNav({routeName}: {routeName: string}) {
const t = useTheme()
const {_} = useLingui()
const {hasSession, currentAccount} = useSession()
const kawaii = useKawaiiMode()
const gutters = useGutters(['base', 0, 'base', 'wide'])
const isSearchScreen = routeName === 'Search'
const {q: searchQuery} = useWebQueryParams()
const showTrending = !isSearchScreen || (isSearchScreen && !!searchQuery)

const {isTablet} = useWebMediaQueries()
if (isTablet) {
Expand Down Expand Up @@ -57,7 +79,7 @@ export function DesktopRightNav({routeName}: {routeName: string}) {
</>
)}

{!isSearchScreen && <SidebarTrendingTopics />}
{showTrending && <SidebarTrendingTopics />}

<Text style={[a.leading_snug, t.atoms.text_contrast_low]}>
{hasSession && (
Expand Down

0 comments on commit e9fce7a

Please sign in to comment.