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