feat: add changelog modal

This commit is contained in:
Paul Makles
2022-06-12 22:19:41 +01:00
parent 6d74d9046c
commit 5c94494280
11 changed files with 239 additions and 4 deletions

View File

@@ -0,0 +1,72 @@
import { action, makeAutoObservable, runInAction } from "mobx";
import { modalController } from "../../context/modals";
import { latestChangelog } from "../../assets/changelogs";
import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store";
import Syncable from "../interfaces/Syncable";
export interface Data {
viewed?: number;
}
/**
* Keeps track of viewed changelog items
*/
export default class Changelog implements Store, Persistent<Data>, Syncable {
/**
* Last viewed changelog ID
*/
private viewed: number;
/**
* Construct new Layout store.
*/
constructor() {
this.viewed = 0;
makeAutoObservable(this);
}
get id() {
return "changelog";
}
toJSON() {
return {
viewed: this.viewed,
};
}
@action hydrate(data: Data) {
if (data.viewed) {
this.viewed = data.viewed;
}
}
apply(_key: string, data: unknown, _revision: number): void {
this.hydrate(data as Data);
}
toSyncable(): { [key: string]: object } {
return {
changelog: this.toJSON(),
};
}
/**
* Check whether there are new updates
*/
checkForUpdates() {
if (this.viewed < latestChangelog) {
modalController.push({
type: "changelog",
initial: latestChangelog,
});
runInAction(() => {
this.viewed = latestChangelog;
});
}
}
}

View File

@@ -19,7 +19,8 @@ export type SyncKeys =
| "appearance"
| "locale"
| "notifications"
| "ordering";
| "ordering"
| "changelog";
export const SYNC_KEYS: SyncKeys[] = [
"theme",
@@ -27,6 +28,7 @@ export const SYNC_KEYS: SyncKeys[] = [
"locale",
"notifications",
"ordering",
"changelog",
];
export interface Data {