feat(mobx): implement locale options

This commit is contained in:
Paul
2021-12-11 11:56:33 +00:00
parent 89748d7044
commit 87a9841885
5 changed files with 155 additions and 144 deletions

View File

@@ -5,6 +5,7 @@ import { useContext } from "preact/hooks";
import Auth from "./stores/Auth";
import Draft from "./stores/Draft";
import LocaleOptions from "./stores/LocaleOptions";
interface StoreDefinition {
id: string;
@@ -20,6 +21,7 @@ interface StoreDefinition {
export default class State {
auth: Auth;
draft: Draft;
locale: LocaleOptions;
/**
* Construct new State.
@@ -27,6 +29,7 @@ export default class State {
constructor() {
this.auth = new Auth();
this.draft = new Draft();
this.locale = new LocaleOptions();
makeAutoObservable(this);
}

View File

@@ -72,13 +72,21 @@ export default class LocaleOptions implements Persistent<Data> {
// eslint-disable-next-line require-jsdoc
@action hydrate(data: Data) {
this.lang = data.lang;
this.setLanguage(data.lang);
}
/**
* Get current language.
*/
@computed getLang() {
@computed getLanguage() {
return this.lang;
}
/**
* Set current language.
*/
@action setLanguage(language: Language) {
if (typeof Languages[language] === "undefined") return;
this.lang = language;
}
}