-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdb1830
commit 338af09
Showing
7 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
client/web/src/components/ChatBox/ChatInputBox/ChatDropArea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import { t, useMemoizedFn } from 'tailchat-shared'; | ||
import { DropTargetMonitor, useDrop } from 'react-dnd'; | ||
import { NativeTypes } from 'react-dnd-html5-backend'; | ||
import { useChatInputActionContext } from './context'; | ||
import { uploadMessageImage } from './utils'; | ||
import { getMessageTextDecorators } from '@/plugin/common'; | ||
import { Icon } from 'tailchat-design'; | ||
|
||
export const ChatDropArea: React.FC = React.memo(() => { | ||
const actionContext = useChatInputActionContext(); | ||
|
||
const handleDrop = useMemoizedFn((files: File[]) => { | ||
const images = files.filter((f) => f.type.startsWith('image/')); | ||
if (images.length > 0) { | ||
// 目前只取一张 | ||
const img = images[0]; | ||
uploadMessageImage(img).then(({ url, width, height }) => { | ||
actionContext?.sendMsg( | ||
getMessageTextDecorators().image(url, { width, height }) | ||
); | ||
}); | ||
} | ||
}); | ||
|
||
const [collectedProps, ref] = useDrop({ | ||
accept: [NativeTypes.FILE], | ||
drop(item: { files: any[] }) { | ||
handleDrop(item.files); | ||
}, | ||
canDrop(item: any) { | ||
return true; | ||
}, | ||
collect: (monitor: DropTargetMonitor) => { | ||
return { | ||
isOver: monitor.isOver(), | ||
canDrop: monitor.canDrop(), | ||
}; | ||
}, | ||
}); | ||
|
||
if (!collectedProps.canDrop) { | ||
return; | ||
} | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
className={ | ||
'absolute inset-0 bg-white bg-opacity-50 dark:bg-black dark:bg-opacity-50 p-4' | ||
} | ||
> | ||
<div className="h-full w-full border-dashed border-8 flex flex-col justify-center items-center"> | ||
<div> | ||
<Icon icon="mdi:cloud-upload" fontSize={128} /> | ||
</div> | ||
<div className="text-xl font-bold">{t('拖放文件以发送到当前会话')}</div> | ||
</div> | ||
</div> | ||
); | ||
}); | ||
ChatDropArea.displayName = 'ChatDropArea'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.