40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
|
|
import type { Action, ThunkOn } from 'easy-peasy'
|
|||
|
|
import { action, thunkOn } from 'easy-peasy'
|
|||
|
|
import appConfig from '../configs/app.config'
|
|||
|
|
import { Injections, StoreModel } from '.'
|
|||
|
|
|
|||
|
|
export interface LocaleStoreModel {
|
|||
|
|
currentLang: string
|
|||
|
|
currentUiVersion: string | undefined
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export interface LocaleStoreActions {
|
|||
|
|
setLang: Action<LocaleStoreModel, string>
|
|||
|
|
onSetLang: ThunkOn<LocaleModel, Injections, StoreModel>
|
|||
|
|
setUiVersion: Action<LocaleStoreModel, string | undefined>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export type LocaleModel = LocaleStoreModel & LocaleStoreActions
|
|||
|
|
|
|||
|
|
const initialState: LocaleStoreModel = {
|
|||
|
|
currentLang: appConfig.locale,
|
|||
|
|
currentUiVersion: appConfig.uiVersion
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const localeModel: LocaleModel = {
|
|||
|
|
...initialState,
|
|||
|
|
setLang: action((state, payload) => {
|
|||
|
|
state.currentLang = payload
|
|||
|
|
}),
|
|||
|
|
onSetLang: thunkOn(
|
|||
|
|
(actions) => actions.setLang,
|
|||
|
|
async (actions, target, helpers) => {
|
|||
|
|
// Dil değiştiğince AppConfig ve Localizationları tekrar al
|
|||
|
|
helpers.getStoreActions().abpConfig.getConfig(false)
|
|||
|
|
},
|
|||
|
|
),
|
|||
|
|
setUiVersion: action((state, payload) => {
|
|||
|
|
state.currentUiVersion = payload
|
|||
|
|
}),
|
|||
|
|
}
|