Adrià Vilanova MartÃnez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame^] | 1 | import {MDCTooltip} from '@material/tooltip'; |
| 2 | |
| 3 | import {parseUrl} from '../../../../common/commonUtils.js'; |
| 4 | import ThreadExtraInfoService from '../services/thread.js'; |
| 5 | |
| 6 | import BaseExtraInfoInjection from './base.js'; |
| 7 | |
| 8 | export 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 | } |