Fix motd close button for community ads (#7752)

Fixes a subtle breakage from the bootstrap migration: The motd close
button works for update/motds but not community ads. This PR cleans up
the duplicate code and subsequent deviation.
This commit is contained in:
Jeremy Rifkin
2025-06-01 21:49:11 -05:00
committed by GitHub
parent 86f37b0ada
commit 2fd27067f4

View File

@@ -26,17 +26,21 @@ import $ from 'jquery';
import {Ad, Motd} from './motd.interfaces.js';
function ensureShownMessage(message: string, motdNode: JQuery) {
motdNode.find('.content').html(message);
motdNode.removeClass('d-none');
function setupMotd(motdNode: JQuery, onHide: () => void) {
motdNode
.find('.btn-close')
.on('click', () => {
motdNode.addClass('d-none');
onHide();
})
.prop('title', 'Hide message');
}
function ensureShownMessage(message: string, motdNode: JQuery) {
motdNode.find('.content').html(message);
motdNode.removeClass('d-none');
}
export function isValidAd(ad: Ad, subLang: string): boolean {
if (!subLang || ad.filter.length === 0 || ad.filter.includes(subLang)) {
const now = Date.now();
@@ -59,6 +63,7 @@ export function isValidAd(ad: Ad, subLang: string): boolean {
}
function handleMotd(motd: Motd, motdNode: JQuery, subLang: string, adsEnabled: boolean, onHide: () => void) {
setupMotd(motdNode, onHide);
if (motd.update) {
ensureShownMessage(motd.update, motdNode);
} else if (motd.motd) {
@@ -68,12 +73,7 @@ function handleMotd(motd: Motd, motdNode: JQuery, subLang: string, adsEnabled: b
if (applicableAds != null && applicableAds.length > 0) {
const randomAd = applicableAds[Math.floor(Math.random() * applicableAds.length)];
motdNode.find('.content').html(randomAd.html);
motdNode.find('.close').on('click', () => {
motdNode.addClass('d-none');
onHide();
});
motdNode.removeClass('d-none');
ensureShownMessage(randomAd.html, motdNode);
}
}
}