mirror of
https://github.com/tooot-app/app
synced 2025-04-19 04:37:24 +02:00
Fix public page switching timeline not updating nav params
This commit is contained in:
parent
34c0bbf4bb
commit
3883c0307a
@ -1,8 +1,7 @@
|
|||||||
import { HeaderRight } from '@components/Header'
|
import { HeaderRight } from '@components/Header'
|
||||||
import Timeline from '@components/Timeline'
|
import Timeline from '@components/Timeline'
|
||||||
import SegmentedControl from '@react-native-community/segmented-control'
|
import SegmentedControl from '@react-native-community/segmented-control'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { NativeStackScreenProps } from '@react-navigation/native-stack'
|
||||||
import { NativeStackNavigationProp, NativeStackScreenProps } from '@react-navigation/native-stack'
|
|
||||||
import { TabPublicStackParamList } from '@utils/navigation/navigators'
|
import { TabPublicStackParamList } from '@utils/navigation/navigators'
|
||||||
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
||||||
import { getGlobalStorage, setGlobalStorage } from '@utils/storage/actions'
|
import { getGlobalStorage, setGlobalStorage } from '@utils/storage/actions'
|
||||||
@ -14,12 +13,7 @@ import { Dimensions } from 'react-native'
|
|||||||
import { SceneMap, TabView } from 'react-native-tab-view'
|
import { SceneMap, TabView } from 'react-native-tab-view'
|
||||||
|
|
||||||
const Route = ({ route: { key: page } }: { route: any }) => {
|
const Route = ({ route: { key: page } }: { route: any }) => {
|
||||||
const navigation =
|
|
||||||
useNavigation<NativeStackNavigationProp<TabPublicStackParamList, 'Tab-Public-Root'>>()
|
|
||||||
const queryKey: QueryKeyTimeline = ['Timeline', { page }]
|
const queryKey: QueryKeyTimeline = ['Timeline', { page }]
|
||||||
useEffect(() => {
|
|
||||||
navigation.setParams({ queryKey })
|
|
||||||
}, [])
|
|
||||||
return <Timeline queryKey={queryKey} disableRefresh={page === 'Trending'} />
|
return <Timeline queryKey={queryKey} disableRefresh={page === 'Trending'} />
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,12 +29,11 @@ const Root: React.FC<NativeStackScreenProps<TabPublicStackParamList, 'Tab-Public
|
|||||||
const { mode } = useTheme()
|
const { mode } = useTheme()
|
||||||
const { t } = useTranslation('screenTabs')
|
const { t } = useTranslation('screenTabs')
|
||||||
|
|
||||||
const previousSegment = getGlobalStorage.string('app.prev_public_segment')
|
|
||||||
const segments: StorageGlobal['app.prev_public_segment'][] = ['Local', 'LocalPublic', 'Trending']
|
const segments: StorageGlobal['app.prev_public_segment'][] = ['Local', 'LocalPublic', 'Trending']
|
||||||
const [segment, setSegment] = useState<number>(
|
const [segment, setSegment] = useState<number>(
|
||||||
Math.max(
|
Math.max(
|
||||||
0,
|
0,
|
||||||
segments.findIndex(segment => segment === previousSegment)
|
segments.findIndex(segment => segment === getGlobalStorage.string('app.prev_public_segment'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
const [routes] = useState([
|
const [routes] = useState([
|
||||||
@ -48,6 +41,10 @@ const Root: React.FC<NativeStackScreenProps<TabPublicStackParamList, 'Tab-Public
|
|||||||
{ key: 'LocalPublic', title: t('tabs.public.segments.federated') },
|
{ key: 'LocalPublic', title: t('tabs.public.segments.federated') },
|
||||||
{ key: 'Trending', title: t('tabs.public.segments.trending') }
|
{ key: 'Trending', title: t('tabs.public.segments.trending') }
|
||||||
])
|
])
|
||||||
|
useEffect(() => {
|
||||||
|
const page = segments[segment]
|
||||||
|
page && navigation.setParams({ queryKey: ['Timeline', { page }] })
|
||||||
|
}, [segment])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
navigation.setOptions({
|
navigation.setOptions({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user