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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user