From 4951900bbc447d1802a5e90c5b6526d5406a4086 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 19 Jan 2022 16:20:05 +0200 Subject: [PATCH] FEATURE: Store dismissed state of topic nav popups (#15570) The dismissed state will be stored between sessions if popupId attribute is present. --- .../app/components/topic-navigation-popup.js | 31 +++++++++++++++++++ .../discourse/app/templates/topic.hbs | 4 ++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js b/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js index 2b104b6506c..2a04dba997a 100644 --- a/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js +++ b/app/assets/javascripts/discourse/app/components/topic-navigation-popup.js @@ -1,12 +1,43 @@ import Component from "@ember/component"; import { action } from "@ember/object"; +import discourseComputed from "discourse-common/utils/decorators"; export default Component.extend({ tagName: "", + popupId: null, hidden: false, + init() { + this._super(...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); + } + } }, }); diff --git a/app/assets/javascripts/discourse/app/templates/topic.hbs b/app/assets/javascripts/discourse/app/templates/topic.hbs index bd82be5733e..e278aff1f8b 100644 --- a/app/assets/javascripts/discourse/app/templates/topic.hbs +++ b/app/assets/javascripts/discourse/app/templates/topic.hbs @@ -133,7 +133,9 @@ {{plugin-outlet name="above-timeline" connectorTagName="div"}} {{#topic-navigation class="topic-navigation" topic=model jumpToDate=(action "jumpToDate") jumpToIndex=(action "jumpToIndex") as |info|}} - {{plugin-outlet name="topic-navigation" connectorTagName="div" args=(hash topic=model)}} + {{#unless site.mobileView}} + {{plugin-outlet name="topic-navigation" connectorTagName="div" args=(hash topic=model)}} + {{/unless}} {{#if info.renderTimeline}} {{topic-timeline