An ATproto social media client -- with an independent Appview.

Fix linking to specific search results (#8520)

* fix linking to bsky.app/search?q=xyz

* add name to comment

* skip if notfound

authored by samuel.fm and committed by

GitHub 06ebd296 3304cd04

+45 -7
+36 -7
src/components/Link.tsx
··· 9 9 import {BSKY_DOWNLOAD_URL} from '#/lib/constants' 10 10 import {useNavigationDeduped} from '#/lib/hooks/useNavigationDeduped' 11 11 import {useOpenLink} from '#/lib/hooks/useOpenLink' 12 - import {type AllNavigatorParams} from '#/lib/routes/types' 12 + import {type AllNavigatorParams, type RouteParams} from '#/lib/routes/types' 13 13 import {shareUrl} from '#/lib/sharing' 14 14 import { 15 15 convertBskyAppUrlIfNeeded, ··· 155 155 } else { 156 156 closeModal() // close any active modals 157 157 158 + const [screen, params] = router.matchPath(href) as [ 159 + screen: keyof AllNavigatorParams, 160 + params?: RouteParams, 161 + ] 162 + 163 + // does not apply to web's flat navigator 164 + if (isNative && screen !== 'NotFound') { 165 + const state = navigation.getState() 166 + // if screen is not in the current navigator, it means it's 167 + // most likely a tab screen 168 + if (!state.routeNames.includes(screen)) { 169 + const parent = navigation.getParent() 170 + if ( 171 + parent && 172 + parent.getState().routeNames.includes(`${screen}Tab`) 173 + ) { 174 + // yep, it's a tab screen. i.e. SearchTab 175 + // thus we need to navigate to the child screen 176 + // via the parent navigator 177 + // see https://reactnavigation.org/docs/upgrading-from-6.x/#changes-to-the-navigate-action 178 + // TODO: can we support the other kinds of actions? push/replace -sfn 179 + 180 + // @ts-expect-error include does not narrow the type unfortunately 181 + parent.navigate(`${screen}Tab`, {screen, params}) 182 + return 183 + } else { 184 + // will probably fail, but let's try anyway 185 + } 186 + } 187 + } 188 + 158 189 if (action === 'push') { 159 - navigation.dispatch(StackActions.push(...router.matchPath(href))) 190 + navigation.dispatch(StackActions.push(screen, params)) 160 191 } else if (action === 'replace') { 161 - navigation.dispatch( 162 - StackActions.replace(...router.matchPath(href)), 163 - ) 192 + navigation.dispatch(StackActions.replace(screen, params)) 164 193 } else if (action === 'navigate') { 165 - // @ts-ignore 166 - navigation.navigate(...router.matchPath(href)) 194 + // @ts-expect-error not typed 195 + navigation.navigate(screen, params) 167 196 } else { 168 197 throw Error('Unsupported navigator action.') 169 198 }
+4
src/lib/hooks/useNavigationDeduped.ts
··· 14 14 | 'dispatch' 15 15 | 'goBack' 16 16 | 'getState' 17 + | 'getParent' 17 18 > 18 19 19 20 export function useNavigationDeduped() { ··· 45 46 }, 46 47 getState: () => { 47 48 return navigation.getState() 49 + }, 50 + getParent: (...args: Parameters<typeof navigation.getParent>) => { 51 + return navigation.getParent(...args) 48 52 }, 49 53 }), 50 54 [dedupe, navigation],
+5
src/lib/strings/url-helpers.ts
··· 193 193 return startUriToStarterPackUri(urlp.pathname) 194 194 } 195 195 196 + // special-case search links 197 + if (urlp.pathname === '/search') { 198 + return `/search?q=${urlp.searchParams.get('q')}` 199 + } 200 + 196 201 return urlp.pathname 197 202 } catch (e) { 198 203 console.error('Unexpected error in convertBskyAppUrlIfNeeded()', e)