mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Start up process of API calls
Prepare for announcement fetching
This commit is contained in:
4
App.tsx
4
App.tsx
@ -7,7 +7,7 @@ import { PersistGate } from 'redux-persist/integration/react'
|
|||||||
import { Index } from '@root/Index'
|
import { Index } from '@root/Index'
|
||||||
import { persistor, store } from '@root/store'
|
import { persistor, store } from '@root/store'
|
||||||
import ThemeManager from '@utils/styles/ThemeManager'
|
import ThemeManager from '@utils/styles/ThemeManager'
|
||||||
import { resetLocal, updateLocal } from '@root/utils/slices/instancesSlice'
|
import { resetLocal } from '@root/utils/slices/instancesSlice'
|
||||||
import client from '@root/api/client'
|
import client from '@root/api/client'
|
||||||
|
|
||||||
const queryClient = new QueryClient()
|
const queryClient = new QueryClient()
|
||||||
@ -66,8 +66,8 @@ const App: React.FC = () => {
|
|||||||
if (res.body.id !== store.getState().instances.local.account.id) {
|
if (res.body.id !== store.getState().instances.local.account.id) {
|
||||||
store.dispatch(resetLocal())
|
store.dispatch(resetLocal())
|
||||||
setLocalCorrupt(true)
|
setLocalCorrupt(true)
|
||||||
setAppLoaded(true)
|
|
||||||
}
|
}
|
||||||
|
setAppLoaded(true)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
store.dispatch(resetLocal())
|
store.dispatch(resetLocal())
|
||||||
|
@ -18,8 +18,11 @@ import { useTheme } from '@utils/styles/ThemeManager'
|
|||||||
import getCurrentTab from '@utils/getCurrentTab'
|
import getCurrentTab from '@utils/getCurrentTab'
|
||||||
import { toast, toastConfig } from '@components/toast'
|
import { toast, toastConfig } from '@components/toast'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { getLocalUrl } from './utils/slices/instancesSlice'
|
import {
|
||||||
|
getLocalUrl,
|
||||||
|
updateLocalAccountPreferences
|
||||||
|
} from '@utils/slices/instancesSlice'
|
||||||
|
|
||||||
enableScreens()
|
enableScreens()
|
||||||
const Tab = createBottomTabNavigator<RootStackParamList>()
|
const Tab = createBottomTabNavigator<RootStackParamList>()
|
||||||
@ -37,6 +40,7 @@ export interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Index: React.FC<Props> = ({ localCorrupt }) => {
|
export const Index: React.FC<Props> = ({ localCorrupt }) => {
|
||||||
|
const dispatch = useDispatch()
|
||||||
const localInstance = useSelector(getLocalUrl)
|
const localInstance = useSelector(getLocalUrl)
|
||||||
const { i18n } = useTranslation()
|
const { i18n } = useTranslation()
|
||||||
const { mode, theme } = useTheme()
|
const { mode, theme } = useTheme()
|
||||||
@ -57,6 +61,12 @@ export const Index: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
return showLocalCorrect
|
return showLocalCorrect
|
||||||
}, [localCorrupt])
|
}, [localCorrupt])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (localInstance) {
|
||||||
|
dispatch(updateLocalAccountPreferences())
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StatusBar barStyle={barStyle[mode]} />
|
<StatusBar barStyle={barStyle[mode]} />
|
||||||
|
@ -13,7 +13,7 @@ import { debounce } from 'lodash'
|
|||||||
import { instanceFetch } from '@utils/fetches/instanceFetch'
|
import { instanceFetch } from '@utils/fetches/instanceFetch'
|
||||||
import * as AuthSession from 'expo-auth-session'
|
import * as AuthSession from 'expo-auth-session'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { updateLocal } from '@utils/slices/instancesSlice'
|
import { loginLocal } from '@utils/slices/instancesSlice'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ const Login: React.FC = () => {
|
|||||||
tokenEndpoint: `https://${instanceDomain}/oauth/token`
|
tokenEndpoint: `https://${instanceDomain}/oauth/token`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
dispatch(updateLocal({ url: instanceDomain, token: accessToken }))
|
dispatch(loginLocal({ url: instanceDomain, token: accessToken }))
|
||||||
navigation.navigate('Screen-Local')
|
navigation.navigate('Screen-Local')
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { updateLocal } from '@utils/slices/instancesSlice'
|
import { resetLocal } from '@utils/slices/instancesSlice'
|
||||||
import MenuButton from '@components/Menu/Button'
|
import MenuButton from '@components/Menu/Button'
|
||||||
import { MenuContainer } from '@components/Menu'
|
import { MenuContainer } from '@components/Menu'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
@ -23,7 +23,7 @@ const Logout: React.FC = () => {
|
|||||||
style: 'destructive' as const,
|
style: 'destructive' as const,
|
||||||
onPress: () => {
|
onPress: () => {
|
||||||
queryClient.clear()
|
queryClient.clear()
|
||||||
dispatch(updateLocal({}))
|
dispatch(resetLocal())
|
||||||
navigation.navigate('Screen-Public', {
|
navigation.navigate('Screen-Public', {
|
||||||
screen: 'Screen-Public-Root',
|
screen: 'Screen-Public-Root',
|
||||||
params: { publicTab: true }
|
params: { publicTab: true }
|
||||||
|
@ -32,19 +32,28 @@ const initialStateLocal = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateLocal = createAsyncThunk(
|
export const updateLocalAccountPreferences = createAsyncThunk(
|
||||||
'instances/updateLocal',
|
'instances/updateLocalAccountPreferences',
|
||||||
|
async () => {
|
||||||
|
const { body: preferences } = await client({
|
||||||
|
method: 'get',
|
||||||
|
instance: 'local',
|
||||||
|
url: `preferences`
|
||||||
|
})
|
||||||
|
|
||||||
|
return preferences as Mastodon.Preferences
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const loginLocal = createAsyncThunk(
|
||||||
|
'instances/loginLocal',
|
||||||
async ({
|
async ({
|
||||||
url,
|
url,
|
||||||
token
|
token
|
||||||
}: {
|
}: {
|
||||||
url?: InstancesState['local']['url']
|
url: InstancesState['local']['url']
|
||||||
token?: InstancesState['local']['token']
|
token: InstancesState['local']['token']
|
||||||
}) => {
|
}) => {
|
||||||
if (!url || !token) {
|
|
||||||
return initialStateLocal
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
body: { id }
|
body: { id }
|
||||||
} = await client({
|
} = await client({
|
||||||
@ -70,7 +79,7 @@ export const updateLocal = createAsyncThunk(
|
|||||||
id,
|
id,
|
||||||
preferences
|
preferences
|
||||||
}
|
}
|
||||||
}
|
} as InstancesState['local']
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -88,9 +97,13 @@ const instancesSlice = createSlice({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
extraReducers: builder => {
|
extraReducers: builder => {
|
||||||
builder.addCase(updateLocal.fulfilled, (state, action) => {
|
builder
|
||||||
state.local = action.payload
|
.addCase(loginLocal.fulfilled, (state, action) => {
|
||||||
})
|
state.local = action.payload
|
||||||
|
})
|
||||||
|
.addCase(updateLocalAccountPreferences.fulfilled, (state, action) => {
|
||||||
|
state.local.account.preferences = action.payload
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user