import { useToggle } from "../../hooks/hooks"; import { Switch } from "@headlessui/react"; import { useMutation, useQuery, useQueryClient } from "react-query"; import { classNames } from "../../utils"; import { DownloadClientAddForm, DownloadClientUpdateForm } from "../../forms"; import { EmptySimple } from "../../components/emptystates"; import { APIClient } from "../../api/APIClient"; import { DownloadClientTypeNameMap } from "../../domain/constants"; import toast from "react-hot-toast"; import Toast from "../../components/notifications/Toast"; interface DLSettingsItemProps { client: DownloadClient; idx: number; } function DownloadClientSettingsListItem({ client, idx }: DLSettingsItemProps) { const [updateClientIsOpen, toggleUpdateClient] = useToggle(false); const queryClient = useQueryClient(); const mutation = useMutation( (client: DownloadClient) => APIClient.download_clients.update(client), { onSuccess: () => { queryClient.invalidateQueries(["downloadClients"]); toast.custom((t) => ); } } ); const onToggleMutation = (newState: boolean) => { mutation.mutate({ ...client, enabled: newState }); }; return (
  • Use setting
    {client.name}
    {client.host}
    {DownloadClientTypeNameMap[client.type]}
    Edit
  • ); } function DownloadClientSettings() { const [addClientIsOpen, toggleAddClient] = useToggle(false); const { error, data } = useQuery( "downloadClients", () => APIClient.download_clients.getAll(), { refetchOnWindowFocus: false } ); if (error) { return

    Failed to fetch download clients

    ; } return (

    Clients

    Manage download clients.

    {data && data.length > 0 ?
    1. Enabled
      Name
      Host
      Type
    2. {data && data.map((client, idx) => ( ))}
    : }
    ); } export default DownloadClientSettings;