This repository has been archived on 2023-12-20. You can view files and clone it, but cannot push or open issues/pull-requests.
PartyApp/src/configs/appVarReducer.ts

57 lines
1.7 KiB
TypeScript

import {createSlice} from '@reduxjs/toolkit';
import type {PayloadAction} from '@reduxjs/toolkit';
import {
PREFERENCES_VARS,
preferences_vars_default,
RegisterProcess,
} from './appVar';
import LangFormat from '@lang/default';
import {lang as defaultLang} from '@lang/en';
import {UserId} from './types';
import {MyUserAccount} from '@user/types';
import {ThemeMode} from './colors';
export interface appVariablesState {
preferences: PREFERENCES_VARS;
lang: LangFormat;
}
const initialState: appVariablesState = {
preferences: preferences_vars_default,
lang: defaultLang,
};
export const appVariablesSlice = createSlice({
name: 'appVariables',
initialState,
reducers: {
setTheme: (state, action: PayloadAction<ThemeMode>) => {
state.preferences.theme = action.payload;
},
setLang: (state, action: PayloadAction<LangFormat>) => {
state.lang = action.payload;
},
loadPreferences: (state, action: PayloadAction<PREFERENCES_VARS>) => {
state.preferences = action.payload;
},
setRegisterProcess: (state, action: PayloadAction<RegisterProcess>) => {
state.preferences.RegisterProcess = action.payload;
},
setCurrentAccount: (state, action: PayloadAction<UserId>) => {
state.preferences.selectedAccount = action.payload;
},
setAccount: (state, action: PayloadAction<MyUserAccount>) => {
state.preferences.accounts[action.payload.UserId] = action.payload;
},
setDBEK: (state, action: PayloadAction<number>) => {
state.preferences.dbek = action.payload;
},
},
});
// Action creators are generated for each case reducer function
const {actions} = appVariablesSlice;
export const appVarActions = actions;
export default appVariablesSlice.reducer;