import { useState } from "react" import useResolution from "@/hooks/useResolution" type FileSelectProps = { onSelection: (file: File) => void } export default function FileSelect(props: FileSelectProps) { const { onSelection } = props const [uploadElemId] = useState(`file-upload-${Math.random().toString()}`) const resolution = useResolution() function onFileSelected(file: File) { if (!file) { return } // Skip non-image files const isImage = file.type.match("image.*") if (!isImage) { return } try { // Check if file is larger than 20mb if (file.size > 20 * 1024 * 1024) { throw new Error("file too large") } onSelection(file) } catch (e) { // eslint-disable-next-line alert(`error: ${(e as any).message}`) } } return (
) }