Fix the flickering issue when dragging files over the chat window

This commit is contained in:
Ilango 2024-01-22 15:51:05 +05:30
parent 7e5d8e7294
commit 59643b65d9
2 changed files with 44 additions and 35 deletions

View File

@ -119,16 +119,34 @@
.cloud-dialog-wrapper { .cloud-dialog-wrapper {
width: 400px; width: 400px;
height: calc(100vh - 260px); height: calc(100vh - 260px);
display: flex;
align-items: start;
justify-content: start;
flex-direction: column;
} }
.cloud-dialog-wrapper { .cloud-dialog-wrapper {
width: 100%; width: 100%;
} }
.cloud-wrapper > div,
.cloud-dialog-wrapper > div {
width: 100%;
height: 100%;
display: flex;
align-items: start;
justify-content: start;
flex-direction: column;
position: relative;
}
.image-dropzone {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 2001; /* Ensure it's above other content */
}
.cloud, .cloud,
.cloud-dialog { .cloud-dialog {
width: 100%; width: 100%;

View File

@ -91,7 +91,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
const fileUploadRef = useRef(null) const fileUploadRef = useRef(null)
const [isChatFlowAvailableForUploads, setIsChatFlowAvailableForUploads] = useState(false) const [isChatFlowAvailableForUploads, setIsChatFlowAvailableForUploads] = useState(false)
const [previews, setPreviews] = useState([]) const [previews, setPreviews] = useState([])
const [isDragOver, setIsDragOver] = useState(false) const [isDragActive, setIsDragActive] = useState(false)
// recording // recording
const [isRecording, setIsRecording] = useState(false) const [isRecording, setIsRecording] = useState(false)
@ -123,8 +123,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
return return
} }
e.preventDefault() e.preventDefault()
e.stopPropagation() setIsDragActive(false)
setIsDragOver(false)
let files = [] let files = []
if (e.dataTransfer.files.length > 0) { if (e.dataTransfer.files.length > 0) {
for (const file of e.dataTransfer.files) { for (const file of e.dataTransfer.files) {
@ -251,28 +250,17 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
} }
} }
const handleDragOver = (e) => { const handleDrag = (e) => {
e.preventDefault()
e.stopPropagation()
}
const handleDragEnter = (e) => {
if (isChatFlowAvailableForUploads) { if (isChatFlowAvailableForUploads) {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
setIsDragOver(true) if (e.type === 'dragenter' || e.type === 'dragover') {
} console.log('drag enter')
} setIsDragActive(true)
} else if (e.type === 'dragleave') {
const handleDragLeave = (e) => { console.log('drag leave')
if (isChatFlowAvailableForUploads) { setIsDragActive(false)
e.preventDefault()
e.stopPropagation()
if (e.originalEvent?.pageX !== 0 || e.originalEvent?.pageY !== 0) {
setIsDragOver(false)
return false
} }
setIsDragOver(false)
} }
} }
@ -599,8 +587,17 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
}, [open, chatflowid]) }, [open, chatflowid])
return ( return (
<> <div onDragEnter={handleDrag}>
{isDragOver && getAllowChatFlowUploads.data?.isUploadAllowed && ( {isDragActive && (
<div
className='image-dropzone'
onDragEnter={handleDrag}
onDragLeave={handleDrag}
onDragEnd={handleDrag}
onDrop={handleDrop}
/>
)}
{isDragActive && getAllowChatFlowUploads.data?.isUploadAllowed && (
<Box className='drop-overlay'> <Box className='drop-overlay'>
<Typography variant='h2'>Drop here to upload</Typography> <Typography variant='h2'>Drop here to upload</Typography>
{getAllowChatFlowUploads.data.uploadFileSizeAndTypes.map((allowed) => { {getAllowChatFlowUploads.data.uploadFileSizeAndTypes.map((allowed) => {
@ -648,13 +645,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
)} )}
</Box> </Box>
)} )}
<div <div className={`${isDialog ? 'cloud-dialog' : 'cloud'}`}>
onDragOver={handleDragOver}
onDragEnter={handleDragEnter}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
className={`${isDialog ? 'cloud-dialog' : 'cloud'}`}
>
<div ref={ps} id='messagelist' className={'messagelist'}> <div ref={ps} id='messagelist' className={'messagelist'}>
{messages && {messages &&
messages.map((message, index) => { messages.map((message, index) => {
@ -959,7 +950,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
</form> </form>
</div> </div>
<SourceDocDialog show={sourceDialogOpen} dialogProps={sourceDialogProps} onCancel={() => setSourceDialogOpen(false)} /> <SourceDocDialog show={sourceDialogOpen} dialogProps={sourceDialogProps} onCancel={() => setSourceDialogOpen(false)} />
</> </div>
) )
} }