Skip to content

Commit

Permalink
IMPR: improved topic timer component's code structure (#12519)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fzngagan committed Mar 25, 2021
1 parent eb25d3a commit 3bd482c
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions app/assets/javascripts/discourse/app/components/topic-timer-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export default Component.extend({
return canModifyTimer && showTopicTimerModal;
},

@discourseComputed
additionalOpts() {
return {};
},

renderTopicTimer() {
const isDeleteRepliesType = this.statusType === DELETE_REPLIES_TYPE;

Expand All @@ -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 = {
Expand All @@ -99,7 +94,8 @@ export default Component.extend({
categoryName: category.get("slug"),
categoryUrl: category.get("url"),
},
options
options,
this.additionalOpts
);
}

Expand All @@ -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") {
Expand Down

0 comments on commit 3bd482c

Please sign in to comment.