mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-06 17:11:55 +00:00
feat(mobx): implement locale options
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user