⬇️ Fetched qBittorrent settings
This commit is contained in:
@@ -1,15 +1,10 @@
|
|||||||
import React, { ReactElement, useCallback, useEffect } from "react";
|
import React, { ReactElement, useCallback } from "react";
|
||||||
import { useAppDispatch, useAppSelector } from "../../../hooks/store";
|
|
||||||
import { getQBitTorrentClientInfo } from "../../../actions/settings.actions";
|
|
||||||
import { saveSettings } from "../../../actions/settings.actions";
|
import { saveSettings } from "../../../actions/settings.actions";
|
||||||
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
|
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
|
||||||
import { useGetAllSettingsQuery } from "../../../services/settings.api";
|
|
||||||
import { isUndefined } from "lodash";
|
|
||||||
import { useConnectToQBittorrentClientQuery } from "../../../services/torrents.api";
|
import { useConnectToQBittorrentClientQuery } from "../../../services/torrents.api";
|
||||||
|
|
||||||
export const QbittorrentConnectionForm = (): ReactElement => {
|
export const QbittorrentConnectionForm = (): ReactElement => {
|
||||||
const dispatch = useAppDispatch();
|
const { data, isLoading } = useConnectToQBittorrentClientQuery({});
|
||||||
|
|
||||||
const onSubmit = useCallback(async (values) => {
|
const onSubmit = useCallback(async (values) => {
|
||||||
try {
|
try {
|
||||||
dispatch(saveSettings(values, "bittorrent"));
|
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;
|
export default QbittorrentConnectionForm;
|
||||||
|
|||||||
@@ -6,12 +6,6 @@ export const settingsApi = emptySplitApi.injectEndpoints({
|
|||||||
getAllSettings: builder.query({
|
getAllSettings: builder.query({
|
||||||
query: () => "localhost:3000/api/settings/getAllSettings",
|
query: () => "localhost:3000/api/settings/getAllSettings",
|
||||||
}),
|
}),
|
||||||
getQBitTorrentClientInfo: builder.query({
|
|
||||||
queryFn: async () => {
|
|
||||||
try {
|
|
||||||
} catch (err) {}
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
overrideExisting: false,
|
overrideExisting: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,20 +4,26 @@ export const torrentsApi = emptySplitApi.injectEndpoints({
|
|||||||
endpoints: (builder) => ({
|
endpoints: (builder) => ({
|
||||||
connectToQBittorrentClient: builder.query({
|
connectToQBittorrentClient: builder.query({
|
||||||
queryFn: async (_arg, _queryApi, _extraOptions, fetchWithBQ) => {
|
queryFn: async (_arg, _queryApi, _extraOptions, fetchWithBQ) => {
|
||||||
const qBittorrentHostInfo = await fetchWithBQ(
|
try {
|
||||||
"localhost:3000/api/settings/getAllSettings",
|
const {
|
||||||
);
|
data: { bittorrent },
|
||||||
await fetchWithBQ({
|
} = await fetchWithBQ("localhost:3000/api/settings/getAllSettings");
|
||||||
url: "localhost:3060/api/qbittorrent/connect",
|
await fetchWithBQ({
|
||||||
method: "POST",
|
url: "localhost:3060/api/qbittorrent/connect",
|
||||||
data: qBittorrentHostInfo,
|
method: "POST",
|
||||||
});
|
body: bittorrent?.client?.host,
|
||||||
console.log(qBittorrentHostInfo);
|
});
|
||||||
return {
|
const { data } = await fetchWithBQ({
|
||||||
url: "",
|
url: "localhost:3060/api/qbittorrent/getClientInfo",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
data: qBittorrentHostInfo,
|
});
|
||||||
};
|
|
||||||
|
return {
|
||||||
|
data: { bittorrent, qbittorrentClientInfo: data },
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user