diff --git a/assets/styles/configuration.scss b/assets/styles/configuration.scss index 3a647c8c..6947f7b1 100644 --- a/assets/styles/configuration.scss +++ b/assets/styles/configuration.scss @@ -72,7 +72,10 @@ $small-view: 800px; } input[type="submit"], - input[type="reset"] { + input[type="reset"], + button[type="submit"], + button[type="reset"], + .peertube-plugin-livechat-configuration-actions button { // Peertube rounded-line-height-1-5 mixins line-height: $button-calc-line-height; @@ -86,7 +89,9 @@ $small-view: 800px; font-size: $button-font-size; } - input[type="submit"] { + input[type="submit"], + button[type="submit"], + .peertube-plugin-livechat-configuration-actions button { // Peertube orange-button mixin &, &:active, @@ -108,7 +113,8 @@ $small-view: 800px; } } - input[type="reset"] { + input[type="reset"], + button[type="reset"] { // Peertube grey-button mixin background-color: var(--greyBackgroundColor); color: var(--greyForegroundColor); diff --git a/client/common/configuration/elements/channel-configuration.ts b/client/common/configuration/elements/channel-configuration.ts index d4e8645b..38723019 100644 --- a/client/common/configuration/elements/channel-configuration.ts +++ b/client/common/configuration/elements/channel-configuration.ts @@ -36,19 +36,40 @@ export class ChannelConfigurationElement extends LivechatElement { @state() public _validationError?: ValidationError - private readonly _asyncTaskRender = new Task(this, { - task: async ([registerClientOptions]) => { - if (registerClientOptions) { - this._channelDetailsService = new ChannelDetailsService(registerClientOptions) - this._channelConfiguration = await this._channelDetailsService.fetchConfiguration(this.channelId ?? 0) - } - }, - args: () => [this.registerClientOptions] - }) + @state() + private _actionDisabled: boolean = false + + private _asyncTaskRender: Task + + constructor () { + super() + this._asyncTaskRender = this._initTask() + } + + protected _initTask (): Task { + return new Task(this, { + task: async ([registerClientOptions]) => { + if (registerClientOptions) { + this._channelDetailsService = new ChannelDetailsService(registerClientOptions) + this._channelConfiguration = await this._channelDetailsService.fetchConfiguration(this.channelId ?? 0) + this._actionDisabled = false // in case of reset + } + }, + args: () => [this.registerClientOptions] + }) + } + + private async _reset (event?: Event): Promise { + event?.preventDefault() + this._actionDisabled = true + this._asyncTaskRender = this._initTask() + this.requestUpdate() + } private readonly _saveConfig = async (event?: Event): Promise => { event?.preventDefault() if (this._channelDetailsService && this._channelConfiguration) { + this._actionDisabled = true this._channelDetailsService.saveOptions(this._channelConfiguration.channel.id, this._channelConfiguration.configuration) .then(() => { @@ -72,6 +93,9 @@ export class ChannelConfigurationElement extends LivechatElement { ) this.requestUpdate('_validationError') }) + .finally(() => { + this._actionDisabled = false + }) } } @@ -398,7 +422,12 @@ export class ChannelConfigurationElement extends LivechatElement { `}
- + +
` diff --git a/client/common/configuration/elements/channel-emojis.ts b/client/common/configuration/elements/channel-emojis.ts index 4421fd0e..2b3a921b 100644 --- a/client/common/configuration/elements/channel-emojis.ts +++ b/client/common/configuration/elements/channel-emojis.ts @@ -37,6 +37,16 @@ export class ChannelEmojisElement extends LivechatElement { @state() private _validationError?: ValidationError + @state() + private _actionDisabled: boolean = false + + private _asyncTaskRender: Task + + constructor () { + super() + this._asyncTaskRender = this._initTask() + } + protected override render = (): unknown => { const tableHeaderList: DynamicFormHeader = { sn: { @@ -84,14 +94,22 @@ export class ChannelEmojisElement extends LivechatElement {
${ this._channelEmojisConfiguration?.emojis?.customEmojis?.length - ? html`` : '' } ${ (this._channelEmojisConfiguration?.emojis?.customEmojis?.length ?? 0) < maxEmojisPerChannel - ? html`` : '' @@ -123,7 +141,10 @@ export class ChannelEmojisElement extends LivechatElement { >
- +
@@ -136,19 +157,29 @@ export class ChannelEmojisElement extends LivechatElement { }) } - private readonly _asyncTaskRender = new Task(this, { - task: async () => { - if (!this.registerClientOptions) { - throw new Error('Missing client options') - } - if (!this.channelId) { - throw new Error('Missing channelId') - } - this._channelDetailsService = new ChannelDetailsService(this.registerClientOptions) - this._channelEmojisConfiguration = await this._channelDetailsService.fetchEmojisConfiguration(this.channelId) - }, - args: () => [] - }) + protected _initTask (): Task { + return new Task(this, { + task: async () => { + if (!this.registerClientOptions) { + throw new Error('Missing client options') + } + if (!this.channelId) { + throw new Error('Missing channelId') + } + this._channelDetailsService = new ChannelDetailsService(this.registerClientOptions) + this._channelEmojisConfiguration = await this._channelDetailsService.fetchEmojisConfiguration(this.channelId) + this._actionDisabled = false // in case of reset + }, + args: () => [] + }) + } + + private async _reset (ev?: Event): Promise { + ev?.preventDefault() + this._actionDisabled = true + this._asyncTaskRender = this._initTask() + this.requestUpdate() + } private async _saveEmojis (ev?: Event): Promise { ev?.preventDefault() @@ -161,6 +192,7 @@ export class ChannelEmojisElement extends LivechatElement { } try { + this._actionDisabled = true await this._channelDetailsService.saveEmojisConfiguration(this.channelId, this._channelEmojisConfiguration.emojis) this._validationError = undefined peertubeHelpers.notifier.info(await peertubeHelpers.translate(LOC_SUCCESSFULLY_SAVED)) @@ -177,13 +209,14 @@ export class ChannelEmojisElement extends LivechatElement { msg ??= await peertubeHelpers.translate(LOC_ERROR) peertubeHelpers.notifier.error(msg) this.requestUpdate('_validationError') + } finally { + this._actionDisabled = false } } private async _importEmojis (ev: Event): Promise { ev.preventDefault() - const b: HTMLElement | null = ev.target && 'tagName' in ev.target ? ev.target as HTMLElement : null - b?.setAttribute('disabled', '') + this._actionDisabled = true try { // download a json file: const file = await new Promise((resolve, reject) => { @@ -256,14 +289,13 @@ export class ChannelEmojisElement extends LivechatElement { } catch (err: any) { this.registerClientOptions?.peertubeHelpers.notifier.error(err.toString()) } finally { - b?.removeAttribute('disabled') + this._actionDisabled = false } } private async _exportEmojis (ev: Event): Promise { ev.preventDefault() - const b: HTMLElement | null = ev.target && 'tagName' in ev.target ? ev.target as HTMLElement : null - b?.setAttribute('disabled', '') + this._actionDisabled = true try { const result: ChannelEmojisConfiguration['emojis']['customEmojis'] = [] for (const ed of this._channelEmojisConfiguration?.emojis?.customEmojis ?? []) { @@ -293,7 +325,7 @@ export class ChannelEmojisElement extends LivechatElement { console.error(err) this.registerClientOptions?.peertubeHelpers.notifier.error(err.toString()) } finally { - b?.removeAttribute('disabled') + this._actionDisabled = false } }