diff --git a/js/ui/components/hashtagStripHelper.js b/js/ui/components/hashtagStripHelper.js index 56f3a5e2..8b0953e2 100644 --- a/js/ui/components/hashtagStripHelper.js +++ b/js/ui/components/hashtagStripHelper.js @@ -7,11 +7,17 @@ import { } from "./tagPillList.js"; export class HashtagStripHelper { - constructor({ document: doc = null, window: win = null, logger } = {}) { + constructor({ + document: doc = null, + window: win = null, + logger, + context = "", + } = {}) { this.document = doc || (typeof document !== "undefined" ? document : null); this.window = win || this.document?.defaultView || (typeof window !== "undefined" ? window : null); this.logger = logger || userLogger; + this.context = typeof context === "string" ? context : ""; this.container = null; this._tagStrip = null; @@ -132,6 +138,14 @@ export class HashtagStripHelper { this.activateHandler = typeof handler === "function" ? handler : null; } + setContext(context) { + this.context = typeof context === "string" ? context : ""; + } + + refreshTagPreferenceStates() { + this.refreshTagStates(); + } + refreshTagStates() { if (!this._tagStrip) { return; @@ -224,7 +238,11 @@ export class HashtagStripHelper { } try { - this.activateHandler(tag, detail); + this.activateHandler({ + tag, + trigger: detail?.button || null, + context: this.context, + }); } catch (error) { this.logger?.warn?.( "[HashtagStripHelper] Tag activation handler threw an error:", diff --git a/js/ui/views/VideoListView.js b/js/ui/views/VideoListView.js index e55d487f..faa8fc77 100644 --- a/js/ui/views/VideoListView.js +++ b/js/ui/views/VideoListView.js @@ -181,8 +181,9 @@ export class VideoListView { window: this.window, logger: userLogger, }); - this.popularTagHelper.setActivateHandler((tag, detail) => - this.handlePopularTagActivate(tag, detail), + this.popularTagHelper.setContext("popular-tags"); + this.popularTagHelper.setActivateHandler((detail) => + this.handlePopularTagActivate(detail), ); this.handlers = { @@ -1278,27 +1279,37 @@ export class VideoListView { refreshTagPreferenceStates() { if (this.popularTagHelper) { - this.popularTagHelper.refreshTagStates(); + this.popularTagHelper.refreshTagPreferenceStates(); } } - handlePopularTagActivate(tag, { event = null, button = null } = {}) { + handlePopularTagActivate(detail = {}, options = {}) { + const candidate = + detail && typeof detail === "object" ? detail : { tag: detail }; + const tag = candidate.tag; + const event = candidate.event || options.event || null; + const trigger = + candidate.trigger || candidate.button || options.button || null; + const context = + typeof candidate.context === "string" && candidate.context + ? candidate.context + : "popular-tags"; const normalizedTag = typeof tag === "string" && tag.trim() ? tag.trim() : String(tag ?? ""); if (!normalizedTag) { return; } - const detail = { + const payload = { tag: normalizedTag, event, - trigger: button, - context: "popular-tags", + trigger, + context, }; if (typeof this.handlers.tagActivate === "function") { try { - this.handlers.tagActivate(detail); + this.handlers.tagActivate(payload); } catch (error) { userLogger.warn( "[VideoListView] Tag activation handler threw an error:", @@ -1307,6 +1318,6 @@ export class VideoListView { } } - this.emit("tag:activate", detail); + this.emit("tag:activate", payload); } }