peertube-plugin-livechat/client/common/lib/elements/help-button.ts

52 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-05-23 15:17:28 +00:00
// SPDX-FileCopyrightText: 2024 Mehdi Benadel <https://mehdibenadel.com>
//
// SPDX-License-Identifier: AGPL-3.0-only
2024-05-23 15:09:58 +00:00
import { html } from 'lit'
import { customElement, property, state } from 'lit/decorators.js'
import { unsafeHTML } from 'lit/directives/unsafe-html.js'
import { helpButtonSVG } from '../../../videowatch/buttons'
import { consume } from '@lit/context'
2024-05-23 14:56:11 +00:00
import { registerClientOptionsContext } from '../contexts/peertube'
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { Task } from '@lit/task'
import { localizedHelpUrl } from '../../../utils/help'
import { ptTr } from '../directives/translation'
import { DirectiveResult } from 'lit/directive'
2024-05-23 15:09:58 +00:00
import { LivechatElement } from './livechat'
2024-05-23 13:52:12 +00:00
@customElement('livechat-help-button')
2024-05-23 15:09:58 +00:00
export class HelpButtonElement extends LivechatElement {
2024-05-23 13:52:12 +00:00
@consume({ context: registerClientOptionsContext, subscribe: true })
2024-05-24 12:08:48 +00:00
public registerClientOptions?: RegisterClientOptions
@property({ attribute: false })
public buttonTitle: string | DirectiveResult = ptTr(LOC_ONLINE_HELP)
@property({ attribute: false })
public page: string = ''
@state()
public url: URL = new URL('https://lmddgtfy.net/')
2024-05-23 20:52:39 +00:00
private readonly _asyncTaskRender = new Task(this, {
task: async ([registerClientOptions]) => {
this.url = new URL(registerClientOptions
? await localizedHelpUrl(registerClientOptions, { page: this.page })
: '')
},
args: () => [this.registerClientOptions]
2024-05-23 20:52:39 +00:00
})
2024-05-23 20:52:39 +00:00
protected override render = (): unknown => {
return this._asyncTaskRender.render({
complete: () => html`<a
href="${this.url.href}"
target=_blank
title="${this.buttonTitle}"
class="orange-button peertube-button-link"
>${unsafeHTML(helpButtonSVG())}</a>`
})
}
}