📝 qbittorrent form RU actions first draft
This commit is contained in:
@@ -11,20 +11,6 @@ import {
|
|||||||
QBITTORRENT_SERVICE_BASE_URI,
|
QBITTORRENT_SERVICE_BASE_URI,
|
||||||
} from "../constants/endpoints";
|
} 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) => {
|
export const getSettings = (settingsKey?) => async (dispatch) => {
|
||||||
const result = await axios({
|
const result = await axios({
|
||||||
url: `${SETTINGS_SERVICE_BASE_URI}/getSettings`,
|
url: `${SETTINGS_SERVICE_BASE_URI}/getSettings`,
|
||||||
|
|||||||
@@ -1,26 +1,23 @@
|
|||||||
import React, { ReactElement, useCallback, useEffect } from "react";
|
import React, { ReactElement, useCallback, useEffect } from "react";
|
||||||
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
|
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";
|
import axios from "axios";
|
||||||
|
|
||||||
export const QbittorrentConnectionForm = (): ReactElement => {
|
export const QbittorrentConnectionForm = (): ReactElement => {
|
||||||
|
// axios interceptors to destructure response
|
||||||
// fetch settings
|
// fetch settings
|
||||||
const {
|
const { data, isLoading, isError } = useQuery({
|
||||||
data: data,
|
queryKey: ["settings"],
|
||||||
isLoading,
|
|
||||||
error,
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: ["host"],
|
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
await axios({
|
await axios({
|
||||||
url: "http://localhost:3000/api/settings/getAllSettings",
|
url: "http://localhost:3000/api/settings/getAllSettings",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const hostDetails = data?.data.bittorrent.client.host;
|
const hostDetails = data?.data.bittorrent.client.host;
|
||||||
// connect to qbittorrent client
|
// connect to qbittorrent client
|
||||||
useQuery({
|
const { data: connectionDetails } = useQuery({
|
||||||
queryKey: [],
|
queryKey: [],
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
await axios({
|
await axios({
|
||||||
@@ -30,29 +27,40 @@ export const QbittorrentConnectionForm = (): ReactElement => {
|
|||||||
}),
|
}),
|
||||||
enabled: !!hostDetails,
|
enabled: !!hostDetails,
|
||||||
});
|
});
|
||||||
|
|
||||||
// get qbittorrent client info
|
// get qbittorrent client info
|
||||||
const {
|
const { data: qbittorrentClientInfo } = useQuery({
|
||||||
data: {},
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: ["qbittorrentClientInfo"],
|
queryKey: ["qbittorrentClientInfo"],
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
await axios({
|
await axios({
|
||||||
url: "http://localhost:3060/api/qbittorrent/getClientInfo",
|
url: "http://localhost:3060/api/qbittorrent/getClientInfo",
|
||||||
method: "GET",
|
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) => {
|
return (
|
||||||
try {
|
<>
|
||||||
// dispatch(saveSettings(values, "bittorrent"));
|
<ConnectionForm
|
||||||
} catch (error) {
|
initialData={hostDetails}
|
||||||
console.log(error);
|
formHeading={"qBittorrent Configuration"}
|
||||||
}
|
submitHandler={mutate}
|
||||||
}, []);
|
/>
|
||||||
|
|
||||||
return <></>;
|
<pre className="mt-5">
|
||||||
|
{JSON.stringify(qbittorrentClientInfo?.data, null, 4)}
|
||||||
|
</pre>
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default QbittorrentConnectionForm;
|
export default QbittorrentConnectionForm;
|
||||||
|
|||||||
Reference in New Issue
Block a user