mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
7a7689e9c5
Jdt improve character selection chat GitOrigin-RevId: 9d9f22aeda5e333e807b710f8ea14bbd47dc7f0c
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import PropTypes from 'prop-types'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
type MessageInputProps = {
|
|
resetUnreadMessages: () => void
|
|
sendMessage: (message: string) => void
|
|
}
|
|
|
|
function MessageInput({ resetUnreadMessages, sendMessage }: MessageInputProps) {
|
|
const { t } = useTranslation()
|
|
|
|
function handleKeyDown(event: React.KeyboardEvent) {
|
|
const selectingCharacter = event.nativeEvent.isComposing
|
|
if (event.key === 'Enter' && !selectingCharacter) {
|
|
event.preventDefault()
|
|
const target = event.target as HTMLInputElement
|
|
sendMessage(target.value)
|
|
// wrap the form reset in setTimeout so input sources have time to finish
|
|
// https://github.com/overleaf/internal/pull/9206
|
|
window.setTimeout(() => {
|
|
target.blur()
|
|
target.closest('form')?.reset()
|
|
target.focus()
|
|
}, 0)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form className="new-message">
|
|
<label htmlFor="chat-input" className="sr-only">
|
|
{t('your_message_to_collaborators')}
|
|
</label>
|
|
<textarea
|
|
id="chat-input"
|
|
placeholder={`${t('your_message_to_collaborators')}…`}
|
|
onKeyDown={handleKeyDown}
|
|
onClick={resetUnreadMessages}
|
|
/>
|
|
</form>
|
|
)
|
|
}
|
|
|
|
MessageInput.propTypes = {
|
|
resetUnreadMessages: PropTypes.func.isRequired,
|
|
sendMessage: PropTypes.func.isRequired,
|
|
}
|
|
|
|
export default MessageInput
|