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)
|
|
|
|
event.target.value = '' // clears the textarea content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="new-message">
|
2020-11-09 09:52:34 -05:00
|
|
|
<label htmlFor="chat-input" className="sr-only">
|
|
|
|
{t('your_message')}
|
|
|
|
</label>
|
2020-10-12 06:25:59 -04:00
|
|
|
<textarea
|
2020-11-09 09:52:34 -05:00
|
|
|
id="chat-input"
|
2020-10-27 06:52:40 -04:00
|
|
|
placeholder={`${t('your_message')}…`}
|
2020-10-12 06:25:59 -04:00
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
onClick={resetUnreadMessages}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|