You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bazarr/frontend/src/pages/Settings/components/index.tsx

69 lines
1.9 KiB

import api from "@/apis/raw";
import { Button } from "@mantine/core";
import { FunctionComponent, useCallback, useState } from "react";
import { useSettingValue } from "./hooks";
export const URLTestButton: FunctionComponent<{
category: "sonarr" | "radarr";
}> = ({ category }) => {
const [title, setTitle] = useState("Test");
const [color, setVar] = useState("primary");
const address = useSettingValue<string>(`settings-${category}-ip`);
const port = useSettingValue<number>(`settings-${category}-port`);
const url = useSettingValue<string>(`settings-${category}-base_url`);
const apikey = useSettingValue<string>(`settings-${category}-apikey`);
const ssl = useSettingValue<boolean>(`settings-${category}-ssl`);
const click = useCallback(() => {
if (address && apikey && ssl !== null) {
let testUrl: string;
if (port) {
testUrl = `${address}:${port}${url ?? ""}`;
} else {
testUrl = `${address}${url ?? ""}`;
}
const request = {
protocol: ssl ? "https" : "http",
url: testUrl,
params: {
apikey,
},
};
if (!request.url.endsWith("/")) {
request.url += "/";
}
api.utils
.urlTest(request.protocol, request.url, request.params)
.then((result) => {
if (result.status) {
setTitle(`Version: ${result.version}`);
setVar("success");
} else {
setTitle(result.error);
setVar("danger");
}
});
}
}, [address, port, url, apikey, ssl]);
return (
<Button onClick={click} color={color} title={title}>
{title}
</Button>
);
};
export * from "./Card";
export * from "./collapse";
export { default as CollapseBox } from "./collapse";
export * from "./forms";
export * from "./hooks";
export * from "./Layout";
export { default as Layout } from "./Layout";
export * from "./Message";
export * from "./pathMapper";
export * from "./Section";