Massive ts error cleanup
This commit is contained in:
@@ -38,16 +38,21 @@ export const AirDCPPHubsForm = (): ReactElement => {
|
||||
enabled: !isEmpty(settings?.data.directConnect?.client?.host),
|
||||
});
|
||||
|
||||
let hubList: any[] = [];
|
||||
interface HubOption {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
let hubList: HubOption[] = [];
|
||||
if (!isNil(hubs)) {
|
||||
hubList = hubs?.data.map(({ hub_url, identity }) => ({
|
||||
hubList = hubs?.data.map(({ hub_url, identity }: { hub_url: string; identity: { name: string } }) => ({
|
||||
value: hub_url,
|
||||
label: identity.name,
|
||||
}));
|
||||
}
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (values) =>
|
||||
mutationFn: async (values: Record<string, unknown>) =>
|
||||
await axios({
|
||||
url: `http://localhost:3000/api/settings/saveSettings`,
|
||||
method: "POST",
|
||||
@@ -69,13 +74,24 @@ export const AirDCPPHubsForm = (): ReactElement => {
|
||||
},
|
||||
});
|
||||
|
||||
const validate = async (values) => {
|
||||
const errors = {};
|
||||
const validate = async (values: Record<string, unknown>) => {
|
||||
const errors: Record<string, string> = {};
|
||||
// Add any validation logic here if needed
|
||||
return errors;
|
||||
};
|
||||
|
||||
const SelectAdapter = ({ input, ...rest }) => {
|
||||
interface SelectAdapterProps {
|
||||
input: {
|
||||
value: unknown;
|
||||
onChange: (value: unknown) => void;
|
||||
onBlur: () => void;
|
||||
onFocus: () => void;
|
||||
name: string;
|
||||
};
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
const SelectAdapter = ({ input, ...rest }: SelectAdapterProps) => {
|
||||
return <Select {...input} {...rest} isClearable isMulti />;
|
||||
};
|
||||
|
||||
@@ -155,7 +171,7 @@ export const AirDCPPHubsForm = (): ReactElement => {
|
||||
</span>
|
||||
<div className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-slate-400 dark:border-gray-700">
|
||||
{settings?.data.directConnect?.client.hubs.map(
|
||||
({ value, label }) => (
|
||||
({ value, label }: HubOption) => (
|
||||
<div key={value}>
|
||||
<div>{label}</div>
|
||||
<span className="is-size-7">{value}</span>
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
import React, { ReactElement } from "react";
|
||||
|
||||
export const AirDCPPSettingsConfirmation = (settingsObject): ReactElement => {
|
||||
const { settings } = settingsObject;
|
||||
interface AirDCPPSessionInfo {
|
||||
_id: string;
|
||||
system_info: {
|
||||
client_version: string;
|
||||
hostname: string;
|
||||
platform: string;
|
||||
};
|
||||
user: {
|
||||
username: string;
|
||||
active_sessions: number;
|
||||
permissions: string[];
|
||||
};
|
||||
}
|
||||
|
||||
interface AirDCPPSettingsConfirmationProps {
|
||||
settings: AirDCPPSessionInfo;
|
||||
}
|
||||
|
||||
export const AirDCPPSettingsConfirmation = ({ settings }: AirDCPPSettingsConfirmationProps): ReactElement => {
|
||||
return (
|
||||
<div>
|
||||
<span className="flex items-center mt-10 mb-4">
|
||||
|
||||
@@ -17,8 +17,16 @@ export const AirDCPPSettingsForm = () => {
|
||||
queryFn: () => axios.get(`${SETTINGS_SERVICE_BASE_URI}/getAllSettings`),
|
||||
});
|
||||
|
||||
interface HostConfig {
|
||||
hostname: string;
|
||||
port: string;
|
||||
username: string;
|
||||
password: string;
|
||||
protocol: string;
|
||||
}
|
||||
|
||||
// Fetch session information
|
||||
const fetchSessionInfo = (host) => {
|
||||
const fetchSessionInfo = (host: HostConfig) => {
|
||||
return axios.post(`${AIRDCPP_SERVICE_BASE_URI}/initialize`, { host });
|
||||
};
|
||||
|
||||
@@ -34,7 +42,7 @@ export const AirDCPPSettingsForm = () => {
|
||||
|
||||
// Handle setting update and subsequent AirDC++ initialization
|
||||
const { mutate } = useMutation({
|
||||
mutationFn: (values) => {
|
||||
mutationFn: (values: Record<string, unknown>) => {
|
||||
return axios.post("http://localhost:3000/api/settings/saveSettings", {
|
||||
settingsPayload: values,
|
||||
settingsKey: "directConnect",
|
||||
@@ -50,12 +58,13 @@ export const AirDCPPSettingsForm = () => {
|
||||
},
|
||||
});
|
||||
|
||||
const deleteSettingsMutation = useMutation(() =>
|
||||
axios.post("http://localhost:3000/api/settings/saveSettings", {
|
||||
settingsPayload: {},
|
||||
settingsKey: "directConnect",
|
||||
}),
|
||||
);
|
||||
const deleteSettingsMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
axios.post("http://localhost:3000/api/settings/saveSettings", {
|
||||
settingsPayload: {},
|
||||
settingsKey: "directConnect",
|
||||
}),
|
||||
});
|
||||
|
||||
const initFormData = settingsData?.data?.directConnect?.client?.host ?? {};
|
||||
|
||||
|
||||
@@ -4,9 +4,13 @@ import { Form, Field } from "react-final-form";
|
||||
import { PROWLARR_SERVICE_BASE_URI } from "../../../constants/endpoints";
|
||||
import axios from "axios";
|
||||
|
||||
export const ProwlarrSettingsForm = (props) => {
|
||||
interface ProwlarrSettingsFormProps {
|
||||
// Add props here if needed
|
||||
}
|
||||
|
||||
export const ProwlarrSettingsForm = (_props: ProwlarrSettingsFormProps) => {
|
||||
const { data } = useQuery({
|
||||
queryFn: async (): any => {
|
||||
queryFn: async () => {
|
||||
return await axios({
|
||||
url: `${PROWLARR_SERVICE_BASE_URI}/getIndexers`,
|
||||
method: "POST",
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
|
||||
import { useQuery, useMutation, QueryClient } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
|
||||
export const QbittorrentConnectionForm = (): ReactElement => {
|
||||
export const QbittorrentConnectionForm = (): ReactElement | null => {
|
||||
const queryClient = new QueryClient();
|
||||
// fetch settings
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
@@ -28,7 +28,7 @@ export const QbittorrentConnectionForm = (): ReactElement => {
|
||||
});
|
||||
// Update action using a mutation
|
||||
const { mutate } = useMutation({
|
||||
mutationFn: async (values) =>
|
||||
mutationFn: async (values: Record<string, unknown>) =>
|
||||
await axios({
|
||||
url: `http://localhost:3000/api/settings/saveSettings`,
|
||||
method: "POST",
|
||||
@@ -77,6 +77,7 @@ export const QbittorrentConnectionForm = (): ReactElement => {
|
||||
</>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export default QbittorrentConnectionForm;
|
||||
|
||||
@@ -10,6 +10,19 @@ import settingsObject from "../../constants/settings/settingsMenu.json";
|
||||
import { isUndefined, map } from "lodash";
|
||||
import type { SettingsProps } from "../../types";
|
||||
|
||||
interface SettingsMenuItem {
|
||||
id: string | number;
|
||||
displayName: string;
|
||||
children?: SettingsMenuItem[];
|
||||
}
|
||||
|
||||
interface SettingsCategory {
|
||||
id: number;
|
||||
category: string;
|
||||
displayName: string;
|
||||
children?: SettingsMenuItem[];
|
||||
}
|
||||
|
||||
export const Settings = (props: SettingsProps): ReactElement => {
|
||||
const [active, setActive] = useState("gen-db");
|
||||
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
|
||||
@@ -62,70 +75,70 @@ export const Settings = (props: SettingsProps): ReactElement => {
|
||||
overflow-hidden"
|
||||
>
|
||||
<div className="px-4 py-6 overflow-y-auto">
|
||||
{map(settingsObject, (settingObject, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="mb-6 text-slate-700 dark:text-slate-300"
|
||||
>
|
||||
<h3 className="text-xs font-semibold text-slate-500 dark:text-slate-400 tracking-wide mb-3">
|
||||
{settingObject.category.toUpperCase()}
|
||||
</h3>
|
||||
|
||||
{!isUndefined(settingObject.children) && (
|
||||
<ul>
|
||||
{map(settingObject.children, (item, idx) => {
|
||||
const isOpen = expanded[item.id];
|
||||
|
||||
return (
|
||||
<li key={idx} className="mb-1">
|
||||
<div
|
||||
onClick={() => toggleExpanded(item.id)}
|
||||
className={`cursor-pointer flex justify-between items-center px-1 py-1 rounded-md transition-colors hover:bg-white/50 dark:hover:bg-slate-700 ${
|
||||
item.id === active
|
||||
? "font-semibold text-blue-600 dark:text-blue-400"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
onClick={() => setActive(item.id.toString())}
|
||||
className="flex-1"
|
||||
{map(settingsObject as SettingsCategory[], (settingObject, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="mb-6 text-slate-700 dark:text-slate-300"
|
||||
>
|
||||
<h3 className="text-xs font-semibold text-slate-500 dark:text-slate-400 tracking-wide mb-3">
|
||||
{settingObject.category.toUpperCase()}
|
||||
</h3>
|
||||
|
||||
{!isUndefined(settingObject.children) && (
|
||||
<ul>
|
||||
{map(settingObject.children, (item: SettingsMenuItem, idx) => {
|
||||
const isOpen = expanded[String(item.id)];
|
||||
|
||||
return (
|
||||
<li key={idx} className="mb-1">
|
||||
<div
|
||||
onClick={() => toggleExpanded(String(item.id))}
|
||||
className={`cursor-pointer flex justify-between items-center px-1 py-1 rounded-md transition-colors hover:bg-white/50 dark:hover:bg-slate-700 ${
|
||||
String(item.id) === active
|
||||
? "font-semibold text-blue-600 dark:text-blue-400"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
{item.displayName}
|
||||
</span>
|
||||
{!isUndefined(item.children) && (
|
||||
<span className="text-xs opacity-60">
|
||||
{isOpen ? "−" : "+"}
|
||||
<span
|
||||
onClick={() => setActive(String(item.id))}
|
||||
className="flex-1"
|
||||
>
|
||||
{item.displayName}
|
||||
</span>
|
||||
{!isUndefined(item.children) && (
|
||||
<span className="text-xs opacity-60">
|
||||
{isOpen ? "−" : "+"}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!isUndefined(item.children) && isOpen && (
|
||||
<ul className="pl-4 mt-1">
|
||||
{map(item.children, (subItem: SettingsMenuItem) => (
|
||||
<li key={String(subItem.id)} className="mb-1">
|
||||
<a
|
||||
onClick={() =>
|
||||
setActive(String(subItem.id))
|
||||
}
|
||||
className={`cursor-pointer flex items-center px-1 py-1 rounded-md transition-colors hover:bg-white/50 dark:hover:bg-slate-700 ${
|
||||
String(subItem.id) === active
|
||||
? "font-semibold text-blue-600 dark:text-blue-400"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
{subItem.displayName}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!isUndefined(item.children) && isOpen && (
|
||||
<ul className="pl-4 mt-1">
|
||||
{map(item.children, (subItem) => (
|
||||
<li key={subItem.id} className="mb-1">
|
||||
<a
|
||||
onClick={() =>
|
||||
setActive(subItem.id.toString())
|
||||
}
|
||||
className={`cursor-pointer flex items-center px-1 py-1 rounded-md transition-colors hover:bg-white/50 dark:hover:bg-slate-700 ${
|
||||
subItem.id.toString() === active
|
||||
? "font-semibold text-blue-600 dark:text-blue-400"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
{subItem.displayName}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useMutation } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
|
||||
export const SystemSettingsForm = (): ReactElement => {
|
||||
const { mutate: flushDb, isLoading } = useMutation({
|
||||
const { mutate: flushDb, isPending } = useMutation({
|
||||
mutationFn: async () => {
|
||||
await axios({
|
||||
url: `http://localhost:3000/api/library/flushDb`,
|
||||
|
||||
Reference in New Issue
Block a user