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 951c84c commit a314943
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/app/chat/(desktop)/features/ChatInput/Footer/DragUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ 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 === 'string' || item.type === 'text/uri-list'
(item) => item.kind === 'string'
);

if (!allItemsAreFiles) {
const htmlData = e.dataTransfer.getData("text/html"); // web image support
var isImg = htmlData && htmlData.startsWith("<img");
if (allItemsAreFiles || isImg) {
e.preventDefault();
}
}
Expand Down Expand Up @@ -102,28 +103,29 @@ const DragUpload = memo(() => {
};

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

dragCounter.current += 1;

if (e.dataTransfer?.items && e.dataTransfer.items.length > 0) {
const allItemsAreFiles = Array.from(e.dataTransfer.items).every(
(item) => item.kind === 'string' || item.type === 'text/uri-list'
(item) => item.kind === 'string'
);

if (!allItemsAreFiles) {
const htmlData = e.dataTransfer.getData("text/html");
var isImg = htmlData && htmlData.startsWith("<img");
if (allItemsAreFiles || isImg) {
e.preventDefault();
setIsDragging(true);
}
}
};

const handleDragLeave = (e: DragEvent) => {
if (e.dataTransfer) {
if (e.dataTransfer && e.dataTransfer.items) {
const allItemsAreFiles = Array.from(e.dataTransfer.items).every(
(item) => item.kind === 'string' || item.type === 'text/uri-list'
(item) => item.kind === 'string'
);

if (!allItemsAreFiles) {
const htmlData = e.dataTransfer.getData("text/html");
var isImg = htmlData && htmlData.startsWith("<img");
if (allItemsAreFiles || isImg) {
e.preventDefault();

// reset counter
Expand All @@ -137,12 +139,13 @@ const DragUpload = memo(() => {
};

const handleDrop = async (e: DragEvent) => {
if (e.dataTransfer) {
if (e.dataTransfer && e.dataTransfer.items) {
const allItemsAreFiles = Array.from(e.dataTransfer.items).every(
(item) => item.kind === 'string' || item.type === 'text/uri-list'
(item) => item.kind === 'file'
);

if (!allItemsAreFiles) {
const htmlData = e.dataTransfer.getData("text/html");
var isImg = htmlData && htmlData.startsWith("<img");
if (allItemsAreFiles || isImg) {
e.preventDefault();
// reset counter
dragCounter.current = 0;
Expand Down

0 comments on commit a314943

Please sign in to comment.