Persist storage working

This commit is contained in:
Zhiyuan Zheng 2020-11-21 13:32:29 +01:00
parent 40266b8ce3
commit 1ad67e67ac
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
7 changed files with 23 additions and 10 deletions

View File

@ -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()

View File

@ -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 ({

View File

@ -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,

View File

@ -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,

View File

@ -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>
} }

View File

@ -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'

View File

@ -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>