mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fixed #538
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { ContextsV0 } from './v0'
|
||||
import { ContextsV1 } from './v1'
|
||||
import { ContextsV2 } from './v2'
|
||||
import { ContextsV3 } from './v3'
|
||||
|
||||
const contextsMigration = {
|
||||
1: (state: ContextsV0): ContextsV1 => {
|
||||
@ -15,7 +16,12 @@ const contextsMigration = {
|
||||
2: (state: ContextsV1): ContextsV2 => {
|
||||
const { mePage, ...rest } = state
|
||||
return rest
|
||||
},
|
||||
3: (state: ContextsV2): ContextsV3 => {
|
||||
return { ...state, previousSegment: 'Local' }
|
||||
}
|
||||
}
|
||||
|
||||
export { ContextsV3 as ContextsLatest }
|
||||
|
||||
export default contextsMigration
|
||||
|
19
src/utils/migrations/contexts/v3.ts
Normal file
19
src/utils/migrations/contexts/v3.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { ScreenTabsStackParamList } from '@utils/navigation/navigators'
|
||||
|
||||
export type ContextsV3 = {
|
||||
storeReview: {
|
||||
context: Readonly<number>
|
||||
current: number
|
||||
shown: boolean
|
||||
}
|
||||
publicRemoteNotice: {
|
||||
context: Readonly<number>
|
||||
current: number
|
||||
hidden: boolean
|
||||
}
|
||||
previousTab: Extract<
|
||||
keyof ScreenTabsStackParamList,
|
||||
'Tab-Local' | 'Tab-Public' | 'Tab-Notifications' | 'Tab-Me'
|
||||
>
|
||||
previousSegment: Extract<App.Pages, 'Local' | 'LocalPublic' | 'Trending'>
|
||||
}
|
@ -1,23 +1,10 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { RootState } from '@root/store'
|
||||
import { ContextsLatest } from '@utils/migrations/contexts/migration'
|
||||
import Constants from 'expo-constants'
|
||||
import * as StoreReview from 'expo-store-review'
|
||||
|
||||
export type ContextsState = {
|
||||
storeReview: {
|
||||
context: Readonly<number>
|
||||
current: number
|
||||
shown: boolean
|
||||
}
|
||||
publicRemoteNotice: {
|
||||
context: Readonly<number>
|
||||
current: number
|
||||
hidden: boolean
|
||||
}
|
||||
previousTab: 'Tab-Local' | 'Tab-Public' | 'Tab-Notifications' | 'Tab-Me'
|
||||
}
|
||||
|
||||
export const contextsInitialState = {
|
||||
export const contextsInitialState: ContextsLatest = {
|
||||
// After 10 successful postings
|
||||
storeReview: {
|
||||
context: 10,
|
||||
@ -30,49 +17,46 @@ export const contextsInitialState = {
|
||||
current: 0,
|
||||
hidden: false
|
||||
},
|
||||
previousTab: 'Tab-Me'
|
||||
previousTab: 'Tab-Me',
|
||||
previousSegment: 'Local'
|
||||
}
|
||||
|
||||
const contextsSlice = createSlice({
|
||||
name: 'contexts',
|
||||
initialState: contextsInitialState as ContextsState,
|
||||
initialState: contextsInitialState,
|
||||
reducers: {
|
||||
updateStoreReview: (state, action: PayloadAction<1>) => {
|
||||
if (Constants.expoConfig?.extra?.environment === 'release') {
|
||||
state.storeReview.current = state.storeReview.current + action.payload
|
||||
if (state.storeReview.current === state.storeReview.context) {
|
||||
StoreReview?.isAvailableAsync().then(() =>
|
||||
StoreReview.requestReview()
|
||||
)
|
||||
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.current = state.publicRemoteNotice.current + action.payload
|
||||
if (state.publicRemoteNotice.current === state.publicRemoteNotice.context) {
|
||||
state.publicRemoteNotice.hidden = true
|
||||
}
|
||||
},
|
||||
updatePreviousTab: (
|
||||
state,
|
||||
action: PayloadAction<ContextsState['previousTab']>
|
||||
) => {
|
||||
updatePreviousTab: (state, action: PayloadAction<ContextsLatest['previousTab']>) => {
|
||||
state.previousTab = action.payload
|
||||
},
|
||||
updatePreviousSegment: (state, action: PayloadAction<ContextsLatest['previousSegment']>) => {
|
||||
state.previousSegment = action.payload
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const getPublicRemoteNotice = (state: RootState) =>
|
||||
state.contexts.publicRemoteNotice
|
||||
export const getPublicRemoteNotice = (state: RootState) => state.contexts.publicRemoteNotice
|
||||
export const getPreviousTab = (state: RootState) => state.contexts.previousTab
|
||||
export const getPreviousSegment = (state: RootState) => state.contexts.previousSegment
|
||||
export const getContexts = (state: RootState) => state.contexts
|
||||
|
||||
export const {
|
||||
updateStoreReview,
|
||||
updatePublicRemoteNotice,
|
||||
updatePreviousTab
|
||||
updatePreviousTab,
|
||||
updatePreviousSegment
|
||||
} = contextsSlice.actions
|
||||
export default contextsSlice.reducer
|
||||
|
Reference in New Issue
Block a user