Some refactoring.

This commit is contained in:
John Livingston 2024-06-06 10:26:39 +02:00
parent 5c87eef915
commit aa9697074a
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
4 changed files with 13 additions and 4 deletions

View File

@ -6,11 +6,14 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types' import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types'
import { registerConfiguration } from './common/configuration/register' import { registerConfiguration } from './common/configuration/register'
import { registerRoom } from './common/room/register' import { registerRoom } from './common/room/register'
import { registerClientOptionsSubject$ } from './common/lib/contexts/peertube'
import './common/lib/elements' // Import shared elements. import './common/lib/elements' // Import shared elements.
async function register (clientOptions: RegisterClientOptions): Promise<void> { async function register (clientOptions: RegisterClientOptions): Promise<void> {
const { peertubeHelpers, registerHook, registerVideoField } = clientOptions const { peertubeHelpers, registerHook, registerVideoField } = clientOptions
registerClientOptionsSubject$.next(clientOptions)
registerHook({ registerHook({
target: 'action:router.navigation-end', target: 'action:router.navigation-end',
handler: () => { handler: () => {

View File

@ -6,7 +6,6 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { html, render } from 'lit' import { html, render } from 'lit'
import './elements' // Import all needed elements. import './elements' // Import all needed elements.
import { registerClientOptionsSubject$ } from '../lib/contexts/peertube'
/** /**
* Registers stuff related to the user's configuration pages. * Registers stuff related to the user's configuration pages.
@ -18,8 +17,6 @@ async function registerConfiguration (clientOptions: RegisterClientOptions): Pro
const settings = await peertubeHelpers.getSettings() const settings = await peertubeHelpers.getSettings()
if (settings['disable-channel-configuration']) { return } if (settings['disable-channel-configuration']) { return }
registerClientOptionsSubject$.next(clientOptions)
registerClientRoute({ registerClientRoute({
route: 'livechat/configuration', route: 'livechat/configuration',
onMount: async ({ rootEl }) => { onMount: async ({ rootEl }) => {

View File

@ -60,6 +60,9 @@ export class TranslationDirective extends AsyncDirective {
} }
private readonly _asyncUpdateTranslation = async (): Promise<true> => { private readonly _asyncUpdateTranslation = async (): Promise<true> => {
if (!this._peertubeHelpers) {
console.error('Translation directive: missing peertubeHelpers')
}
const newValue = await this._peertubeHelpers?.translate(this._localizationId) ?? '' const newValue = await this._peertubeHelpers?.translate(this._localizationId) ?? ''
if (newValue !== '' && newValue !== this._translatedValue) { if (newValue !== '' && newValue !== this._translatedValue) {

View File

@ -2,9 +2,12 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { LivechatElement } from './livechat' import { LivechatElement } from './livechat'
import { registerClientOptionsContext } from '../contexts/peertube'
import { html } from 'lit' import { html } from 'lit'
import { customElement, property, state } from 'lit/decorators.js' import { customElement, property } from 'lit/decorators.js'
import { consume } from '@lit/context'
import { ifDefined } from 'lit/directives/if-defined.js' import { ifDefined } from 'lit/directives/if-defined.js'
/** /**
@ -21,6 +24,9 @@ import { ifDefined } from 'lit/directives/if-defined.js'
*/ */
@customElement('livechat-image-file-input') @customElement('livechat-image-file-input')
export class ImageFileInputElement extends LivechatElement { export class ImageFileInputElement extends LivechatElement {
@consume({ context: registerClientOptionsContext, subscribe: true })
public registerClientOptions?: RegisterClientOptions
@property({ attribute: false }) @property({ attribute: false })
public name?: string public name?: string