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

This commit is contained in:
Jarek Radosz 2024-05-29 10:54:55 +02:00 committed by GitHub
parent f76d143919
commit 96305ec9a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 13 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}