Adding zustand and react-query (Settings Page) #95

Merged
rishighan merged 33 commits from qbittorrent-settings-form into main 2023-11-07 17:56:29 +00:00
3 changed files with 55 additions and 21 deletions
Showing only changes of commit 2a6eeaf943 - Show all commits

View File

@@ -24,11 +24,6 @@ import {
LS_SINGLE_IMPORT, LS_SINGLE_IMPORT,
} from "../constants/action-types"; } from "../constants/action-types";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
const queryClient = new QueryClient({});
/** /**
* Method that initializes an AirDC++ socket connection * Method that initializes an AirDC++ socket connection
* 1. Initializes event listeners for download init, tick and complete events * 1. Initializes event listeners for download init, tick and complete events
@@ -118,11 +113,10 @@ export const App = (): ReactElement => {
// } // }
// }, []); // }, []);
return ( return (
<QueryClientProvider client={queryClient}> <>
{/* The rest of your application */} {/* The rest of your application */}
<ReactQueryDevtools initialIsOpen={true} />
{/* <AirDCPPSocketComponent /> */}; {/* <AirDCPPSocketComponent /> */};
</QueryClientProvider> </>
); );
}; };

View File

@@ -1,25 +1,58 @@
import React, { ReactElement, useCallback } from "react"; import React, { ReactElement, useCallback, useEffect } from "react";
import { saveSettings } from "../../../actions/settings.actions";
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm"; import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
import { useQuery } from "@tanstack/react-query";
import axios from "axios";
export const QbittorrentConnectionForm = (): ReactElement => { export const QbittorrentConnectionForm = (): ReactElement => {
// fetch settings
const {
data: data,
isLoading,
error,
} = useQuery({
queryKey: ["host"],
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({
queryKey: [],
queryFn: async () =>
await axios({
url: "http://localhost:3060/api/qbittorrent/connect",
method: "POST",
data: hostDetails,
}),
enabled: !!hostDetails,
});
// get qbittorrent client info
const {
data: {},
} = useQuery({
queryKey: ["qbittorrentClientInfo"],
queryFn: async () =>
await axios({
url: "http://localhost:3060/api/qbittorrent/getClientInfo",
method: "GET",
}),
enabled: !!hostDetails,
});
const onSubmit = useCallback(async (values) => { const onSubmit = useCallback(async (values) => {
try { try {
// dispatch(saveSettings(values, "bittorrent"));
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
}, []); }, []);
return ( return <></>;
<>
<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;

View File

@@ -6,6 +6,10 @@ import { createBrowserRouter, RouterProvider } from "react-router-dom";
import Settings from "./components/Settings/Settings"; import Settings from "./components/Settings/Settings";
const rootEl = document.getElementById("root"); const rootEl = document.getElementById("root");
const root = createRoot(rootEl); const root = createRoot(rootEl);
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
const queryClient = new QueryClient();
const router = createBrowserRouter([ const router = createBrowserRouter([
{ {
@@ -20,6 +24,9 @@ const router = createBrowserRouter([
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<QueryClientProvider client={queryClient}>
<RouterProvider router={router} /> <RouterProvider router={router} />
<ReactQueryDevtools initialIsOpen={true} />
</QueryClientProvider>
</React.StrictMode>, </React.StrictMode>,
); );