Skip to content

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

DEV: Clean up user-tips service (#25361)

Jarek Radosz40355139018a
diff --git a/app/assets/javascripts/discourse/app/services/user-tips.js b/app/assets/javascripts/discourse/app/services/user-tips.js
index 751ab86b5c7..f45e89ba3fe 100644
--- a/app/assets/javascripts/discourse/app/services/user-tips.js
+++ b/app/assets/javascripts/discourse/app/services/user-tips.js
@@ -1,7 +1,6 @@
import Service, { inject as service } from "@ember/service";
-import { TrackedMap } from "@ember-compat/tracked-built-ins";
+import { TrackedSet } from "@ember-compat/tracked-built-ins";
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
-import Site from "discourse/models/site";
import { isTesting } from "discourse-common/config/environment";
@disableImplicitInjections
@@ -11,15 +10,14 @@ export default class UserTips extends Service {
#availableTips = new Set();
#renderedId;
- #shouldRenderMap = new TrackedMap();
+ #shouldRenderSet = new TrackedSet();
#updateRenderedId() {
- const tipsArray = [...this.#availableTips];
- if (tipsArray.find((tip) => tip.id === this.#renderedId)) {
+ if (this.#availableTips.has(this.#renderedId)) {
return;
}
- const newId = tipsArray
+ const newId = [...this.#availableTips]
.sortBy("priority")
.reverse()
.find((tip) => {
@@ -29,14 +27,14 @@ export default class UserTips extends Service {
})?.id;
if (this.#renderedId !== newId) {
- this.#shouldRenderMap.delete(this.#renderedId);
- this.#shouldRenderMap.set(newId, true);
+ this.#shouldRenderSet.delete(this.#renderedId);
+ this.#shouldRenderSet.add(newId);
this.#renderedId = newId;
}
}
shouldRender(id) {
- return this.#shouldRenderMap.get(id);
+ return this.#shouldRenderSet.has(id);
}
addAvailableTip(tip) {
@@ -54,8 +52,7 @@ export default class UserTips extends Service {
return false;
}
- const userTips = Site.currentProp("user_tips");
-
+ const userTips = this.site.user_tips;
if (!userTips || this.currentUser.user_option?.skip_new_user_tips) {
return false;
}
@@ -81,7 +78,7 @@ export default class UserTips extends Service {
return;
}
- const userTips = Site.currentProp("user_tips");
+ const userTips = this.site.user_tips;
if (!userTips || this.currentUser.user_option?.skip_new_user_tips) {
return;
}