From 2df0fce79296ed6653e2248029241c81d26e45c7 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 23 Oct 2023 14:07:52 -0400 Subject: [PATCH] =?UTF-8?q?=E2=AC=87=EF=B8=8F=20Fetched=20qBittorrent=20se?= =?UTF-8?q?ttings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QbittorrentConnectionForm.tsx | 22 +++++++----- src/client/services/settings.api.ts | 6 ---- src/client/services/torrents.api.ts | 34 +++++++++++-------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx b/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx index 074f048..dce90cc 100644 --- a/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx +++ b/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx @@ -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 && ( + + )} +
{JSON.stringify(data?.qbittorrentClientInfo, null, 2)}
+ + ); }; export default QbittorrentConnectionForm; diff --git a/src/client/services/settings.api.ts b/src/client/services/settings.api.ts index bce1989..be49bc1 100644 --- a/src/client/services/settings.api.ts +++ b/src/client/services/settings.api.ts @@ -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, }); diff --git a/src/client/services/torrents.api.ts b/src/client/services/torrents.api.ts index ee496ef..00aa6cb 100644 --- a/src/client/services/torrents.api.ts +++ b/src/client/services/torrents.api.ts @@ -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; + } }, }), }),