fix: Embed disabled state should persist (#3407)

* Normalize code around localStorage
Persist disabled embed state

* fix: Cannot view more than 10 starred items on load

* More tidying of sidebar state
This commit is contained in:
Tom Moor
2022-04-17 10:24:40 -07:00
committed by GitHub
parent 1e1a57d246
commit e4e98286f4
11 changed files with 267 additions and 192 deletions

View File

@@ -1,11 +1,12 @@
import { addDays, differenceInDays } from "date-fns";
import { floor } from "lodash";
import { action, computed, observable } from "mobx";
import { action, autorun, computed, observable } from "mobx";
import parseTitle from "@shared/utils/parseTitle";
import unescape from "@shared/utils/unescape";
import DocumentsStore from "~/stores/DocumentsStore";
import User from "~/models/User";
import { NavigationNode } from "~/types";
import Storage from "~/utils/Storage";
import ParanoidModel from "./ParanoidModel";
import View from "./View";
import Field from "./decorators/Field";
@@ -18,11 +19,28 @@ type SaveOptions = {
};
export default class Document extends ParanoidModel {
constructor(fields: Record<string, any>, store: DocumentsStore) {
super(fields, store);
if (this.isPersistedOnce && this.isFromTemplate) {
this.title = "";
}
this.embedsDisabled = Storage.get(`embedsDisabled-${this.id}`) ?? false;
autorun(() => {
Storage.set(
`embedsDisabled-${this.id}`,
this.embedsDisabled ? true : undefined
);
});
}
@observable
isSaving = false;
@observable
embedsDisabled = false;
embedsDisabled: boolean;
@observable
lastViewedAt: string | undefined;
@@ -82,14 +100,6 @@ export default class Document extends ParanoidModel {
revision: number;
constructor(fields: Record<string, any>, store: DocumentsStore) {
super(fields, store);
if (this.isPersistedOnce && this.isFromTemplate) {
this.title = "";
}
}
@computed
get emoji() {
const { emoji } = parseTitle(this.title);