mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Added store review
This commit is contained in:
64
src/utils/slices/contextsSlice.ts
Normal file
64
src/utils/slices/contextsSlice.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { RootState } from '@root/store'
|
||||
import * as StoreReview from 'expo-store-review'
|
||||
|
||||
export const supportedLngs = ['zh-Hans', 'en']
|
||||
|
||||
export type ContextsState = {
|
||||
storeReview: {
|
||||
context: Readonly<number>
|
||||
current: number
|
||||
shown: boolean
|
||||
}
|
||||
publicRemoteNotice: {
|
||||
context: Readonly<number>
|
||||
current: number
|
||||
hidden: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export const contextsInitialState = {
|
||||
// After 3 successful postings
|
||||
storeReview: {
|
||||
context: 3,
|
||||
current: 0,
|
||||
shown: false
|
||||
},
|
||||
// After public remote settings has been used once
|
||||
publicRemoteNotice: {
|
||||
context: 1,
|
||||
current: 0,
|
||||
hidden: false
|
||||
}
|
||||
}
|
||||
|
||||
const contextsSlice = createSlice({
|
||||
name: 'settings',
|
||||
initialState: contextsInitialState as ContextsState,
|
||||
reducers: {
|
||||
updateStoreReview: (state, action: PayloadAction<1>) => {
|
||||
state.storeReview.current = state.storeReview.current + action.payload
|
||||
if (state.storeReview.current === state.storeReview.context) {
|
||||
StoreReview.isAvailableAsync().then(() => StoreReview.requestReview())
|
||||
}
|
||||
},
|
||||
updatePublicRemoteNotice: (state, action: PayloadAction<1>) => {
|
||||
state.publicRemoteNotice.current =
|
||||
state.publicRemoteNotice.current + action.payload
|
||||
if (
|
||||
state.publicRemoteNotice.current === state.publicRemoteNotice.context
|
||||
) {
|
||||
state.publicRemoteNotice.hidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const getPublicRemoteNotice = (state: RootState) =>
|
||||
state.contexts.publicRemoteNotice
|
||||
|
||||
export const {
|
||||
updateStoreReview,
|
||||
updatePublicRemoteNotice
|
||||
} = contextsSlice.actions
|
||||
export default contextsSlice.reducer
|
Reference in New Issue
Block a user