Skip to content

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

DEV: Convert TopicNavigationPopup to gjs (#29476)

Jarek Radosz671f7beadb25
diff --git a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.gjs b/app/assets/javascripts/discourse/app/components/topic-navigation-popup.gjs
new file mode 100644
index 00000000000..f236b5ca4d3
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/topic-navigation-popup.gjs
@@ -0,0 +1,55 @@
+import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { action } from "@ember/object";
+import { service } from "@ember/service";
+import DButton from "discourse/components/d-button";
+
+// For use in plugins
+export default class TopicNavigationPopup extends Component {
+ @service keyValueStore;
+
+ @tracked hidden = false;
+
+ constructor() {
+ super(...arguments);
+
+ if (this.popupKey) {
+ const value = this.keyValueStore.getItem(this.popupKey);
+
+ if (value === true || value > +new Date()) {
+ this.hidden = true;
+ } else {
+ this.keyValueStore.removeItem(this.popupKey);
+ }
+ }
+ }
+
+ get popupKey() {
+ if (this.args.popupId) {
+ return `dismiss_topic_nav_popup_${this.args.popupId}`;
+ }
+ }
+
+ @action
+ close() {
+ this.hidden = true;
+
+ if (this.popupKey) {
+ if (this.args.dismissDuration) {
+ const expiry = +new Date() + this.args.dismissDuration;
+ this.keyValueStore.setItem(this.popupKey, expiry);
+ } else {
+ this.keyValueStore.setItem(this.popupKey, true);
+ }
+ }
+ }
+
+ <template>
+ {{#unless this.hidden}}
+ <div class="topic-navigation-popup">
+ <DButton @action={{this.close}} @icon="xmark" class="close btn-flat" />
+ {{yield}}
+ </div>
+ {{/unless}}
+ </template>
+}
diff --git a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.hbs b/app/assets/javascripts/discourse/app/components/topic-navigation-popup.hbs
deleted file mode 100644
index c7fb4f3c9fb..00000000000
--- a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.hbs
+++ /dev/null
@@ -1,6 +0,0 @@
-{{#unless this.hidden}}
- <div class="topic-navigation-popup">
- <DButton @action={{this.close}} @icon="xmark" class="close btn-flat" />
- {{yield}}
- </div>
-{{/unless}}
\ No newline at end of file
diff --git a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js b/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js
deleted file mode 100644
index 62781c75ec7..00000000000
--- a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js
+++ /dev/null
@@ -1,44 +0,0 @@
-import Component from "@ember/component";
-import { action } from "@ember/object";
-import { tagName } from "@ember-decorators/component";
-import discourseComputed from "discourse-common/utils/decorators";
-
-@tagName("")
-export default class TopicNavigationPopup extends Component {
- popupId = null;
- hidden = false;
-
- init() {
- super.init(...arguments);
-
- if (this.popupKey) {
- const value = this.keyValueStore.getItem(this.popupKey);
- if (value === true || value > +new Date()) {
- this.set("hidden", true);
- } else {
- this.keyValueStore.removeItem(this.popupKey);
- }
- }
- }
-
- @discourseComputed("popupId")
- popupKey(popupId) {
- if (popupId) {
- return `dismiss_topic_nav_popup_${popupId}`;
- }
- }
-
- @action
- close() {
- this.set("hidden", true);
-
- if (this.popupKey) {
- if (this.dismissDuration) {
- const expiry = +new Date() + this.dismissDuration;
- this.keyValueStore.setItem(this.popupKey, expiry);
- } else {
- this.keyValueStore.setItem(this.popupKey, true);
- }
- }
- }
-}