/* * Copyright (c) 2021 - 2023, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { useRef, useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { toast } from "react-hot-toast"; import { APIClient } from "@api/APIClient"; import Toast from "@components/notifications/Toast"; import { releaseKeys } from "@screens/releases/ReleaseTable"; import { useToggle } from "@hooks/hooks"; import { DeleteModal } from "@components/modals"; import { Section } from "./_components"; const ReleaseSettings = () => (

Danger zone

This will clear release history in your database

); const getDurationLabel = (durationValue: number): string => { const durationOptions: Record = { 0: "all time", 1: "1 hour", 12: "12 hours", 24: "1 day", 168: "1 week", 720: "1 month", 2160: "3 months", 4320: "6 months", 8760: "1 year" }; return durationOptions[durationValue] || "Invalid duration"; }; function DeleteReleases() { const queryClient = useQueryClient(); const [duration, setDuration] = useState(""); const [parsedDuration, setParsedDuration] = useState(0); const cancelModalButtonRef = useRef(null); const [deleteModalIsOpen, toggleDeleteModal] = useToggle(false); const deleteOlderMutation = useMutation({ mutationFn: (olderThan: number) => APIClient.release.delete(olderThan), onSuccess: () => { if (parsedDuration === 0) { toast.custom((t) => ( )); } else { toast.custom((t) => ( )); } // Invalidate filters just in case, most likely not necessary but can't hurt. queryClient.invalidateQueries({ queryKey: releaseKeys.lists() }); } }); const deleteOlderReleases = () => { if (isNaN(parsedDuration) || parsedDuration < 0) { toast.custom((t) => ); return; } deleteOlderMutation.mutate(parsedDuration); }; return (
); } export default ReleaseSettings;