mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +03:00
update chat message layout and fix when first start prompt clicked but not sent
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
.button-container {
|
.button-container {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
z-index: 1000;
|
||||||
display: flex;
|
display: flex;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
-webkit-overflow-scrolling: touch; /* For momentum scroll on mobile devices */
|
-webkit-overflow-scrolling: touch; /* For momentum scroll on mobile devices */
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Button } from '@mui/material'
|
import { Chip } from '@mui/material'
|
||||||
import './StarterPromptsCard.css'
|
import './StarterPromptsCard.css'
|
||||||
|
|
||||||
const StarterPromptsCard = ({ isGrid, starterPrompts, onPromptClick }) => {
|
const StarterPromptsCard = ({ isGrid, starterPrompts, onPromptClick }) => {
|
||||||
return (
|
return (
|
||||||
<Box className={'button-container'} sx={{ maxWidth: isGrid ? 'inherit' : '400px' }}>
|
<Box className={'button-container'} sx={{ maxWidth: isGrid ? 'inherit' : '400px', m: 1 }}>
|
||||||
{starterPrompts.map((sp, index) => (
|
{starterPrompts.map((sp, index) => (
|
||||||
<Button variant='outlined' className={'button'} key={index} onClick={(e) => onPromptClick(sp.prompt, e)}>
|
<Chip label={sp.prompt} className={'button'} key={index} onClick={(e) => onPromptClick(sp.prompt, e)} />
|
||||||
{sp.prompt}
|
|
||||||
</Button>
|
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -108,26 +108,30 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
|
|||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePromptClick = async (prompt, e) => {
|
const handlePromptClick = async (promptStarterInput) => {
|
||||||
setUserInput(prompt)
|
setUserInput(promptStarterInput)
|
||||||
await handleSubmit(e)
|
handleSubmit(undefined, promptStarterInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle form submission
|
// Handle form submission
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e, promptStarterInput) => {
|
||||||
e.preventDefault()
|
if (e) e.preventDefault()
|
||||||
|
|
||||||
if (userInput.trim() === '') {
|
if (!promptStarterInput && userInput.trim() === '') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let input = userInput
|
||||||
|
|
||||||
|
if (promptStarterInput !== undefined && promptStarterInput.trim() !== '') input = promptStarterInput
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setMessages((prevMessages) => [...prevMessages, { message: userInput, type: 'userMessage' }])
|
setMessages((prevMessages) => [...prevMessages, { message: input, type: 'userMessage' }])
|
||||||
|
|
||||||
// Send user question and history to API
|
// Send user question and history to API
|
||||||
try {
|
try {
|
||||||
const params = {
|
const params = {
|
||||||
question: userInput,
|
question: input,
|
||||||
history: messages.filter((msg) => msg.message !== 'Hi there! How can I help?'),
|
history: messages.filter((msg) => msg.message !== 'Hi there! How can I help?'),
|
||||||
chatId
|
chatId
|
||||||
}
|
}
|
||||||
@@ -439,13 +443,16 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Divider />
|
|
||||||
|
<div style={{ position: 'relative' }}>
|
||||||
|
{messages && messages.length === 1 && (
|
||||||
|
<StarterPromptsCard starterPrompts={starterPrompts || []} onPromptClick={handlePromptClick} isGrid={isDialog} />
|
||||||
|
)}
|
||||||
|
<Divider />
|
||||||
|
</div>
|
||||||
<div className='center'>
|
<div className='center'>
|
||||||
<div style={{ width: '100%' }}>
|
<div style={{ width: '100%' }}>
|
||||||
<form style={{ width: '100%' }} onSubmit={handleSubmit}>
|
<form style={{ width: '100%' }} onSubmit={handleSubmit}>
|
||||||
{messages && messages.length === 1 && (
|
|
||||||
<StarterPromptsCard starterPrompts={starterPrompts || []} onPromptClick={handlePromptClick} isGrid={isDialog} />
|
|
||||||
)}
|
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
|
|||||||
Reference in New Issue
Block a user