2020-10-12 06:25:59 -04:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
|
|
|
|
function MessageInput({ resetUnreadMessages, sendMessage }) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
function handleKeyDown(event) {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
event.preventDefault()
|
|
|
|
sendMessage(event.target.value)
|
2022-08-11 05:16:24 -04:00
|
|
|
// wrap the form reset in setTimeout so input sources have time to finish
|
|
|
|
// https://github.com/overleaf/internal/pull/9206
|
|
|
|
window.setTimeout(() => {
|
|
|
|
event.target.blur()
|
|
|
|
event.target.closest('form').reset()
|
|
|
|
event.target.focus()
|
|
|
|
}, 0)
|
2020-10-12 06:25:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-08-11 05:16:24 -04:00
|
|
|
<form className="new-message">
|
2020-11-09 09:52:34 -05:00
|
|
|
<label htmlFor="chat-input" className="sr-only">
|
2022-10-03 11:22:47 -04:00
|
|
|
{t('your_message_to_collaborators')}
|
2020-11-09 09:52:34 -05:00
|
|
|
</label>
|
2020-10-12 06:25:59 -04:00
|
|
|
<textarea
|
2020-11-09 09:52:34 -05:00
|
|
|
id="chat-input"
|
2022-10-03 11:22:47 -04:00
|
|
|
placeholder={`${t('your_message_to_collaborators')}…`}
|
2020-10-12 06:25:59 -04:00
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
onClick={resetUnreadMessages}
|
|
|
|
/>
|
2022-08-11 05:16:24 -04:00
|
|
|
</form>
|
2020-10-12 06:25:59 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageInput.propTypes = {
|
|
|
|
resetUnreadMessages: PropTypes.func.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
sendMessage: PropTypes.func.isRequired,
|
2020-10-12 06:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default MessageInput
|