Skip to content

A platform for community discussion. Free, open, simple.

DEV: Work around topic-timer data flow issues (#27207)

Jarek Radosz96305ec9a6a2
diff --git a/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.hbs b/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.hbs
index a8bb97eac32..83bde72319d 100644
--- a/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.hbs
+++ b/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.hbs
@@ -7,13 +7,15 @@
class="edit-topic-timer-modal"
>
<:body>
- <EditTopicTimerForm
- @topic={{@model.topic}}
- @topicTimer={{this.topicTimer}}
- @timerTypes={{this.publicTimerTypes}}
- @onChangeStatusType={{this.onChangeStatusType}}
- @onChangeInput={{this.onChangeInput}}
- />
+ {{#if this.topicTimer}}
+ <EditTopicTimerForm
+ @topic={{@model.topic}}
+ @topicTimer={{this.topicTimer}}
+ @timerTypes={{this.publicTimerTypes}}
+ @onChangeStatusType={{this.onChangeStatusType}}
+ @onChangeInput={{this.onChangeInput}}
+ />
+ {{/if}}
</:body>
<:footer>
<DButton
diff --git a/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.js b/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.js
index c1b0b6aeecd..918f0b1786c 100644
--- a/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.js
+++ b/app/assets/javascripts/discourse/app/components/modal/edit-topic-timer.js
@@ -1,6 +1,7 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
+import { next } from "@ember/runloop";
import { service } from "@ember/service";
import { TrackedObject } from "@ember-compat/tracked-built-ins";
import { popupAjaxError } from "discourse/lib/ajax-error";
@@ -19,13 +20,23 @@ export const DELETE_REPLIES_TYPE = "delete_replies";
export default class EditTopicTimer extends Component {
@service currentUser;
- @tracked
- topicTimer = new TrackedObject(
- this.args.model.topic?.topic_timer || this.createDefaultTimer()
- );
+ @tracked topicTimer;
@tracked loading = false;
@tracked flash;
+ constructor() {
+ super(...arguments);
+
+ if (this.args.model.topic?.topic_timer) {
+ this.topicTimer = new TrackedObject(this.args.model.topic?.topic_timer);
+ } else {
+ // TODO: next() is a hack, to-be-removed
+ next(() => {
+ this.topicTimer = new TrackedObject(this.createDefaultTimer());
+ });
+ }
+ }
+
get defaultStatusType() {
return this.publicTimerTypes[0].id;
}
diff --git a/app/assets/javascripts/discourse/app/components/topic-timer-info.js b/app/assets/javascripts/discourse/app/components/topic-timer-info.js
index 949a9457c3d..4900454dd66 100644
--- a/app/assets/javascripts/discourse/app/components/topic-timer-info.js
+++ b/app/assets/javascripts/discourse/app/components/topic-timer-info.js
@@ -1,5 +1,5 @@
import Component from "@ember/component";
-import { cancel } from "@ember/runloop";
+import { cancel, next } from "@ember/runloop";
import { htmlSafe } from "@ember/template";
import { DELETE_REPLIES_TYPE } from "discourse/components/modal/edit-topic-timer";
import Category from "discourse/models/category";
@@ -78,7 +78,8 @@ export default Component.extend({
// The topic status has just been toggled, so we can hide the timer info.
this.set("showTopicTimer", null);
// The timer has already been removed on the back end. The front end is not aware of the change yet.
- this.set("executeAt", null);
+ // TODO: next() is a hack, to-be-removed
+ next(() => this.set("executeAt", null));
return;
}