mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fixed #497
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { SettingsV0 } from './v0'
|
||||
import { SettingsV1 } from './v1'
|
||||
import { SettingsV2 } from './v2'
|
||||
import { SettingsV3 } from './v3'
|
||||
|
||||
const settingsMigration = {
|
||||
1: (state: SettingsV0): SettingsV1 => {
|
||||
@ -15,6 +16,10 @@ const settingsMigration = {
|
||||
darkTheme: 'lighter',
|
||||
staticEmoji: false
|
||||
}
|
||||
},
|
||||
3: (state: SettingsV2): SettingsV3 => {
|
||||
const { analytics, ...rest } = state
|
||||
return rest
|
||||
}
|
||||
}
|
||||
|
||||
|
8
src/utils/migrations/settings/v3.ts
Normal file
8
src/utils/migrations/settings/v3.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export type SettingsV3 = {
|
||||
fontsize: -1 | 0 | 1 | 2 | 3
|
||||
language: string
|
||||
theme: 'light' | 'dark' | 'auto'
|
||||
darkTheme: 'lighter' | 'darker'
|
||||
browser: 'internal' | 'external'
|
||||
staticEmoji: boolean
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import analytics from '@components/analytics'
|
||||
import features from '@helpers/features'
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { RootState } from '@root/store'
|
||||
@ -184,8 +183,6 @@ const instancesSlice = createSlice({
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
analytics('login')
|
||||
})
|
||||
.addCase(addInstance.rejected, (state, action) => {
|
||||
console.error(state.instances)
|
||||
@ -204,8 +201,6 @@ const instancesSlice = createSlice({
|
||||
}
|
||||
})
|
||||
state.instances.length && (state.instances[state.instances.length - 1].active = true)
|
||||
|
||||
analytics('logout')
|
||||
})
|
||||
.addCase(removeInstance.rejected, (state, action) => {
|
||||
console.error(state)
|
||||
|
@ -1,72 +1,43 @@
|
||||
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { LOCALES } from '@root/i18n/locales'
|
||||
import { RootState } from '@root/store'
|
||||
import { SettingsV2 } from '@utils/migrations/settings/v2'
|
||||
import * as Analytics from 'expo-firebase-analytics'
|
||||
import { SettingsV3 } from '@utils/migrations/settings/v3'
|
||||
import * as Localization from 'expo-localization'
|
||||
import { pickBy } from 'lodash'
|
||||
|
||||
export const changeAnalytics = createAsyncThunk(
|
||||
'settings/changeAnalytics',
|
||||
async (newValue: SettingsState['analytics']) => {
|
||||
await Analytics.setAnalyticsCollectionEnabled(newValue)
|
||||
return { newValue }
|
||||
}
|
||||
)
|
||||
|
||||
export type SettingsState = SettingsV2
|
||||
export type SettingsState = SettingsV3
|
||||
|
||||
export const settingsInitialState = {
|
||||
fontsize: 0,
|
||||
notification: {
|
||||
enabled: false
|
||||
},
|
||||
language: Object.keys(
|
||||
pickBy(LOCALES, (_, key) => Localization.locale.startsWith(key))
|
||||
)
|
||||
? Object.keys(
|
||||
pickBy(LOCALES, (_, key) => Localization.locale.startsWith(key))
|
||||
)[0]
|
||||
language: Object.keys(pickBy(LOCALES, (_, key) => Localization.locale.startsWith(key)))
|
||||
? Object.keys(pickBy(LOCALES, (_, key) => Localization.locale.startsWith(key)))[0]
|
||||
: 'en',
|
||||
theme: 'auto',
|
||||
darkTheme: 'lighter',
|
||||
browser: 'internal',
|
||||
staticEmoji: false,
|
||||
analytics: true
|
||||
staticEmoji: false
|
||||
}
|
||||
|
||||
const settingsSlice = createSlice({
|
||||
name: 'settings',
|
||||
initialState: settingsInitialState as SettingsState,
|
||||
reducers: {
|
||||
changeFontsize: (
|
||||
state,
|
||||
action: PayloadAction<SettingsState['fontsize']>
|
||||
) => {
|
||||
changeFontsize: (state, action: PayloadAction<SettingsState['fontsize']>) => {
|
||||
state.fontsize = action.payload
|
||||
},
|
||||
changeLanguage: (
|
||||
state,
|
||||
action: PayloadAction<NonNullable<SettingsState['language']>>
|
||||
) => {
|
||||
changeLanguage: (state, action: PayloadAction<NonNullable<SettingsState['language']>>) => {
|
||||
state.language = action.payload
|
||||
},
|
||||
changeTheme: (
|
||||
state,
|
||||
action: PayloadAction<NonNullable<SettingsState['theme']>>
|
||||
) => {
|
||||
changeTheme: (state, action: PayloadAction<NonNullable<SettingsState['theme']>>) => {
|
||||
state.theme = action.payload
|
||||
},
|
||||
changeDarkTheme: (
|
||||
state,
|
||||
action: PayloadAction<NonNullable<SettingsState['darkTheme']>>
|
||||
) => {
|
||||
changeDarkTheme: (state, action: PayloadAction<NonNullable<SettingsState['darkTheme']>>) => {
|
||||
state.darkTheme = action.payload
|
||||
},
|
||||
changeBrowser: (
|
||||
state,
|
||||
action: PayloadAction<NonNullable<SettingsState['browser']>>
|
||||
) => {
|
||||
changeBrowser: (state, action: PayloadAction<NonNullable<SettingsState['browser']>>) => {
|
||||
state.browser = action.payload
|
||||
},
|
||||
changeStaticEmoji: (
|
||||
@ -75,25 +46,15 @@ const settingsSlice = createSlice({
|
||||
) => {
|
||||
state.staticEmoji = action.payload
|
||||
}
|
||||
},
|
||||
extraReducers: builder => {
|
||||
builder.addCase(changeAnalytics.fulfilled, (state, action) => {
|
||||
state.analytics = action.payload.newValue
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const getSettingsFontsize = (state: RootState) =>
|
||||
state.settings.fontsize || 0
|
||||
export const getSettingsFontsize = (state: RootState) => state.settings.fontsize || 0
|
||||
export const getSettingsLanguage = (state: RootState) => state.settings.language
|
||||
export const getSettingsTheme = (state: RootState) => state.settings.theme
|
||||
export const getSettingsDarkTheme = (state: RootState) =>
|
||||
state.settings.darkTheme
|
||||
export const getSettingsDarkTheme = (state: RootState) => state.settings.darkTheme
|
||||
export const getSettingsBrowser = (state: RootState) => state.settings.browser
|
||||
export const getSettingsStaticEmoji = (state: RootState) =>
|
||||
state.settings.staticEmoji
|
||||
export const getSettingsAnalytics = (state: RootState) =>
|
||||
state.settings.analytics
|
||||
export const getSettingsStaticEmoji = (state: RootState) => state.settings.staticEmoji
|
||||
|
||||
export const {
|
||||
changeFontsize,
|
||||
|
Reference in New Issue
Block a user