mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-10 01:03:36 -05:00
fix(state): sync locale correctly
This commit is contained in:
parent
3ce04f543f
commit
05266790ae
1 changed files with 14 additions and 1 deletions
|
@ -4,6 +4,7 @@ import { Language, Languages } from "../../context/Locale";
|
||||||
|
|
||||||
import Persistent from "../interfaces/Persistent";
|
import Persistent from "../interfaces/Persistent";
|
||||||
import Store from "../interfaces/Store";
|
import Store from "../interfaces/Store";
|
||||||
|
import Syncable from "../interfaces/Syncable";
|
||||||
|
|
||||||
export interface Data {
|
export interface Data {
|
||||||
lang: Language;
|
lang: Language;
|
||||||
|
@ -51,7 +52,9 @@ export function findLanguage(lang?: string): Language {
|
||||||
/**
|
/**
|
||||||
* Keeps track of user's language settings.
|
* Keeps track of user's language settings.
|
||||||
*/
|
*/
|
||||||
export default class LocaleOptions implements Store, Persistent<Data> {
|
export default class LocaleOptions
|
||||||
|
implements Store, Persistent<Data>, Syncable
|
||||||
|
{
|
||||||
private lang: Language;
|
private lang: Language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,6 +75,16 @@ export default class LocaleOptions implements Store, Persistent<Data> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply(_key: "locale", data: unknown, _revision: number): void {
|
||||||
|
this.hydrate(data as Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed toSyncable(): { [key: string]: object } {
|
||||||
|
return {
|
||||||
|
locale: this.toJSON(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@action hydrate(data: Data) {
|
@action hydrate(data: Data) {
|
||||||
this.setLanguage(data.lang);
|
this.setLanguage(data.lang);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue