fix(more-menu): resolve modal ⋯ video so Event Details + Popularity work (#31)

The video modal's ⋯ trigger declares its context via `data-more-dropdown="modal"`,
but attachMoreMenuHandlers read only `data-context`, so it defaulted to "card",
skipped the modal video resolution, and opened the popover with a null video. The
panel is built from that video, so every menu item got an empty data-event-id and
both Event Details and Popularity reported "No video selected."

- Read context from `data-more-dropdown` as well as `data-context`.
- Modal branch falls back to the modal's `activeVideo` when getCurrentVideo() is
  null (deep-link opens don't set the playback service's currentVideo).
- Defense-in-depth: handleEventDetailsAction resolves the video from
  app.videosMap.get(eventId); view-stats resolves via a new getVideoByEventId
  callback instead of a risky `|| currentVideo` that could show the wrong stats.
- Regression tests in tests/more-menu-controller.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.8 committed 2026-06-24 18:48:49 -04:00
1 parent 63dcb5f6ed
commit 1c256808ff
4 files changed
+160 -8

No files matched your search

+24 -3
View File
@@ -45,6 +45,7 @@ export default class MoreMenuController {
this.callbacks = {
getCurrentVideo: callbacks.getCurrentVideo || (() => null),
getVideoByEventId: callbacks.getVideoByEventId || (() => null),
getCurrentUserNpub: callbacks.getCurrentUserNpub || (() => null),
getCurrentUserPubkey: callbacks.getCurrentUserPubkey || (() => null),
canCurrentUserManageBlacklist:
@@ -1018,7 +1019,13 @@ export default class MoreMenuController {
event.preventDefault();
event.stopPropagation();
const context = button.getAttribute("data-context") || "card";
// The modal ⋯ trigger declares its context via `data-more-dropdown`
// ("modal"), not `data-context` — reading only the latter made it
// default to "card" and skip the modal video resolution below.
const context =
button.getAttribute("data-context") ||
button.getAttribute("data-more-dropdown") ||
"card";
let video = null;
let pointerInfo = null;
@@ -1027,6 +1034,11 @@ export default class MoreMenuController {
if (context === "modal") {
video = this.callbacks.getCurrentVideo();
// currentVideo can be null when the modal opened without playback
// starting (e.g. a deep link); fall back to the modal's activeVideo.
if (!video && this.videoModal?.activeVideo) {
video = this.videoModal.activeVideo;
}
if (Array.isArray(video?.pointer) && video.pointer.length >= 2) {
pointerInfo = { pointer: video.pointer };
}
@@ -1163,8 +1175,17 @@ export default class MoreMenuController {
break;
}
case "view-stats": {
const targetVideo =
video || (context === "modal" ? currentVideo : null) || currentVideo;
// Prefer the card's own video; fall back to resolving it from the menu
// item's eventId (card popovers don't always carry the object), and only
// use the modal's current video for the modal context.
let targetVideo = video || null;
if (!targetVideo && dataset?.eventId) {
targetVideo =
this.callbacks.getVideoByEventId(dataset.eventId) || null;
}
if (!targetVideo && context === "modal") {
targetVideo = currentVideo || null;
}
if (!targetVideo) {
this.callbacks.showError("No video selected.");
break;