blob: f5a6874954134c63d830e82e03ad778ecc4185b3 [file] [log] [blame]
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +01001import {MDCTooltip} from '@material/tooltip';
2
3import {parseUrl} from '../../../../common/commonUtils.js';
4import ThreadExtraInfoService from '../services/thread.js';
5
6import BaseExtraInfoInjection from './base.js';
7
8export default class ExpandedThreadListExtraInfoInjection extends
9 BaseExtraInfoInjection {
10 getInjectionDetails(toolbelt) {
11 const headerContent =
12 toolbelt?.parentNode?.parentNode?.parentNode?.querySelector?.(
13 '.main-header .header a.header-content');
14 if (headerContent === null) {
15 throw new Error(
16 `extraInfo: Header is not present in the thread item's DOM.`);
17 }
18
19 const threadInfo = parseUrl(headerContent.href);
20 if (threadInfo === false)
21 throw new Error(`extraInfo: Thread's link cannot be parsed.`);
22
23 return {
24 toolbelt,
25 threadInfo,
26 isExpanded: true,
27 };
28 }
29
30 inject(threads, injectionDetails) {
31 const thread = ThreadExtraInfoService.getThreadFromThreadList(
32 threads, injectionDetails.threadInfo);
33 const [chipContentList, tooltips] =
34 ThreadExtraInfoService.getThreadChips(thread);
35 this.addExtraInfoChips(
36 chipContentList, injectionDetails.toolbelt, /* withContainer = */ true);
37 for (const tooltip of tooltips) new MDCTooltip(tooltip);
38 }
39}