From e89a7f9c91fed936ec4e4d42e44120d3d6f9189a Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 2 Nov 2023 22:53:49 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20qbittorrent=20form=20RU=20action?= =?UTF-8?q?s=20first=20draft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/actions/settings.actions.tsx | 14 ----- .../QbittorrentConnectionForm.tsx | 52 +++++++++++-------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/client/actions/settings.actions.tsx b/src/client/actions/settings.actions.tsx index 94a6d92..384783a 100644 --- a/src/client/actions/settings.actions.tsx +++ b/src/client/actions/settings.actions.tsx @@ -11,20 +11,6 @@ import { QBITTORRENT_SERVICE_BASE_URI, } from "../constants/endpoints"; -export const saveSettings = - (settingsPayload, settingsKey: string, settingsObjectId?: string) => - async (dispatch) => { - const result = await axios({ - url: `${SETTINGS_SERVICE_BASE_URI}/saveSettings`, - method: "POST", - data: { settingsPayload, settingsKey, settingsObjectId }, - }); - dispatch({ - type: SETTINGS_OBJECT_FETCHED, - data: result.data, - }); - }; - export const getSettings = (settingsKey?) => async (dispatch) => { const result = await axios({ url: `${SETTINGS_SERVICE_BASE_URI}/getSettings`, diff --git a/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx b/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx index 51714b9..3c7c342 100644 --- a/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx +++ b/src/client/components/Settings/QbittorrentSettings/QbittorrentConnectionForm.tsx @@ -1,26 +1,23 @@ import React, { ReactElement, useCallback, useEffect } from "react"; import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm"; -import { useQuery } from "@tanstack/react-query"; +import { useQuery, useMutation } from "@tanstack/react-query"; +import { saveSettings } from "../../../actions/settings.actions"; import axios from "axios"; export const QbittorrentConnectionForm = (): ReactElement => { + // axios interceptors to destructure response // fetch settings - const { - data: data, - isLoading, - error, - } = useQuery({ - queryKey: ["host"], + const { data, isLoading, isError } = useQuery({ + queryKey: ["settings"], queryFn: async () => await axios({ url: "http://localhost:3000/api/settings/getAllSettings", method: "GET", }), }); - const hostDetails = data?.data.bittorrent.client.host; // connect to qbittorrent client - useQuery({ + const { data: connectionDetails } = useQuery({ queryKey: [], queryFn: async () => await axios({ @@ -30,29 +27,40 @@ export const QbittorrentConnectionForm = (): ReactElement => { }), enabled: !!hostDetails, }); - // get qbittorrent client info - const { - data: {}, - } = useQuery({ + const { data: qbittorrentClientInfo } = useQuery({ queryKey: ["qbittorrentClientInfo"], queryFn: async () => await axios({ url: "http://localhost:3060/api/qbittorrent/getClientInfo", method: "GET", }), - enabled: !!hostDetails, + enabled: !!connectionDetails, + }); + console.log(qbittorrentClientInfo?.data); + + const { mutate } = useMutation({ + mutationFn: async (values) => + await axios({ + url: `http://localhost:3000/api/settings/saveSettings`, + method: "POST", + data: { settingsPayload: values, settingsKey: "bittorrent" }, + }), }); - const onSubmit = useCallback(async (values) => { - try { - // dispatch(saveSettings(values, "bittorrent")); - } catch (error) { - console.log(error); - } - }, []); + return ( + <> + - return <>; +
+        {JSON.stringify(qbittorrentClientInfo?.data, null, 4)}
+      
+ + ); }; export default QbittorrentConnectionForm;