Commit d8cfcc9e authored by Joel's avatar Joel

fix: input method enter also send message

parent f5432694
'use client' 'use client'
import type { FC } from 'react' import type { FC, } from 'react'
import React, { useEffect } from 'react' import React, { useEffect, useRef } from 'react'
import cn from 'classnames' import cn from 'classnames'
import { HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline' import { HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
...@@ -232,6 +232,7 @@ const Chat: FC<IChatProps> = ({ ...@@ -232,6 +232,7 @@ const Chat: FC<IChatProps> = ({
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { notify } = Toast const { notify } = Toast
const isUseInputMethod = useRef(false)
const [query, setQuery] = React.useState('') const [query, setQuery] = React.useState('')
const handleContentChange = (e: any) => { const handleContentChange = (e: any) => {
...@@ -267,12 +268,15 @@ const Chat: FC<IChatProps> = ({ ...@@ -267,12 +268,15 @@ const Chat: FC<IChatProps> = ({
const handleKeyUp = (e: any) => { const handleKeyUp = (e: any) => {
if (e.code === 'Enter') { if (e.code === 'Enter') {
e.preventDefault() e.preventDefault()
if (!e.shiftKey) // prevent send message when using input method enter
if (!e.shiftKey && !isUseInputMethod.current) {
handleSend() handleSend()
}
} }
} }
const haneleKeyDown = (e: any) => { const haneleKeyDown = (e: any) => {
isUseInputMethod.current = e.nativeEvent.isComposing
if (e.code === 'Enter' && !e.shiftKey) { if (e.code === 'Enter' && !e.shiftKey) {
setQuery(query.replace(/\n$/, '')) setQuery(query.replace(/\n$/, ''))
e.preventDefault() e.preventDefault()
......
...@@ -3,7 +3,7 @@ export const APP_ID = '' ...@@ -3,7 +3,7 @@ export const APP_ID = ''
export const API_KEY = '' export const API_KEY = ''
export const APP_INFO: AppInfo = { export const APP_INFO: AppInfo = {
"title": 'Chat APP', "title": 'Chat APP11',
"description": '', "description": '',
"copyright": '', "copyright": '',
"privacy_policy": '', "privacy_policy": '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment