diff --git a/components/NewInfractionModal.tsx b/components/NewInfractionModal.tsx index 6c3c51e..3a13331 100644 --- a/components/NewInfractionModal.tsx +++ b/components/NewInfractionModal.tsx @@ -14,6 +14,32 @@ import { } from "@chakra-ui/react"; export default function (props: { isOpen: boolean; onClose: () => void }) { + addEventListener("paste", (e) => { + if (!props.isOpen) return; + + const evidenceElement = document.getElementById( + "evidence" + ) as HTMLInputElement; + + if (!evidenceElement.files && e.clipboardData?.files) { + evidenceElement.files = e.clipboardData.files; + return; + } + + if (!evidenceElement.files || !e.clipboardData?.files.length) return; + + if (typeof window["DataTransfer"] === "undefined") + return alert("Your browser is too old to paste images in."); + + const dataTransfer = new DataTransfer(); + + for (const file of evidenceElement.files) dataTransfer.items.add(file); + + dataTransfer.items.add(e.clipboardData.files[0]); + + evidenceElement.files = dataTransfer.files; + }); + function reset() { ( document.getElementById("punishment") as unknown as HTMLSelectElement