mirror of
https://github.com/tooot-app/app
synced 2024-12-28 10:20:17 +01:00
Move app startup check to App.tsx
This commit is contained in:
parent
a1a959995e
commit
2bd9e6be2f
15
App.tsx
15
App.tsx
@ -7,6 +7,7 @@ import { PersistGate } from 'redux-persist/integration/react'
|
||||
import { Index } from '@root/Index'
|
||||
import { persistor, store } from '@root/store'
|
||||
import ThemeManager from '@utils/styles/ThemeManager'
|
||||
import { resetLocal, updateLocal } from '@root/utils/slices/instancesSlice'
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
@ -49,7 +50,19 @@ const App: React.FC = () => {
|
||||
<Provider store={store}>
|
||||
<PersistGate
|
||||
persistor={persistor}
|
||||
onBeforeLift={() => setAppLoaded(true)}
|
||||
onBeforeLift={async () => {
|
||||
const localUrl = store.getState().instances.local.url
|
||||
const localToken = store.getState().instances.local.token
|
||||
if (localUrl && localToken) {
|
||||
const dispatchStatus = await store.dispatch(
|
||||
updateLocal({ url: localUrl, token: localToken })
|
||||
)
|
||||
if (dispatchStatus.type.includes('/rejected')) {
|
||||
store.dispatch(resetLocal())
|
||||
}
|
||||
}
|
||||
setAppLoaded(true)
|
||||
}}
|
||||
>
|
||||
{bootstrapped => {
|
||||
if (bootstrapped) {
|
||||
|
26
src/@types/mastodon.d.ts
vendored
26
src/@types/mastodon.d.ts
vendored
@ -31,6 +31,32 @@ declare namespace Mastodon {
|
||||
source: Source
|
||||
}
|
||||
|
||||
type Announcement = {
|
||||
// Base
|
||||
id: string
|
||||
text: string
|
||||
published: boolean
|
||||
all_day: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
read: boolean
|
||||
reactions: AnnouncementReaction[]
|
||||
|
||||
// Others
|
||||
scheduled_at?: string
|
||||
starts_at?: string
|
||||
ends_at?: string
|
||||
}
|
||||
|
||||
type AnnouncementReaction = {
|
||||
// Base
|
||||
name: string
|
||||
count: number
|
||||
me: boolean
|
||||
url: string
|
||||
static_url: string
|
||||
}
|
||||
|
||||
type Application = {
|
||||
// Base
|
||||
name: string
|
||||
|
@ -3,7 +3,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
|
||||
import { NavigationContainer } from '@react-navigation/native'
|
||||
import { enableScreens } from 'react-native-screens'
|
||||
|
||||
import React, { useEffect } from 'react'
|
||||
import React from 'react'
|
||||
import { StatusBar } from 'react-native'
|
||||
import Toast from 'react-native-toast-message'
|
||||
import { Feather } from '@expo/vector-icons'
|
||||
@ -18,12 +18,8 @@ import { useTheme } from '@utils/styles/ThemeManager'
|
||||
import getCurrentTab from '@utils/getCurrentTab'
|
||||
import { toastConfig } from '@components/toast'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
import {
|
||||
getLocalToken,
|
||||
getLocalUrl,
|
||||
updateLocal
|
||||
} from './utils/slices/instancesSlice'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { getLocalUrl } from './utils/slices/instancesSlice'
|
||||
|
||||
enableScreens()
|
||||
const Tab = createBottomTabNavigator<RootStackParamList>()
|
||||
@ -37,9 +33,7 @@ export type RootStackParamList = {
|
||||
}
|
||||
|
||||
export const Index: React.FC = () => {
|
||||
const dispatch = useDispatch()
|
||||
const localInstance = useSelector(getLocalUrl)
|
||||
const localToken = useSelector(getLocalToken)
|
||||
const { i18n } = useTranslation()
|
||||
const { mode, theme } = useTheme()
|
||||
enum barStyle {
|
||||
@ -47,12 +41,6 @@ export const Index: React.FC = () => {
|
||||
dark = 'light-content'
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (localInstance && localToken) {
|
||||
dispatch(updateLocal({ url: localInstance, token: localToken }))
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<StatusBar barStyle={barStyle[mode]} />
|
||||
|
@ -82,7 +82,11 @@ const instancesSlice = createSlice({
|
||||
url: 'm.cmx.im'
|
||||
}
|
||||
} as InstancesState,
|
||||
reducers: {},
|
||||
reducers: {
|
||||
resetLocal: state => {
|
||||
state.local = initialStateLocal
|
||||
}
|
||||
},
|
||||
extraReducers: builder => {
|
||||
builder.addCase(updateLocal.fulfilled, (state, action) => {
|
||||
state.local = action.payload
|
||||
@ -98,4 +102,6 @@ export const getLocalAccountId = (state: RootState) =>
|
||||
export const getLocalAccountPreferences = (state: RootState) =>
|
||||
state.instances.local.account.preferences
|
||||
|
||||
export const { resetLocal } = instancesSlice.actions
|
||||
|
||||
export default instancesSlice.reducer
|
||||
|
Loading…
Reference in New Issue
Block a user