1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Partially fixed #113

This commit is contained in:
Zhiyuan Zheng
2021-05-09 21:59:03 +02:00
parent 006edd5c87
commit 0b659913dc
62 changed files with 2308 additions and 703 deletions

View File

@ -0,0 +1,43 @@
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
import { RootState } from '@root/store'
import apiGeneral from '@api/general'
import { Constants } from 'react-native-unimodules'
export const retriveVersionLatest = createAsyncThunk(
'version/latest',
async () => {
const res = await apiGeneral<{ latest: string }>({
method: 'get',
domain: 'tooot.app',
url: 'version.json'
})
return res.body.latest
}
)
export type VersionState = {
update: boolean
}
export const versionInitialState = {
update: false
}
const versionSlice = createSlice({
name: 'version',
initialState: versionInitialState,
reducers: {},
extraReducers: builder => {
builder.addCase(retriveVersionLatest.fulfilled, (state, action) => {
if (action.payload && Constants.manifest.version) {
if (parseInt(action.payload) > parseInt(Constants.manifest.version)) {
state.update = true
}
}
})
}
})
export const getVersionUpdate = (state: RootState) => state.version.update
export default versionSlice.reducer