1+ import { Routes } from '@/src/common/constants/routes' ;
12import { useCurrentIdentity } from '@/src/common/lib/polycentric-hooks' ;
3+ import { router } from 'expo-router' ;
24import {
35 createContext ,
6+ useCallback ,
47 useContext ,
5- useEffect ,
68 useMemo ,
7- useState ,
89 type ReactNode ,
910} from 'react' ;
1011
11- type ActiveFeed = 'posts' | 'likes ' ;
12+ export type ActiveFeed = 'posts' | 'verifications ' ;
1213
1314interface ProfileContextValue {
1415 identityKey : string | null ;
@@ -25,23 +26,36 @@ const ProfileContext = createContext<ProfileContextValue | null>(null);
2526export function ProfileProvider ( {
2627 identityKey,
2728 alias = null ,
29+ activeFeed = 'posts' ,
2830 children,
2931} : {
3032 identityKey : string | null ;
3133 alias ?: string | null ;
34+ // Which tab's route rendered this profile.
35+ activeFeed ?: ActiveFeed ;
3236 children : ReactNode ;
3337} ) {
3438 const { identity : selfIdentity } = useCurrentIdentity ( ) ;
3539 const isSelf = ! ! identityKey && selfIdentity ?. identityKey === identityKey ;
3640
37- const [ activeFeed , setActiveFeed ] = useState < ActiveFeed > ( 'posts' ) ;
38- useEffect ( ( ) => {
39- if ( ! isSelf ) setActiveFeed ( 'posts' ) ;
40- } , [ isSelf ] ) ;
41+ // Tabs are routes; switching replaces the URL, keeping the alias when
42+ // the profile was reached via one.
43+ const setActiveFeed = useCallback (
44+ ( tab : ActiveFeed ) => {
45+ const profileId = alias ?? identityKey ;
46+ if ( tab === activeFeed || ! profileId ) return ;
47+ router . replace (
48+ tab === 'verifications'
49+ ? Routes . tabs . profileVerifications ( profileId )
50+ : Routes . tabs . profile ( profileId ) ,
51+ ) ;
52+ } ,
53+ [ activeFeed , alias , identityKey ] ,
54+ ) ;
4155
4256 const value = useMemo < ProfileContextValue > (
4357 ( ) => ( { identityKey, isSelf, activeFeed, setActiveFeed, alias } ) ,
44- [ identityKey , isSelf , activeFeed , alias ] ,
58+ [ identityKey , isSelf , activeFeed , setActiveFeed , alias ] ,
4559 ) ;
4660
4761 return (
0 commit comments