⬇️ Fetched qBittorrent settings

This commit is contained in:
2023-10-23 14:07:52 -04:00
parent 4ea9086e3f
commit 2df0fce792
3 changed files with 34 additions and 28 deletions

View File

@@ -1,15 +1,10 @@
import React, { ReactElement, useCallback, useEffect } from "react";
import { useAppDispatch, useAppSelector } from "../../../hooks/store";
import { getQBitTorrentClientInfo } from "../../../actions/settings.actions";
import React, { ReactElement, useCallback } from "react";
import { saveSettings } from "../../../actions/settings.actions";
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
import { useGetAllSettingsQuery } from "../../../services/settings.api";
import { isUndefined } from "lodash";
import { useConnectToQBittorrentClientQuery } from "../../../services/torrents.api";
export const QbittorrentConnectionForm = (): ReactElement => {
const dispatch = useAppDispatch();
const { data, isLoading } = useConnectToQBittorrentClientQuery({});
const onSubmit = useCallback(async (values) => {
try {
dispatch(saveSettings(values, "bittorrent"));
@@ -18,7 +13,18 @@ export const QbittorrentConnectionForm = (): ReactElement => {
}
}, []);
return <></>;
return (
<>
{!isLoading && (
<ConnectionForm
initialData={data?.bittorrent.client.host}
submitHandler={onSubmit}
formHeading={"Qbittorrent Configuration"}
/>
)}
<pre>{JSON.stringify(data?.qbittorrentClientInfo, null, 2)}</pre>
</>
);
};
export default QbittorrentConnectionForm;

View File

@@ -6,12 +6,6 @@ export const settingsApi = emptySplitApi.injectEndpoints({
getAllSettings: builder.query({
query: () => "localhost:3000/api/settings/getAllSettings",
}),
getQBitTorrentClientInfo: builder.query({
queryFn: async () => {
try {
} catch (err) {}
},
}),
}),
overrideExisting: false,
});

View File

@@ -4,20 +4,26 @@ export const torrentsApi = emptySplitApi.injectEndpoints({
endpoints: (builder) => ({
connectToQBittorrentClient: builder.query({
queryFn: async (_arg, _queryApi, _extraOptions, fetchWithBQ) => {
const qBittorrentHostInfo = await fetchWithBQ(
"localhost:3000/api/settings/getAllSettings",
);
await fetchWithBQ({
url: "localhost:3060/api/qbittorrent/connect",
method: "POST",
data: qBittorrentHostInfo,
});
console.log(qBittorrentHostInfo);
return {
url: "",
method: "GET",
data: qBittorrentHostInfo,
};
try {
const {
data: { bittorrent },
} = await fetchWithBQ("localhost:3000/api/settings/getAllSettings");
await fetchWithBQ({
url: "localhost:3060/api/qbittorrent/connect",
method: "POST",
body: bittorrent?.client?.host,
});
const { data } = await fetchWithBQ({
url: "localhost:3060/api/qbittorrent/getClientInfo",
method: "GET",
});
return {
data: { bittorrent, qbittorrentClientInfo: data },
};
} catch (err) {
throw err;
}
},
}),
}),