Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First pass at allowing image pasting on the infraction modal
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 477fe04 commit 51d2da3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions components/NewInfractionModal.tsx
Expand Up @@ -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
Expand Down

0 comments on commit 51d2da3

Please sign in to comment.