chore(mobx): add legacy redux migations

This commit is contained in:
Paul
2021-12-21 12:31:14 +00:00
parent 961ba0dedb
commit b80e02cfaf
10 changed files with 99 additions and 16 deletions

View File

@@ -2,6 +2,8 @@ import { action, computed, makeAutoObservable, ObservableMap } from "mobx";
import { Session } from "revolt-api/types/Auth";
import { Nullable } from "revolt.js/dist/util/null";
import { mapToRecord } from "../../lib/conversion";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
@@ -9,8 +11,8 @@ interface Account {
session: Session;
}
interface Data {
sessions: Record<string, Account> | [string, Account][];
export interface Data {
sessions: Record<string, Account>;
current?: string;
}
@@ -37,7 +39,7 @@ export default class Auth implements Store, Persistent<Data> {
@action toJSON() {
return {
sessions: JSON.parse(JSON.stringify(this.sessions)),
sessions: JSON.parse(JSON.stringify(mapToRecord(this.sessions))),
current: this.current ?? undefined,
};
}

View File

@@ -5,7 +5,7 @@ import { mapToRecord } from "../../lib/conversion";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
interface Data {
export interface Data {
drafts: Record<string, string>;
}

View File

@@ -35,7 +35,7 @@ export const EXPERIMENTS: {
},
};
interface Data {
export interface Data {
enabled?: Experiment[];
}

View File

@@ -5,7 +5,7 @@ import { mapToRecord } from "../../lib/conversion";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
interface Data {
export interface Data {
lastSection?: "home" | "server";
lastHomePath?: string;
lastOpened?: Record<string, string>;

View File

@@ -5,7 +5,7 @@ import { Language, Languages } from "../../context/Locale";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
interface Data {
export interface Data {
lang: Language;
}

View File

@@ -34,7 +34,7 @@ export const DEFAULT_STATES: {
*/
export const DEFAULT_SERVER_STATE: NotificationState = "mention";
interface Data {
export interface Data {
server?: Record<string, NotificationState>;
channel?: Record<string, NotificationState>;
}

View File

@@ -6,10 +6,6 @@ import { Nullable } from "revolt.js/dist/util/null";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
interface Data {
config?: RevoltConfiguration;
}
/**
* Stores server configuration data.
*/

View File

@@ -12,7 +12,7 @@ import SAudio, { SoundOptions } from "./helpers/SAudio";
import SSecurity from "./helpers/SSecurity";
import STheme from "./helpers/STheme";
interface ISettings {
export interface ISettings {
"notifications:desktop": boolean;
"notifications:sounds": SoundOptions;
@@ -60,8 +60,9 @@ export default class Settings implements Store, Persistent<ISettings> {
}
@action hydrate(data: ISettings) {
Object.keys(data).forEach((key) =>
this.data.set(key, (data as any)[key]),
Object.keys(data).forEach(
(key) =>
(data as any)[key] && this.data.set(key, (data as any)[key]),
);
}

View File

@@ -21,7 +21,7 @@ export const SYNC_KEYS: SyncKeys[] = [
"notifications",
];
interface Data {
export interface Data {
disabled: SyncKeys[];
}