import { useMutation, useQuery, useQueryClient } from "react-query"; import { classNames, IsEmptyDate, simplifyDate } from "../../utils"; import { IrcNetworkAddForm, IrcNetworkUpdateForm } from "../../forms"; import { useToggle } from "../../hooks/hooks"; import { APIClient } from "../../api/APIClient"; import { EmptySimple } from "../../components/emptystates"; import { LockClosedIcon, LockOpenIcon } from "@heroicons/react/24/solid"; import { Menu, Switch, Transition } from "@headlessui/react"; import { Fragment, useRef } from "react"; import { DeleteModal } from "../../components/modals"; import { toast } from "react-hot-toast"; import Toast from "../../components/notifications/Toast"; import { ArrowsPointingInIcon, ArrowsPointingOutIcon, EllipsisHorizontalIcon, ExclamationCircleIcon, PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline"; export const IrcSettings = () => { const [expandNetworks, toggleExpand] = useToggle(false); const [addNetworkIsOpen, toggleAddNetwork] = useToggle(false); const { data } = useQuery("networks", () => APIClient.irc.getNetworks(), { refetchOnWindowFocus: false, // Refetch every 3 seconds refetchInterval: 3000 }); return (

IRC

IRC networks and channels. Click on a network to view channel status.

  1. Network healthy
  2. Network unhealthy
  3. Network disabled
{data && data.length > 0 ? (
  1. Enabled
    Network
    Server
    Nick
  2. {data && data.map((network, idx) => ( ))}
) : ( )}
); }; interface ListItemProps { idx: number; network: IrcNetworkWithHealth; expanded: boolean; } const ListItem = ({ idx, network, expanded }: ListItemProps) => { const [updateIsOpen, toggleUpdate] = useToggle(false); const [edit, toggleEdit] = useToggle(false); const queryClient = useQueryClient(); const mutation = useMutation( (network: IrcNetwork) => APIClient.irc.updateNetwork(network), { onSuccess: () => { queryClient.invalidateQueries(["networks"]); toast.custom((t) => ); } } ); const onToggleMutation = (newState: boolean) => { mutation.mutate({ ...network, enabled: newState }); }; return (
  • Enable
    {network.enabled ? ( network.healthy ? ( ) : ( ) ) : ( )}
    {network.name}
    {network.tls ? ( ) : ( )}

    {network.server}:{network.port}

    {network.nick}
    {(edit || expanded) && (
    {network.channels.length > 0 ? (
    1. Channel
      Monitoring since
      Last announce
    2. {network.channels.map((c) => (
    3. {network.enabled ? ( c.monitoring ? ( ) : ( ) ) : ( )} {c.name}
      {IsEmptyDate(c.monitoring_since)}
      {IsEmptyDate(c.last_announce)}
    4. ))}
    ) : (

    No channels!

    )}
    )}
  • ); }; interface ListItemDropdownProps { network: IrcNetwork; toggleUpdate: () => void; } const ListItemDropdown = ({ network, toggleUpdate }: ListItemDropdownProps) => { const cancelModalButtonRef = useRef(null); const queryClient = useQueryClient(); const [deleteModalIsOpen, toggleDeleteModal] = useToggle(false); const deleteMutation = useMutation( (id: number) => APIClient.irc.deleteNetwork(id), { onSuccess: () => { queryClient.invalidateQueries(["networks"]); queryClient.invalidateQueries(["networks", network.id]); toast.custom((t) => ); toggleDeleteModal(); } } ); const restartMutation = useMutation( (id: number) => APIClient.irc.restartNetwork(id), { onSuccess: () => { toast.custom((t) => ); queryClient.invalidateQueries(["networks"]); queryClient.invalidateQueries(["networks", network.id]); } } ); const restart = (id: number) => { restartMutation.mutate(id); }; return ( { deleteMutation.mutate(network.id); toggleDeleteModal(); }} title={`Remove network: ${network.name}`} text="Are you sure you want to remove this network? This action cannot be undone." />
    {({ active }) => ( )} {/**/} {/* {({ active }) => (*/} {/* onToggle(!network.enabled)}*/} {/* >*/} {/* */} {({ active }) => ( )}
    {({ active }) => ( )}
    ); };