mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
fix(popularity): correct lazy-import path + forward video; single-instance modal
Two bugs in the #26 wiring surfaced live: - The ⋯ menu lazy-import used "../../viewCountChart.js" which resolves one level too high (dist/viewCountChart.js → 404 "Failed to fetch dynamically imported module"). Corrected to "../viewCountChart.js" (js/ui → js/viewCountChart.js). - The video-list context path called handleMoreMenuAction without the video, so view-stats hit "No video selected". Forward detail.video. Also make the popularity modal single-instance: close any open one (proper subscription/listener cleanup) before opening a new one, so the two menu paths firing for one click can't stack duplicates or leak a live subscription. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
575befb83c
commit
6911df075a
2 files changed
+23
-3
No files matched your search
@@ -157,7 +157,7 @@ export default class MoreMenuController {
|
||||
...(detail.dataset || {}),
|
||||
eventId: detail.dataset?.eventId || detail.video?.id || "",
|
||||
};
|
||||
this.handleMoreMenuAction(detail.action, dataset);
|
||||
this.handleMoreMenuAction(detail.action, dataset, detail.video || null);
|
||||
};
|
||||
|
||||
if (typeof view.addEventListener === "function") {
|
||||
@@ -1176,7 +1176,7 @@ export default class MoreMenuController {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
const { openPopularityModal } = await import("../../viewCountChart.js");
|
||||
const { openPopularityModal } = await import("../viewCountChart.js");
|
||||
openPopularityModal({ video: targetVideo });
|
||||
} catch (error) {
|
||||
userLogger.warn("[MoreMenu] Failed to open popularity modal:", error);
|
||||
|
||||
+21
-1
@@ -159,6 +159,9 @@ function el(doc, tag, className, text) {
|
||||
return node;
|
||||
}
|
||||
|
||||
// At most one popularity modal open at a time.
|
||||
let activePopularityModal = null;
|
||||
|
||||
// Opens the popularity modal for a video. Dependencies are injectable for tests.
|
||||
export function openPopularityModal({
|
||||
document: doc = typeof document !== "undefined" ? document : null,
|
||||
@@ -174,6 +177,18 @@ export function openPopularityModal({
|
||||
}
|
||||
const pointer = pointerInfo.pointer;
|
||||
|
||||
// Close any already-open popularity modal (proper cleanup of its subscription
|
||||
// + listeners) so re-triggering — or two menu paths firing for one click —
|
||||
// can't stack duplicates.
|
||||
if (activePopularityModal) {
|
||||
try {
|
||||
activePopularityModal.close();
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
activePopularityModal = null;
|
||||
}
|
||||
|
||||
const root = mount || doc.getElementById("uiOverlay") || doc.body;
|
||||
const backdrop = el(doc, "div", "ds-overlay-backdrop popularity-modal__backdrop");
|
||||
const dialog = el(doc, "div", "popularity-modal card p-md");
|
||||
@@ -255,6 +270,9 @@ export function openPopularityModal({
|
||||
}
|
||||
doc.removeEventListener("keydown", onKeydown, true);
|
||||
backdrop.remove();
|
||||
if (activePopularityModal === handle) {
|
||||
activePopularityModal = null;
|
||||
}
|
||||
};
|
||||
|
||||
function onKeydown(event) {
|
||||
@@ -298,5 +316,7 @@ export function openPopularityModal({
|
||||
devLogger.warn("[popularity] Failed to subscribe to view events:", error);
|
||||
}
|
||||
|
||||
return { close };
|
||||
const handle = { close };
|
||||
activePopularityModal = handle;
|
||||
return handle;
|
||||
}
|
||||
Reference in new issue
Block a user