import { t, Trans } from "@lingui/macro"
import { Box, Button, FileInput, Group, Stack } from "@mantine/core"
import { useForm } from "@mantine/form"
import { client, errorToStrings } from "app/client"
import { redirectToSelectedSource } from "app/slices/redirect"
import { reloadTree } from "app/slices/tree"
import { useAppDispatch } from "app/store"
import { Alert } from "components/Alert"
import { TbFileImport } from "react-icons/tb"
import useMutation from "use-mutation"
export function ImportOpml() {
const dispatch = useAppDispatch()
const form = useForm<{ file: File }>({
validate: {
file: v => (v ? null : t`file is required`),
},
})
const [importOpml, importOpmlResult] = useMutation(client.feed.importOpml, {
onSuccess: () => {
dispatch(reloadTree())
dispatch(redirectToSelectedSource())
},
})
const errors = errorToStrings(importOpmlResult.error)
return (
<>
{errors.length > 0 && (