mirror of
https://github.com/tooot-app/app
synced 2025-02-13 18:30:42 +01:00
Keep previous tab for next load
This commit is contained in:
parent
313b7af4a8
commit
3303864394
@ -9,6 +9,7 @@ import ScreenAnnouncements from '@screens/Announcements'
|
|||||||
import ScreenCompose from '@screens/Compose'
|
import ScreenCompose from '@screens/Compose'
|
||||||
import ScreenImagesViewer from '@screens/ImagesViewer'
|
import ScreenImagesViewer from '@screens/ImagesViewer'
|
||||||
import ScreenTabs from '@screens/Tabs'
|
import ScreenTabs from '@screens/Tabs'
|
||||||
|
import { updatePreviousTab } from '@utils/slices/contextsSlice'
|
||||||
import {
|
import {
|
||||||
getLocalActiveIndex,
|
getLocalActiveIndex,
|
||||||
updateLocalAccountPreferences
|
updateLocalAccountPreferences
|
||||||
@ -36,7 +37,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
const { t } = useTranslation('common')
|
const { t } = useTranslation('common')
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const localActiveIndex = useSelector(getLocalActiveIndex)
|
const localActiveIndex = useSelector(getLocalActiveIndex)
|
||||||
const { mode, theme } = useTheme()
|
const { mode } = useTheme()
|
||||||
enum barStyle {
|
enum barStyle {
|
||||||
light = 'dark-content',
|
light = 'dark-content',
|
||||||
dark = 'light-content'
|
dark = 'light-content'
|
||||||
@ -70,15 +71,20 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
|
|
||||||
// On launch display login credentials corrupt information
|
// On launch display login credentials corrupt information
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const showLocalCorrect = localCorrupt
|
const showLocalCorrect = () => {
|
||||||
? toast({
|
if (localCorrupt) {
|
||||||
|
toast({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: t('index.localCorrupt'),
|
message: t('index.localCorrupt'),
|
||||||
description: localCorrupt.length ? localCorrupt : undefined,
|
description: localCorrupt.length ? localCorrupt : undefined,
|
||||||
autoHide: false
|
autoHide: false
|
||||||
})
|
})
|
||||||
: undefined
|
navigationRef.current?.navigate('Screen-Tabs', {
|
||||||
return showLocalCorrect
|
screen: 'Tab-Me'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return showLocalCorrect()
|
||||||
}, [localCorrupt])
|
}, [localCorrupt])
|
||||||
|
|
||||||
// On launch check if there is any unread announcements
|
// On launch check if there is any unread announcements
|
||||||
@ -116,6 +122,12 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
const previousRouteName = routeNameRef.current
|
const previousRouteName = routeNameRef.current
|
||||||
const currentRouteName = navigationRef.current?.getCurrentRoute()?.name
|
const currentRouteName = navigationRef.current?.getCurrentRoute()?.name
|
||||||
|
|
||||||
|
const matchTabName = currentRouteName?.match(/(Tab-.*)-Root/)
|
||||||
|
if (matchTabName) {
|
||||||
|
//@ts-ignore
|
||||||
|
dispatch(updatePreviousTab(matchTabName[1]))
|
||||||
|
}
|
||||||
|
|
||||||
if (previousRouteName !== currentRouteName) {
|
if (previousRouteName !== currentRouteName) {
|
||||||
Analytics.setCurrentScreen(currentRouteName)
|
Analytics.setCurrentScreen(currentRouteName)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
import { NavigatorScreenParams } from '@react-navigation/native'
|
import { NavigatorScreenParams } from '@react-navigation/native'
|
||||||
import { StackScreenProps } from '@react-navigation/stack'
|
import { StackScreenProps } from '@react-navigation/stack'
|
||||||
import { useTimelineQuery } from '@utils/queryHooks/timeline'
|
import { useTimelineQuery } from '@utils/queryHooks/timeline'
|
||||||
|
import { getPreviousTab } from '@utils/slices/contextsSlice'
|
||||||
import {
|
import {
|
||||||
getLocalAccount,
|
getLocalAccount,
|
||||||
getLocalActiveIndex,
|
getLocalActiveIndex,
|
||||||
@ -41,7 +42,7 @@ const Tab = createBottomTabNavigator<Nav.ScreenTabsStackParamList>()
|
|||||||
|
|
||||||
const ScreenTabs = React.memo(
|
const ScreenTabs = React.memo(
|
||||||
({ navigation }: ScreenTabsProp) => {
|
({ navigation }: ScreenTabsProp) => {
|
||||||
const { theme } = useTheme()
|
const { mode, theme } = useTheme()
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const localActiveIndex = useSelector(getLocalActiveIndex)
|
const localActiveIndex = useSelector(getLocalActiveIndex)
|
||||||
const localAccount = useSelector(
|
const localAccount = useSelector(
|
||||||
@ -103,7 +104,7 @@ const ScreenTabs = React.memo(
|
|||||||
showLabel: false,
|
showLabel: false,
|
||||||
...(Platform.OS === 'android' && { keyboardHidesTabBar: true })
|
...(Platform.OS === 'android' && { keyboardHidesTabBar: true })
|
||||||
}),
|
}),
|
||||||
[theme, localActiveIndex]
|
[mode, localActiveIndex]
|
||||||
)
|
)
|
||||||
const localListeners = useCallback(
|
const localListeners = useCallback(
|
||||||
() => ({
|
() => ({
|
||||||
@ -167,7 +168,11 @@ const ScreenTabs = React.memo(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Tab.Navigator
|
<Tab.Navigator
|
||||||
initialRouteName={localActiveIndex !== null ? 'Tab-Local' : 'Tab-Me'}
|
initialRouteName={
|
||||||
|
localActiveIndex !== null
|
||||||
|
? useSelector(getPreviousTab, () => true)
|
||||||
|
: 'Tab-Me'
|
||||||
|
}
|
||||||
screenOptions={screenOptions}
|
screenOptions={screenOptions}
|
||||||
tabBarOptions={tabBarOptions}
|
tabBarOptions={tabBarOptions}
|
||||||
>
|
>
|
||||||
|
@ -70,7 +70,7 @@ const queryFunction = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
case 'Account_Default':
|
case 'Account_Default':
|
||||||
if (pageParam && pageParam.pointer === 'max_id') {
|
if (pageParam && pageParam.hasOwnProperty('max_id')) {
|
||||||
return client<Mastodon.Status[]>({
|
return client<Mastodon.Status[]>({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
instance: 'local',
|
instance: 'local',
|
||||||
@ -101,7 +101,7 @@ const queryFunction = ({
|
|||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
body: uniqBy([...res1.body, ...res2.body], 'id'),
|
body: uniqBy([...res1.body, ...res2.body], 'id'),
|
||||||
...(res2.links.next && { links: { max_id: res2.links.next } }),
|
...(res2.links.next && { links: { next: res2.links.next } }),
|
||||||
pinned
|
pinned
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -16,6 +16,7 @@ export type ContextsState = {
|
|||||||
current: number
|
current: number
|
||||||
hidden: boolean
|
hidden: boolean
|
||||||
}
|
}
|
||||||
|
previousTab: 'Tab-Local' | 'Tab-Public' | 'Tab-Notifications' | 'Tab-Me'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const contextsInitialState = {
|
export const contextsInitialState = {
|
||||||
@ -30,7 +31,8 @@ export const contextsInitialState = {
|
|||||||
context: 1,
|
context: 1,
|
||||||
current: 0,
|
current: 0,
|
||||||
hidden: false
|
hidden: false
|
||||||
}
|
},
|
||||||
|
previousTab: 'Tab-Local'
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextsSlice = createSlice({
|
const contextsSlice = createSlice({
|
||||||
@ -53,15 +55,23 @@ const contextsSlice = createSlice({
|
|||||||
) {
|
) {
|
||||||
state.publicRemoteNotice.hidden = true
|
state.publicRemoteNotice.hidden = true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
updatePreviousTab: (
|
||||||
|
state,
|
||||||
|
action: PayloadAction<ContextsState['previousTab']>
|
||||||
|
) => {
|
||||||
|
state.previousTab = action.payload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getPublicRemoteNotice = (state: RootState) =>
|
export const getPublicRemoteNotice = (state: RootState) =>
|
||||||
state.contexts.publicRemoteNotice
|
state.contexts.publicRemoteNotice
|
||||||
|
export const getPreviousTab = (state: RootState) => state.contexts.previousTab
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
updateStoreReview,
|
updateStoreReview,
|
||||||
updatePublicRemoteNotice
|
updatePublicRemoteNotice,
|
||||||
|
updatePreviousTab
|
||||||
} = contextsSlice.actions
|
} = contextsSlice.actions
|
||||||
export default contextsSlice.reducer
|
export default contextsSlice.reducer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user