import { useMutation } from "react-query"; import { APIClient } from "../../api/APIClient"; import { queryClient } from "../../App"; import { toast } from "react-hot-toast"; import Toast from "../../components/notifications/Toast"; import { SlideOver } from "../../components/panels"; import { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "../../components/inputs"; import { ImplementationMap } from "../../screens/settings/Feed"; import { componentMapType } from "./DownloadClientForms"; import { sleep } from "../../utils"; import { useState } from "react"; interface UpdateProps { isOpen: boolean; toggle: () => void; feed: Feed; } export function FeedUpdateForm({ isOpen, toggle, feed }: UpdateProps) { const [isTesting, setIsTesting] = useState(false); const [isTestSuccessful, setIsSuccessfulTest] = useState(false); const [isTestError, setIsErrorTest] = useState(false); const mutation = useMutation( (feed: Feed) => APIClient.feeds.update(feed), { onSuccess: () => { queryClient.invalidateQueries(["feeds"]); toast.custom((t) => ); toggle(); } } ); const onSubmit = (formData: unknown) => { mutation.mutate(formData as Feed); }; const deleteMutation = useMutation( (feedID: number) => APIClient.feeds.delete(feedID), { onSuccess: () => { queryClient.invalidateQueries(["feeds"]); toast.custom((t) => ); } } ); const deleteAction = () => { deleteMutation.mutate(feed.id); }; const testFeedMutation = useMutation( (feed: Feed) => APIClient.feeds.test(feed), { onMutate: () => { setIsTesting(true); setIsErrorTest(false); setIsSuccessfulTest(false); }, onSuccess: () => { sleep(1000) .then(() => { setIsTesting(false); setIsSuccessfulTest(true); }) .then(() => { sleep(2500).then(() => { setIsSuccessfulTest(false); }); }); }, onError: () => { setIsTesting(false); setIsErrorTest(true); sleep(2500).then(() => { setIsErrorTest(false); }); } } ); const testFeed = (data: unknown) => { testFeedMutation.mutate(data as Feed); }; const initialValues = { id: feed.id, indexer: feed.indexer, enabled: feed.enabled, type: feed.type, name: feed.name, url: feed.url, api_key: feed.api_key, interval: feed.interval }; return ( {(values) => (
{ImplementationMap[feed.type]}
{componentMap[values.type]}
)}
); } function FormFieldsTorznab() { return (
); } const componentMap: componentMapType = { TORZNAB: };