import { IconFileImport } from '@tabler/icons-react'; import { FC } from 'react'; import { useTranslation } from 'next-i18next'; import { SupportedExportFormats } from '@/types/export'; import { SidebarButton } from '../Sidebar/SidebarButton'; interface Props { onImport: (data: SupportedExportFormats) => void; } export const Import: FC = ({ onImport }) => { const { t } = useTranslation('sidebar'); return ( <> { if (!e.target.files?.length) return; const file = e.target.files[0]; const reader = new FileReader(); reader.onload = (e) => { let json = JSON.parse(e.target?.result as string); onImport(json); }; reader.readAsText(file); }} /> } onClick={() => { const importFile = document.querySelector( '#import-file', ) as HTMLInputElement; if (importFile) { importFile.click(); } }} /> ); };