FIX: prevents double set in the same computation (#31348)

The current code was doing:
- initial value for `showPreview`
- setting another default value in `_setupPreview`

The fix is to move all the computation in one initial step when
initializing the property.
This commit is contained in:
Joffrey JAFFEUX 2025-02-14 11:52:55 +01:00 committed by GitHub
parent 04531f1443
commit 7779cf1e90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,7 +4,7 @@ import { alias, and, or, reads } from "@ember/object/computed";
import { cancel, scheduleOnce } from "@ember/runloop";
import Service, { service } from "@ember/service";
import { isEmpty } from "@ember/utils";
import { observes, on } from "@ember-decorators/object";
import { observes } from "@ember-decorators/object";
import $ from "jquery";
import { Promise } from "rsvp";
import DiscardDraftModal from "discourse/components/modal/discard-draft";
@ -107,7 +107,11 @@ export default class ComposerService extends Service {
@service siteSettings;
@service store;
@tracked showPreview = true;
@tracked
showPreview = this.site.mobileView
? false
: (this.keyValueStore.get("composer.showPreview") || "true") === "true";
@tracked allowPreview = true;
checkedMessages = false;
messageCount = null;
@ -154,14 +158,6 @@ export default class ComposerService extends Service {
return NEW_PRIVATE_MESSAGE_KEY + "_" + new Date().getTime();
}
@on("init")
_setupPreview() {
const val = this.site.mobileView
? false
: this.keyValueStore.get("composer.showPreview") || "true";
this.set("showPreview", val === "true");
}
@computed(
"model.loading",
"isUploading",