mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 16:55:08 +00:00
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;
|
return canModifyTimer && showTopicTimerModal;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed
|
||||||
|
additionalOpts() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
|
||||||
renderTopicTimer() {
|
renderTopicTimer() {
|
||||||
const isDeleteRepliesType = this.statusType === DELETE_REPLIES_TYPE;
|
const isDeleteRepliesType = this.statusType === DELETE_REPLIES_TYPE;
|
||||||
|
|
||||||
@ -71,16 +76,6 @@ export default Component.extend({
|
|||||||
const duration = moment.duration(statusUpdateAt - moment());
|
const duration = moment.duration(statusUpdateAt - moment());
|
||||||
const minutesLeft = duration.asMinutes();
|
const minutesLeft = duration.asMinutes();
|
||||||
if (minutesLeft > 0 || isDeleteRepliesType || this.basedOnLastPost) {
|
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 durationMinutes = parseInt(this.durationMinutes, 0) || 0;
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
@ -99,7 +94,8 @@ export default Component.extend({
|
|||||||
categoryName: category.get("slug"),
|
categoryName: category.get("slug"),
|
||||||
categoryUrl: category.get("url"),
|
categoryUrl: category.get("url"),
|
||||||
},
|
},
|
||||||
options
|
options,
|
||||||
|
this.additionalOpts
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,13 +109,27 @@ export default Component.extend({
|
|||||||
if (!isTesting()) {
|
if (!isTesting()) {
|
||||||
this._delayedRerender = later(() => {
|
this._delayedRerender = later(() => {
|
||||||
this.renderTopicTimer();
|
this.renderTopicTimer();
|
||||||
}, rerenderDelay);
|
}, this.rerenderDelay(minutesLeft));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.set("showTopicTimer", null);
|
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() {
|
_noticeKey() {
|
||||||
let statusType = this.statusType;
|
let statusType = this.statusType;
|
||||||
if (statusType === "silent_close") {
|
if (statusType === "silent_close") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user