about summary refs log tree commit diff
path: root/src/Navigation.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-04-21 12:21:38 -0500
committerGitHub <noreply@github.com>2023-04-21 12:21:38 -0500
commit0f5735b616e3565c1c739e4c8007f4ea4aedba92 (patch)
treeb5a8c63415b815988435f291ecd68b672d915126 /src/Navigation.tsx
parent9f9bd314b34037a02e863df84dd642c2819b3472 (diff)
downloadvoidsky-0f5735b616e3565c1c739e4c8007f4ea4aedba92.tar.zst
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
Diffstat (limited to 'src/Navigation.tsx')
-rw-r--r--src/Navigation.tsx20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/Navigation.tsx b/src/Navigation.tsx
index e868dd3b0..3973b9dfa 100644
--- a/src/Navigation.tsx
+++ b/src/Navigation.tsx
@@ -1,8 +1,10 @@
 import * as React from 'react'
 import {StyleSheet} from 'react-native'
+import {observer} from 'mobx-react-lite'
 import {
   NavigationContainer,
   createNavigationContainerRef,
+  CommonActions,
   StackActions,
 } from '@react-navigation/native'
 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 store = useStores()
   return (
@@ -180,14 +182,14 @@ function MyProfileTabNavigator() {
         // @ts-ignore // TODO: fix this broken type in ProfileScreen
         component={ProfileScreen}
         initialParams={{
-          name: store.me.handle,
+          name: store.me.did,
           hideBackButton: true,
         }}
       />
       {commonScreens(MyProfileTab as typeof HomeTab)}
     </MyProfileTab.Navigator>
   )
-}
+})
 
 /**
  * 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) {
   let path
   if (url.startsWith('/')) {
@@ -326,6 +339,7 @@ const styles = StyleSheet.create({
 export {
   navigate,
   resetToTab,
+  reset,
   handleLink,
   TabsNavigator,
   FlatNavigator,