Fix profile link 404s on session change & handle change [APP 523] (#507)

* Use DID to link to the user profile to gracefully handle... handle changes

* Reset nav state on active profile change
zio/stable
Paul Frazee 2023-04-21 12:21:38 -05:00 committed by GitHub
parent 9f9bd314b3
commit 0f5735b616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -1,8 +1,10 @@
import * as React from 'react' import * as React from 'react'
import {StyleSheet} from 'react-native' import {StyleSheet} from 'react-native'
import {observer} from 'mobx-react-lite'
import { import {
NavigationContainer, NavigationContainer,
createNavigationContainerRef, createNavigationContainerRef,
CommonActions,
StackActions, StackActions,
} from '@react-navigation/native' } from '@react-navigation/native'
import {createNativeStackNavigator} from '@react-navigation/native-stack' import {createNativeStackNavigator} from '@react-navigation/native-stack'
@ -163,7 +165,7 @@ function NotificationsTabNavigator() {
) )
} }
function MyProfileTabNavigator() { const MyProfileTabNavigator = observer(() => {
const contentStyle = useColorSchemeStyle(styles.bgLight, styles.bgDark) const contentStyle = useColorSchemeStyle(styles.bgLight, styles.bgDark)
const store = useStores() const store = useStores()
return ( return (
@ -180,14 +182,14 @@ function MyProfileTabNavigator() {
// @ts-ignore // TODO: fix this broken type in ProfileScreen // @ts-ignore // TODO: fix this broken type in ProfileScreen
component={ProfileScreen} component={ProfileScreen}
initialParams={{ initialParams={{
name: store.me.handle, name: store.me.did,
hideBackButton: true, hideBackButton: true,
}} }}
/> />
{commonScreens(MyProfileTab as typeof HomeTab)} {commonScreens(MyProfileTab as typeof HomeTab)}
</MyProfileTab.Navigator> </MyProfileTab.Navigator>
) )
} })
/** /**
* The FlatNavigator is used by Web to represent the routes * The FlatNavigator is used by Web to represent the routes
@ -281,6 +283,17 @@ function resetToTab(tabName: 'HomeTab' | 'SearchTab' | 'NotificationsTab') {
} }
} }
function reset() {
if (navigationRef.isReady()) {
navigationRef.dispatch(
CommonActions.reset({
index: 0,
routes: [{name: isNative ? 'HomeTab' : 'Home'}],
}),
)
}
}
function handleLink(url: string) { function handleLink(url: string) {
let path let path
if (url.startsWith('/')) { if (url.startsWith('/')) {
@ -326,6 +339,7 @@ const styles = StyleSheet.create({
export { export {
navigate, navigate,
resetToTab, resetToTab,
reset,
handleLink, handleLink,
TabsNavigator, TabsNavigator,
FlatNavigator, FlatNavigator,

View File

@ -21,6 +21,7 @@ import {PreferencesModel} from './ui/preferences'
import {resetToTab} from '../../Navigation' import {resetToTab} from '../../Navigation'
import {ImageSizesCache} from './cache/image-sizes' import {ImageSizesCache} from './cache/image-sizes'
import {MutedThreads} from './muted-threads' import {MutedThreads} from './muted-threads'
import {reset as resetNavigation} from '../../Navigation'
export const appInfo = z.object({ export const appInfo = z.object({
build: z.string(), build: z.string(),
@ -123,6 +124,7 @@ export class RootStoreModel {
this.agent = agent this.agent = agent
this.me.clear() this.me.clear()
await this.me.load() await this.me.load()
resetNavigation()
} }
/** /**