From be8b7a5cb49a6efef628f8b482ea39ecc6c72dd5 Mon Sep 17 00:00:00 2001 From: floriankilian <34104015+floriankilian@users.noreply.github.com> Date: Wed, 9 Jul 2025 20:29:29 +0200 Subject: [PATCH] feat(news-button): highlight button when new version is available (#1385) Introduced a visual indicator for the NewsButton component to notify users about new content upon version update. This change adds an `isActive` state to the NewsButton that checks against the version stored in localStorage. If a new version is detected, the button is highlighted with specific styling defined in styles.css, including a pulsing notification effect to draw user attention. The state resets to inactive upon button click. This enhancement improves user engagement by ensuring they are aware of new updates. Fixes #1369 ## Description:   ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: [UN]nvm --- src/client/components/NewsButton.ts | 34 +++++++++++++++++++++++++---- src/client/styles.css | 34 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/client/components/NewsButton.ts b/src/client/components/NewsButton.ts index 52ecf5479..ba7411a34 100644 --- a/src/client/components/NewsButton.ts +++ b/src/client/components/NewsButton.ts @@ -1,15 +1,36 @@ import { LitElement, html } from "lit"; -import { customElement, property } from "lit/decorators.js"; +import { customElement, property, state } from "lit/decorators.js"; import megaphone from "../../../resources/images/Megaphone.svg"; +import version from "../../../resources/version.txt"; import { NewsModal } from "../NewsModal"; import { translateText } from "../Utils"; @customElement("news-button") export class NewsButton extends LitElement { - @property({ type: Boolean }) - hidden = false; + @property({ type: Boolean }) hidden = false; + @state() private isActive = false; + + connectedCallback() { + super.connectedCallback(); + this.checkForNewVersion(); + } + + private checkForNewVersion() { + try { + const lastSeenVersion = localStorage.getItem( + "news-button-last-seen-version", + ); + this.isActive = lastSeenVersion !== version; + } catch (error) { + // Fallback to NOT showing notification if localStorage fails + this.isActive = false; + } + } private handleClick() { + localStorage.setItem("news-button-last-seen-version", version); + this.isActive = false; + const newsModal = document.querySelector("news-modal") as NewsModal; if (newsModal) { newsModal.open(); @@ -18,7 +39,12 @@ export class NewsButton extends LitElement { render() { return html` -