peertube-plugin-livechat/client/common/configuration/register.ts

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-08-08 15:15:05 +00:00
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import { renderConfigurationHome } from './templates/home'
import { renderConfigurationChannel } from './templates/channel'
2023-08-08 15:15:05 +00:00
2023-08-08 16:26:40 +00:00
/**
* Registers stuff related to the user's configuration pages.
2023-08-08 16:26:40 +00:00
* @param clientOptions Peertube client options
*/
async function registerConfiguration (clientOptions: RegisterClientOptions): Promise<void> {
2023-08-08 15:15:05 +00:00
const { peertubeHelpers, registerClientRoute, registerHook } = clientOptions
const settings = await peertubeHelpers.getSettings()
if (settings['disable-channel-configuration']) { return }
2023-08-08 15:15:05 +00:00
registerClientRoute({
route: 'livechat/configuration',
2023-08-08 15:15:05 +00:00
onMount: async ({ rootEl }) => {
rootEl.innerHTML = await renderConfigurationHome(clientOptions)
2023-08-08 15:15:05 +00:00
}
})
2023-08-08 16:26:40 +00:00
registerClientRoute({
route: 'livechat/configuration/channel',
2023-08-08 16:26:40 +00:00
onMount: async ({ rootEl }) => {
const urlParams = new URLSearchParams(window.location.search)
const channelId = urlParams.get('channelId') ?? ''
2023-09-21 15:13:28 +00:00
await renderConfigurationChannel(clientOptions, channelId, rootEl)
2023-08-08 16:26:40 +00:00
}
})
2023-08-08 15:15:05 +00:00
registerHook({
target: 'filter:left-menu.links.create.result',
handler: async (links: any) => {
// Adding the links to livechat/configuration for logged users.
2023-08-08 15:15:05 +00:00
if (!peertubeHelpers.isLoggedIn()) { return links }
if (!Array.isArray(links)) { return links }
let myLibraryLinks
// Searching the 'in-my-library' entry.
for (const link of links) {
if (typeof link !== 'object') { continue }
if (!('key' in link)) { continue }
if (link.key !== 'in-my-library') { continue }
myLibraryLinks = link
break
}
if (!myLibraryLinks) { return links }
if (!Array.isArray(myLibraryLinks.links)) { return links }
const label = await peertubeHelpers.translate(LOC_MENU_CONFIGURATION_LABEL)
2023-08-08 15:15:05 +00:00
myLibraryLinks.links.push({
label,
shortLabel: label,
path: '/p/livechat/configuration',
2023-08-08 15:15:05 +00:00
icon: 'live'
})
return links
}
})
}
export {
registerConfiguration
2023-08-08 15:15:05 +00:00
}