/* * Copyright (c) 2021 - 2023, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { toast } from "react-hot-toast"; import { APIClient } from "@api/APIClient"; import { Checkbox } from "@components/Checkbox"; import { SettingsContext } from "@utils/Context"; import { GithubRelease } from "@app/types/Update"; import Toast from "@components/notifications/Toast"; interface RowItemProps { label: string; value?: string; title?: string; emptyText?: string; newUpdate?: GithubRelease; } const RowItem = ({ label, value, title, emptyText }: RowItemProps) => { return (
{label}
{value ? {value} : emptyText}
); }; // interface RowItemNumberProps { // label: string; // value?: string | number; // title?: string; // unit?: string; // } // const RowItemNumber = ({ label, value, title, unit }: RowItemNumberProps) => { // return ( //
//
{label}:
//
// {value} // {unit && // {unit} // } //
//
// ); // }; const RowItemVersion = ({ label, value, title, newUpdate }: RowItemProps) => { if (!value) { return null; } return (
{label}
{value} {newUpdate && newUpdate.html_url && ( {newUpdate.name} available! )}
); }; function ApplicationSettings() { const [settings, setSettings] = SettingsContext.use(); const { isLoading, data } = useQuery({ queryKey: ["config"], queryFn: APIClient.config.get, retry: false, refetchOnWindowFocus: false, onError: err => console.log(err) }); const { data: updateData } = useQuery({ queryKey: ["updates"], queryFn: APIClient.updates.getLatestRelease, retry: false, refetchOnWindowFocus: false, enabled: data?.check_for_updates === true, onError: err => console.log(err) }); const queryClient = useQueryClient(); const checkUpdateMutation = useMutation({ mutationFn: APIClient.updates.check, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["updates"] }); } }); const toggleCheckUpdateMutation = useMutation((value: boolean) => APIClient.config.update({ check_for_updates: value }).then(() => value), { onSuccess: (value: boolean) => { toast.custom(t => ); queryClient.invalidateQueries({ queryKey: ["config"] }); checkUpdateMutation.mutate(); } }); return (

Application

Application settings. Change in config.toml and restart to take effect.

{!isLoading && data && (
)}
    setSettings({ ...settings, debug: newValue })} />
    { toggleCheckUpdateMutation.mutate(newValue); }} />
    setSettings({ ...settings, darkTheme: newValue })} />
); } export default ApplicationSettings;