import { Group, Text, useMantineTheme, MantineTheme } from '@mantine/core'; import { Upload, Photo, X, Icon as TablerIcon, Check } from 'tabler-icons-react'; import { DropzoneStatus, FullScreenDropzone } from '@mantine/dropzone'; import { showNotification } from '@mantine/notifications'; import { useRef } from 'react'; import { useRouter } from 'next/router'; import { useConfig } from '../../tools/state'; import { Config } from '../../tools/types'; function getIconColor(status: DropzoneStatus, theme: MantineTheme) { return status.accepted ? theme.colors[theme.primaryColor][theme.colorScheme === 'dark' ? 4 : 6] : status.rejected ? theme.colors.red[theme.colorScheme === 'dark' ? 4 : 6] : theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.colors.gray[7]; } function ImageUploadIcon({ status, ...props }: React.ComponentProps & { status: DropzoneStatus }) { if (status.accepted) { return ; } if (status.rejected) { return ; } return ; } export const dropzoneChildren = (status: DropzoneStatus, theme: MantineTheme) => (
Drag images here or click to select files Attach as many files as you like, each file should not exceed 5mb
); export default function LoadConfigComponent(props: any) { const { saveConfig, setConfig } = useConfig(); const theme = useMantineTheme(); const router = useRouter(); const openRef = useRef<() => void>(); return ( { files[0].text().then((e) => { try { JSON.parse(e) as Config; } catch (e) { showNotification({ autoClose: 5000, title: Error, color: 'red', icon: , message: 'could not load your config. Invalid JSON format.', }); return; } showNotification({ autoClose: 5000, radius: 'md', title: Config loaded successfully, color: 'green', icon: , message: undefined, }); setConfig(JSON.parse(e)); }); }} accept={['application/json']} > {(status) => dropzoneChildren(status, theme)} ); }