mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
allow dropping files as input
This commit is contained in:
parent
5160f906f4
commit
4eb49ca90d
1 changed files with 23 additions and 9 deletions
|
@ -137,6 +137,11 @@ function Modal({ modalProps }: { modalProps: ModalProps; }) {
|
||||||
const [blob, setBlob] = useState<Blob>();
|
const [blob, setBlob] = useState<Blob>();
|
||||||
const [blobUrl, setBlobUrl] = useObjectUrl();
|
const [blobUrl, setBlobUrl] = useObjectUrl();
|
||||||
|
|
||||||
|
const setAudioBlob = blob => {
|
||||||
|
setBlob(blob);
|
||||||
|
setBlobUrl(blob);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => () => {
|
useEffect(() => () => {
|
||||||
if (blobUrl)
|
if (blobUrl)
|
||||||
URL.revokeObjectURL(blobUrl);
|
URL.revokeObjectURL(blobUrl);
|
||||||
|
@ -182,6 +187,16 @@ function Modal({ modalProps }: { modalProps: ModalProps; }) {
|
||||||
|| blob.type.includes("codecs") && !blob.type.includes("opus")
|
|| blob.type.includes("codecs") && !blob.type.includes("opus")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleDrop = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const file = event.dataTransfer.files[0];
|
||||||
|
if (file) setAudioBlob(file);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDragOver = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalRoot {...modalProps}>
|
<ModalRoot {...modalProps}>
|
||||||
<ModalHeader>
|
<ModalHeader>
|
||||||
|
@ -189,22 +204,21 @@ function Modal({ modalProps }: { modalProps: ModalProps; }) {
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
|
|
||||||
<ModalContent className={cl("modal")}>
|
<ModalContent className={cl("modal")}>
|
||||||
<div className={cl("buttons")}>
|
<div
|
||||||
|
onDrop={handleDrop}
|
||||||
|
onDragOver={handleDragOver}
|
||||||
|
className={cl("buttons")}
|
||||||
|
>
|
||||||
|
|
||||||
<VoiceRecorder
|
<VoiceRecorder
|
||||||
setAudioBlob={blob => {
|
setAudioBlob={blob => setAudioBlob(blob)}
|
||||||
setBlob(blob);
|
|
||||||
setBlobUrl(blob);
|
|
||||||
}}
|
|
||||||
onRecordingChange={setRecording}
|
onRecordingChange={setRecording}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const file = await chooseFile("audio/*");
|
const file = await chooseFile("audio/*");
|
||||||
if (file) {
|
if (file) setAudioBlob(file);
|
||||||
setBlob(file);
|
|
||||||
setBlobUrl(file);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Upload File
|
Upload File
|
||||||
|
|
Loading…
Add table
Reference in a new issue