Update tag strip activation payload

This commit is contained in:
thePR0M3TH3AN committed 2026-01-22 19:48:56 -05:00
1 parent cf2672918a
commit f91a35d89e
2 files changed
+40 -11

No files matched your search

+20 -2
View File
@@ -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:",
+20 -9
View File
@@ -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);
}
}