From 05266790aeb5dc4e5e13c82eb0ff14bfaa01e088 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Sat, 15 Jan 2022 15:43:32 +0000 Subject: [PATCH] fix(state): sync locale correctly --- src/mobx/stores/LocaleOptions.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mobx/stores/LocaleOptions.ts b/src/mobx/stores/LocaleOptions.ts index 9c708d6e..a22d3b3c 100644 --- a/src/mobx/stores/LocaleOptions.ts +++ b/src/mobx/stores/LocaleOptions.ts @@ -4,6 +4,7 @@ import { Language, Languages } from "../../context/Locale"; import Persistent from "../interfaces/Persistent"; import Store from "../interfaces/Store"; +import Syncable from "../interfaces/Syncable"; export interface Data { lang: Language; @@ -51,7 +52,9 @@ export function findLanguage(lang?: string): Language { /** * Keeps track of user's language settings. */ -export default class LocaleOptions implements Store, Persistent { +export default class LocaleOptions + implements Store, Persistent, Syncable +{ private lang: Language; /** @@ -72,6 +75,16 @@ export default class LocaleOptions implements Store, Persistent { }; } + 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) { this.setLanguage(data.lang); }