discourse/plugins/chat/assets/javascripts/discourse/components/chat-composer.hbs
Joffrey JAFFEUX 2d567cee26
FEATURE: thread pagination (#22624)
Prior to this commit we were loading a large number of thread messages without any pagination. This commit attempts to fix this and also improves the following points:

- code sharing between channels and threads:
Attempts to reuse/share the code use in channels for threads. To make it possible part of this code has been extracted in dedicated helpers or has been improved to reduce the duplication needed.

Examples of extracted helpers:
- `stackingContextFix`: the ios hack for rendering bug when momentum scrolling is interrupted
- `scrollListToMessage`, `scrollListToTop`, `scrollListToBottom`:  a series of helper to correctly scroll to a specific position in the list of messages

- better general performance of listing messages:
One of the main changes which has been made is to remove the computation of visible message during scroll, it will only happen when needed (update last read for example). This constant recomputation of `message.visible` on intersection observer event while scrolling was consuming a lot of CPU time.
2023-07-27 09:57:03 +02:00

129 lines
4.2 KiB
Handlebars

{{! template-lint-disable no-pointer-down-event-binding }}
{{! template-lint-disable no-invalid-interactive }}
<div class="chat-composer__wrapper">
{{#if this.shouldRenderMessageDetails}}
<ChatComposerMessageDetails
@message={{if
this.currentMessage.editing
this.currentMessage
this.currentMessage.inReplyTo
}}
@cancelAction={{this.composer.cancel}}
/>
{{/if}}
<div
role="region"
aria-label={{i18n "chat.aria_roles.composer"}}
class={{concat-class
"chat-composer"
(if this.isFocused "is-focused")
(if this.pane.sending "is-sending")
(if this.sendEnabled "is-send-enabled" "is-send-disabled")
(if this.disabled "is-disabled" "is-enabled")
(if this.currentMessage.draftSaved "is-draft-saved" "is-draft-unsaved")
}}
{{did-update this.didUpdateMessage this.currentMessage}}
{{did-update this.didUpdateInReplyTo this.currentMessage.inReplyTo}}
{{did-insert this.setup}}
{{will-destroy this.teardown}}
{{will-destroy this.cancelPersistDraft}}
>
<div class="chat-composer__outer-container">
<div class="chat-composer__inner-container">
<ChatComposerDropdown
@buttons={{this.dropdownButtons}}
@isDisabled={{this.disabled}}
@hasActivePanel={{eq
this.chatEmojiPickerManager.picker.context
this.context
}}
@onCloseActivePanel={{this.chatEmojiPickerManager.close}}
{{on "focus" (fn this.computeIsFocused true)}}
{{on "blur" (fn this.computeIsFocused false)}}
/>
<div
class="chat-composer__input-container"
{{on "click" this.composer.focus}}
>
<DTextarea
id={{this.composerId}}
value={{readonly this.currentMessage.message}}
type="text"
class="chat-composer__input"
disabled={{this.disabled}}
autocorrect="on"
autocapitalize="sentences"
placeholder={{this.placeholder}}
rows={{1}}
{{did-insert this.setupTextareaInteractor}}
{{on "input" this.onInput}}
{{on "keydown" this.onKeyDown}}
{{on "focusin" this.onTextareaFocusIn}}
{{on "focusin" (fn this.computeIsFocused true)}}
{{on "focusout" (fn this.computeIsFocused false)}}
{{did-insert this.setupAutocomplete}}
data-chat-composer-context={{this.context}}
/>
</div>
{{#if this.inlineButtons.length}}
{{#each this.inlineButtons as |button|}}
<Chat::Composer::Button
@icon={{button.icon}}
class="-{{button.id}}"
disabled={{or this.disabled button.disabled}}
tabindex={{if button.disabled -1 0}}
{{on
"click"
(fn this.handleInlineButonAction button.action)
bubbles=false
}}
{{on "focus" (fn this.computeIsFocused true)}}
{{on "blur" (fn this.computeIsFocused false)}}
/>
{{/each}}
<Chat::Composer::Separator />
{{/if}}
<Chat::Composer::Button
@icon="paper-plane"
class="-send"
title={{i18n "chat.composer.send"}}
disabled={{or this.disabled (not this.sendEnabled)}}
tabindex={{if this.sendEnabled 0 -1}}
{{on "click" this.onSend}}
{{on "mousedown" this.trapMouseDown}}
{{on "focus" (fn this.computeIsFocused true)}}
{{on "blur" (fn this.computeIsFocused false)}}
/>
</div>
</div>
</div>
{{#if this.canAttachUploads}}
<ChatComposerUploads
@fileUploadElementId={{this.fileUploadElementId}}
@onUploadChanged={{this.onUploadChanged}}
@existingUploads={{this.currentMessage.uploads}}
@uploadDropZone={{@uploadDropZone}}
@composerInputEl={{this.composer.textarea.element}}
/>
{{/if}}
{{#if this.shouldRenderReplyingIndicator}}
<div class="chat-replying-indicator-container">
<ChatReplyingIndicator
@presenceChannelName={{this.presenceChannelName}}
/>
</div>
{{/if}}
<ChatEmojiPicker
@context={{this.context}}
@didSelectEmoji={{this.onSelectEmoji}}
/>
</div>