IMPR: improved topic timer component's code structure (#12519)
This PR improves the code structure of the topic-timer-info component while retaining all the functionality and making it extensible for theme/plugin devs.
This commit is contained in:
parent
eb25d3a954
commit
3bd482c6bd
|
@ -45,6 +45,11 @@ export default Component.extend({
|
|||
return canModifyTimer && showTopicTimerModal;
|
||||
},
|
||||
|
||||
@discourseComputed
|
||||
additionalOpts() {
|
||||
return {};
|
||||
},
|
||||
|
||||
renderTopicTimer() {
|
||||
const isDeleteRepliesType = this.statusType === DELETE_REPLIES_TYPE;
|
||||
|
||||
|
@ -71,16 +76,6 @@ export default Component.extend({
|
|||
const duration = moment.duration(statusUpdateAt - moment());
|
||||
const minutesLeft = duration.asMinutes();
|
||||
if (minutesLeft > 0 || isDeleteRepliesType || this.basedOnLastPost) {
|
||||
let rerenderDelay = 1000;
|
||||
if (minutesLeft > 2160) {
|
||||
rerenderDelay = 12 * 60 * 60000;
|
||||
} else if (minutesLeft > 1410) {
|
||||
rerenderDelay = 60 * 60000;
|
||||
} else if (minutesLeft > 90) {
|
||||
rerenderDelay = 30 * 60000;
|
||||
} else if (minutesLeft > 2) {
|
||||
rerenderDelay = 60000;
|
||||
}
|
||||
let durationMinutes = parseInt(this.durationMinutes, 0) || 0;
|
||||
|
||||
let options = {
|
||||
|
@ -99,7 +94,8 @@ export default Component.extend({
|
|||
categoryName: category.get("slug"),
|
||||
categoryUrl: category.get("url"),
|
||||
},
|
||||
options
|
||||
options,
|
||||
this.additionalOpts
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -113,13 +109,27 @@ export default Component.extend({
|
|||
if (!isTesting()) {
|
||||
this._delayedRerender = later(() => {
|
||||
this.renderTopicTimer();
|
||||
}, rerenderDelay);
|
||||
}, this.rerenderDelay(minutesLeft));
|
||||
}
|
||||
} else {
|
||||
this.set("showTopicTimer", null);
|
||||
}
|
||||
},
|
||||
|
||||
rerenderDelay(minutesLeft) {
|
||||
if (minutesLeft > 2160) {
|
||||
return 12 * 60 * 60000;
|
||||
} else if (minutesLeft > 1410) {
|
||||
return 60 * 60000;
|
||||
} else if (minutesLeft > 90) {
|
||||
return 30 * 60000;
|
||||
} else if (minutesLeft > 2) {
|
||||
return 60000;
|
||||
}
|
||||
|
||||
return 1000;
|
||||
},
|
||||
|
||||
_noticeKey() {
|
||||
let statusType = this.statusType;
|
||||
if (statusType === "silent_close") {
|
||||
|
|
Loading…
Reference in New Issue