From 04403225fb5ca7bd4bf9ea841d542e11b5f98121 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 5 Jun 2024 15:56:03 +0200 Subject: [PATCH] Custom channel emoticons WIP (#130) + various fix --- assets/styles/configuration.scss | 12 +++ client/@types/global.d.ts | 4 + .../configuration/elements/channel-emojis.ts | 43 ++++++++- .../common/lib/elements/dynamic-table-form.ts | 70 ++++++++++----- client/common/lib/elements/help-button.ts | 2 +- .../common/lib/elements/image-file-input.ts | 89 +++++++++++++++++++ client/common/lib/elements/index.js | 2 + languages/en.yml | 8 ++ server/lib/emojis/emojis.ts | 4 + server/lib/emojis/index.ts | 4 + 10 files changed, 215 insertions(+), 23 deletions(-) create mode 100644 client/common/lib/elements/image-file-input.ts diff --git a/assets/styles/configuration.scss b/assets/styles/configuration.scss index 859f83ab..d3923cdf 100644 --- a/assets/styles/configuration.scss +++ b/assets/styles/configuration.scss @@ -423,3 +423,15 @@ livechat-tags-input { filter: opacity(50%) grayscale(80%); } } + +livechat-image-file-input { + img { + cursor: pointer; + position: fixed; + + // width and height are values coming from ConverseJS custom emojis. + // If we want to upload something else, we should add options on the field to customize. + height: 1.5em; + width: 1.5em; + } +} diff --git a/client/@types/global.d.ts b/client/@types/global.d.ts index 97b336ee..1633c118 100644 --- a/client/@types/global.d.ts +++ b/client/@types/global.d.ts @@ -90,3 +90,7 @@ declare const LOC_CHATROOM_NOT_ACCESSIBLE: string declare const LOC_PROMOTE: string declare const LOC_LIVECHAT_CONFIGURATION_CHANNEL_EMOJIS_TITLE: string +declare const LOC_LIVECHAT_EMOJIS_SHORTNAME: string +declare const LOC_LIVECHAT_EMOJIS_SHORTNAME_DESC: string +declare const LOC_LIVECHAT_EMOJIS_FILE: string +declare const LOC_LIVECHAT_EMOJIS_FILE_DESC: string diff --git a/client/common/configuration/elements/channel-emojis.ts b/client/common/configuration/elements/channel-emojis.ts index 012586d2..72c874ef 100644 --- a/client/common/configuration/elements/channel-emojis.ts +++ b/client/common/configuration/elements/channel-emojis.ts @@ -4,13 +4,15 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { ChannelEmojisConfiguration } from 'shared/lib/types' +import type { DynamicFormHeader, DynamicFormSchema } from '../../lib/elements/dynamic-table-form' import { LivechatElement } from '../../lib/elements/livechat' import { registerClientOptionsContext } from '../../lib/contexts/peertube' import { ChannelDetailsService } from '../services/channel-details' import { channelDetailsServiceContext } from '../contexts/channel' import { ptTr } from '../../lib/directives/translation' +import { ValidationError } from '../../lib/models/validation' import { Task } from '@lit/task' -import { customElement, property } from 'lit/decorators.js' +import { customElement, property, state } from 'lit/decorators.js' import { provide } from '@lit/context' import { html } from 'lit' @@ -31,7 +33,30 @@ export class ChannelEmojisElement extends LivechatElement { @provide({ context: channelDetailsServiceContext }) private _channelDetailsService?: ChannelDetailsService + @state() + private _validationError?: ValidationError + protected override render = (): unknown => { + const tableHeaderList: DynamicFormHeader = { + shortname: { + colName: ptTr(LOC_LIVECHAT_EMOJIS_SHORTNAME), + description: ptTr(LOC_LIVECHAT_EMOJIS_SHORTNAME_DESC) + }, + file: { + colName: ptTr(LOC_LIVECHAT_EMOJIS_FILE), + description: ptTr(LOC_LIVECHAT_EMOJIS_FILE_DESC) + } + } + const tableSchema: DynamicFormSchema = { + shortname: { + inputType: 'text', + default: '' + }, + file: { + inputType: 'image-file', + default: '' + } + } return this._asyncTaskRender.render({ pending: () => {}, complete: () => html` @@ -49,6 +74,22 @@ export class ChannelEmojisElement extends LivechatElement { FIXME: help url OK?
+
+ { + // if (this._channelEmojisConfiguration) { + // this._channelEmojisConfiguration.configuration.emojis.customEmojis = e.detail + // this.requestUpdate('_channelEmojisConfiguration') + // } + } + } + > +