Skip to content

Commit

Permalink
fix drag
Browse files Browse the repository at this point in the history
  • Loading branch information
sxjeru committed Apr 20, 2024
1 parent 17f6b05 commit d85ac5b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/app/chat/(desktop)/features/ChatInput/Footer/DragUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const useStyles = createStyles(({ css, token, stylish }) => {
const handleDragOver = (e: DragEvent) => {
if (e.dataTransfer?.items && e.dataTransfer.items.length > 0) {
const allItemsAreFiles = Array.from(e.dataTransfer.items).every(
(item) => item.kind === 'file' || item.type === 'text/uri-list' // Web page images
(item) => item.kind === 'file' || item.type.startsWith('text/html') // Web page images
);

if (allItemsAreFiles) {
Expand Down Expand Up @@ -107,7 +107,7 @@ const DragUpload = memo(() => {
dragCounter.current += 1;
if (e.dataTransfer?.items && e.dataTransfer.items.length > 0) {
const allItemsAreFiles = Array.from(e.dataTransfer.items).every(
(item) => item.kind === 'file' || item.type === 'text/uri-list'
(item) => item.kind === 'file' || item.type.startsWith('text/html')
);

if (allItemsAreFiles) {
Expand All @@ -118,13 +118,21 @@ const DragUpload = memo(() => {
};

const handleDragLeave = (e: DragEvent) => {
e.preventDefault();

// reset counter
dragCounter.current -= 1;

if (dragCounter.current === 0) {
setIsDragging(false);
if (e.dataTransfer) {
const allItemsAreFiles = Array.from(e.dataTransfer.items).every(
(item) => item.kind === 'file' || item.type.startsWith('text/html') // Web page images
);

if (allItemsAreFiles) {
e.preventDefault();

// reset counter
dragCounter.current -= 1;

if (dragCounter.current === 0) {
setIsDragging(false);
}
}
}
};

Expand Down

0 comments on commit d85ac5b

Please sign in to comment.