mirror of https://github.com/tooot-app/app
Persist storage working
This commit is contained in:
parent
40266b8ce3
commit
1ad67e67ac
2
App.tsx
2
App.tsx
|
@ -3,7 +3,7 @@ import { QueryCache, ReactQueryCacheProvider, setConsole } from 'react-query'
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
|
|
||||||
import { Index } from 'src/Index'
|
import { Index } from 'src/Index'
|
||||||
import store from 'src/store'
|
import { store } from 'src/store'
|
||||||
|
|
||||||
const queryCache = new QueryCache()
|
const queryCache = new QueryCache()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import store, { RootState } from 'src/store'
|
import { store, RootState } from 'src/store'
|
||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
|
|
||||||
const client = async ({
|
const client = async ({
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { Feather } from '@expo/vector-icons'
|
||||||
|
|
||||||
import client from 'src/api/client'
|
import client from 'src/api/client'
|
||||||
import { getLocalAccountId } from 'src/utils/slices/instancesSlice'
|
import { getLocalAccountId } from 'src/utils/slices/instancesSlice'
|
||||||
import store from 'src/store'
|
import {store} from 'src/store'
|
||||||
|
|
||||||
const fireMutation = async ({
|
const fireMutation = async ({
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
getLocalAccountId,
|
getLocalAccountId,
|
||||||
getLocalUrl
|
getLocalUrl
|
||||||
} from 'src/utils/slices/instancesSlice'
|
} from 'src/utils/slices/instancesSlice'
|
||||||
import store from 'src/store'
|
import {store} from 'src/store'
|
||||||
|
|
||||||
const fireMutation = async ({
|
const fireMutation = async ({
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import store from 'src/store'
|
import { useSelector } from 'react-redux'
|
||||||
import { getLocalRegistered } from 'src/utils/slices/instancesSlice'
|
|
||||||
|
import { RootState } from 'src/store'
|
||||||
|
|
||||||
import Login from './Root/Login'
|
import Login from './Root/Login'
|
||||||
|
|
||||||
const ScreenMeRoot: React.FC = () => {
|
const ScreenMeRoot: React.FC = () => {
|
||||||
const localRegistered = getLocalRegistered(store.getState())
|
const localRegistered = useSelector(
|
||||||
|
(state: RootState) => state.instances.local.url
|
||||||
|
)
|
||||||
|
|
||||||
return <View>{localRegistered ? <></> : <Login />}</View>
|
return <View>{localRegistered ? <></> : <Login />}</View>
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { SafeAreaView } from 'react-native-safe-area-context'
|
||||||
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
|
|
||||||
import store from 'src/store'
|
import { store } from 'src/store'
|
||||||
import PostMain from './Compose/PostMain'
|
import PostMain from './Compose/PostMain'
|
||||||
import client from 'src/api/client'
|
import client from 'src/api/client'
|
||||||
import { getLocalAccountPreferences } from 'src/utils/slices/instancesSlice'
|
import { getLocalAccountPreferences } from 'src/utils/slices/instancesSlice'
|
||||||
|
|
14
src/store.ts
14
src/store.ts
|
@ -1,13 +1,23 @@
|
||||||
import { configureStore } from '@reduxjs/toolkit'
|
import { configureStore } from '@reduxjs/toolkit'
|
||||||
|
import { persistReducer, persistStore } from 'redux-persist'
|
||||||
|
import createSecureStore from 'redux-persist-expo-securestore'
|
||||||
|
|
||||||
import instancesSlice from 'src/utils/slices/instancesSlice'
|
import instancesSlice from 'src/utils/slices/instancesSlice'
|
||||||
|
|
||||||
|
const secureStorage = createSecureStore()
|
||||||
|
|
||||||
|
const instancesPersistConfig = {
|
||||||
|
key: 'instances',
|
||||||
|
storage: secureStorage
|
||||||
|
}
|
||||||
|
|
||||||
const store = configureStore({
|
const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
instances: instancesSlice
|
instances: persistReducer(instancesPersistConfig, instancesSlice)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export default store
|
let persistor = persistStore(store)
|
||||||
|
|
||||||
|
export { store, persistor }
|
||||||
export type RootState = ReturnType<typeof store.getState>
|
export type RootState = ReturnType<typeof store.getState>
|
||||||
|
|
Loading…
Reference in New Issue