mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 09:56:03 +08:00
fix: start chat check & chat send button theme
This commit is contained in:
parent
7abe76f07e
commit
fd6476b941
@ -37,6 +37,8 @@ import type {
|
|||||||
import { useToastContext } from '@/app/components/base/toast'
|
import { useToastContext } from '@/app/components/base/toast'
|
||||||
import { changeLanguage } from '@/i18n/i18next-config'
|
import { changeLanguage } from '@/i18n/i18next-config'
|
||||||
import { useAppFavicon } from '@/hooks/use-app-favicon'
|
import { useAppFavicon } from '@/hooks/use-app-favicon'
|
||||||
|
import { InputVarType } from '@/app/components/workflow/types'
|
||||||
|
import { TransferMethod } from '@/types/app'
|
||||||
|
|
||||||
export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
||||||
const isInstalledApp = useMemo(() => !!installedAppInfo, [installedAppInfo])
|
const isInstalledApp = useMemo(() => !!installedAppInfo, [installedAppInfo])
|
||||||
@ -220,21 +222,38 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => {
|
|||||||
|
|
||||||
const { notify } = useToastContext()
|
const { notify } = useToastContext()
|
||||||
const checkInputsRequired = useCallback((silent?: boolean) => {
|
const checkInputsRequired = useCallback((silent?: boolean) => {
|
||||||
if (inputsForms.length) {
|
let hasEmptyInput = ''
|
||||||
for (let i = 0; i < inputsForms.length; i += 1) {
|
let fileIsUploading = false
|
||||||
const item = inputsForms[i]
|
const requiredVars = inputsForms.filter(({ required }) => required)
|
||||||
|
if (requiredVars.length) {
|
||||||
if (item.required && !newConversationInputsRef.current[item.variable]) {
|
requiredVars.forEach(({ variable, label, type }) => {
|
||||||
if (!silent) {
|
if (hasEmptyInput)
|
||||||
notify({
|
|
||||||
type: 'error',
|
|
||||||
message: t('appDebug.errorMessage.valueOfVarRequired', { key: item.variable }),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if (fileIsUploading)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (!newConversationInputsRef.current[variable] && !silent)
|
||||||
|
hasEmptyInput = label as string
|
||||||
|
|
||||||
|
if ((type === InputVarType.singleFile || type === InputVarType.multiFiles) && newConversationInputsRef.current[variable] && !silent) {
|
||||||
|
const files = newConversationInputsRef.current[variable]
|
||||||
|
if (Array.isArray(files))
|
||||||
|
fileIsUploading = files.find(item => item.transferMethod === TransferMethod.local_file && !item.uploadedId)
|
||||||
|
else
|
||||||
|
fileIsUploading = files.transferMethod === TransferMethod.local_file && !files.uploadedId
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return true
|
}
|
||||||
|
|
||||||
|
if (hasEmptyInput) {
|
||||||
|
notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput }) })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileIsUploading) {
|
||||||
|
notify({ type: 'info', message: t('appDebug.errorMessage.waitForFileUpload') })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -50,7 +50,7 @@ const ChatInputArea = ({
|
|||||||
onSend,
|
onSend,
|
||||||
inputs = {},
|
inputs = {},
|
||||||
inputsForm = [],
|
inputsForm = [],
|
||||||
// theme,
|
theme,
|
||||||
}: ChatInputAreaProps) => {
|
}: ChatInputAreaProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { notify } = useToastContext()
|
const { notify } = useToastContext()
|
||||||
@ -127,6 +127,7 @@ const ChatInputArea = ({
|
|||||||
speechToTextConfig={speechToTextConfig}
|
speechToTextConfig={speechToTextConfig}
|
||||||
onShowVoiceInput={handleShowVoiceInput}
|
onShowVoiceInput={handleShowVoiceInput}
|
||||||
onSend={handleSend}
|
onSend={handleSend}
|
||||||
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
import type {
|
import type {
|
||||||
EnableType,
|
EnableType,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
|
import type { Theme } from '../../embedded-chatbot/theme/theme-context'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
import ActionButton from '@/app/components/base/action-button'
|
import ActionButton from '@/app/components/base/action-button'
|
||||||
import { FileUploaderInChatInput } from '@/app/components/base/file-uploader'
|
import { FileUploaderInChatInput } from '@/app/components/base/file-uploader'
|
||||||
@ -20,12 +21,14 @@ type OperationProps = {
|
|||||||
speechToTextConfig?: EnableType
|
speechToTextConfig?: EnableType
|
||||||
onShowVoiceInput?: () => void
|
onShowVoiceInput?: () => void
|
||||||
onSend: () => void
|
onSend: () => void
|
||||||
|
theme?: Theme | null
|
||||||
}
|
}
|
||||||
const Operation = forwardRef<HTMLDivElement, OperationProps>(({
|
const Operation = forwardRef<HTMLDivElement, OperationProps>(({
|
||||||
fileConfig,
|
fileConfig,
|
||||||
speechToTextConfig,
|
speechToTextConfig,
|
||||||
onShowVoiceInput,
|
onShowVoiceInput,
|
||||||
onSend,
|
onSend,
|
||||||
|
theme,
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -54,6 +57,13 @@ const Operation = forwardRef<HTMLDivElement, OperationProps>(({
|
|||||||
className='ml-3 px-0 w-8'
|
className='ml-3 px-0 w-8'
|
||||||
variant='primary'
|
variant='primary'
|
||||||
onClick={onSend}
|
onClick={onSend}
|
||||||
|
style={
|
||||||
|
theme
|
||||||
|
? {
|
||||||
|
backgroundColor: theme.primaryColor,
|
||||||
|
}
|
||||||
|
: {}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<RiSendPlane2Fill className='w-4 h-4' />
|
<RiSendPlane2Fill className='w-4 h-4' />
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -30,6 +30,8 @@ import type {
|
|||||||
} from '@/models/share'
|
} from '@/models/share'
|
||||||
import { useToastContext } from '@/app/components/base/toast'
|
import { useToastContext } from '@/app/components/base/toast'
|
||||||
import { changeLanguage } from '@/i18n/i18next-config'
|
import { changeLanguage } from '@/i18n/i18next-config'
|
||||||
|
import { InputVarType } from '@/app/components/workflow/types'
|
||||||
|
import { TransferMethod } from '@/types/app'
|
||||||
|
|
||||||
export const useEmbeddedChatbot = () => {
|
export const useEmbeddedChatbot = () => {
|
||||||
const isInstalledApp = false
|
const isInstalledApp = false
|
||||||
@ -206,21 +208,38 @@ export const useEmbeddedChatbot = () => {
|
|||||||
|
|
||||||
const { notify } = useToastContext()
|
const { notify } = useToastContext()
|
||||||
const checkInputsRequired = useCallback((silent?: boolean) => {
|
const checkInputsRequired = useCallback((silent?: boolean) => {
|
||||||
if (inputsForms.length) {
|
let hasEmptyInput = ''
|
||||||
for (let i = 0; i < inputsForms.length; i += 1) {
|
let fileIsUploading = false
|
||||||
const item = inputsForms[i]
|
const requiredVars = inputsForms.filter(({ required }) => required)
|
||||||
|
if (requiredVars.length) {
|
||||||
if (item.required && !newConversationInputsRef.current[item.variable]) {
|
requiredVars.forEach(({ variable, label, type }) => {
|
||||||
if (!silent) {
|
if (hasEmptyInput)
|
||||||
notify({
|
|
||||||
type: 'error',
|
|
||||||
message: t('appDebug.errorMessage.valueOfVarRequired', { key: item.variable }),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if (fileIsUploading)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (!newConversationInputsRef.current[variable] && !silent)
|
||||||
|
hasEmptyInput = label as string
|
||||||
|
|
||||||
|
if ((type === InputVarType.singleFile || type === InputVarType.multiFiles) && newConversationInputsRef.current[variable] && !silent) {
|
||||||
|
const files = newConversationInputsRef.current[variable]
|
||||||
|
if (Array.isArray(files))
|
||||||
|
fileIsUploading = files.find(item => item.transferMethod === TransferMethod.local_file && !item.uploadedId)
|
||||||
|
else
|
||||||
|
fileIsUploading = files.transferMethod === TransferMethod.local_file && !files.uploadedId
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return true
|
}
|
||||||
|
|
||||||
|
if (hasEmptyInput) {
|
||||||
|
notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: hasEmptyInput }) })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileIsUploading) {
|
||||||
|
notify({ type: 'info', message: t('appDebug.errorMessage.waitForFileUpload') })
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user