🌊 qBittorrent Settings Scaffold #90
@@ -1,31 +1,39 @@
|
|||||||
import React, { ReactElement, useCallback, useContext } from "react";
|
import React, { ReactElement, useCallback } from "react";
|
||||||
import {
|
|
||||||
saveSettings,
|
|
||||||
deleteSettings,
|
|
||||||
} from "../../../actions/settings.actions";
|
|
||||||
import { AirDCPPSettingsConfirmation } from "./AirDCPPSettingsConfirmation";
|
import { AirDCPPSettingsConfirmation } from "./AirDCPPSettingsConfirmation";
|
||||||
import { isUndefined, isEmpty } from "lodash";
|
import { isUndefined, isEmpty } from "lodash";
|
||||||
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
|
import { ConnectionForm } from "../../shared/ConnectionForm/ConnectionForm";
|
||||||
import { useStore } from "../../../store/index";
|
import { useStore } from "../../../store/index";
|
||||||
|
import { useShallow } from "zustand/react/shallow";
|
||||||
|
|
||||||
export const AirDCPPSettingsForm = (): ReactElement => {
|
export const AirDCPPSettingsForm = (): ReactElement => {
|
||||||
// const airDCPPSettings = useContext(AirDCPPSocketContext);
|
// const airDCPPSettings = useContext(AirDCPPSocketContext);
|
||||||
const airDCPPSettings = useStore((store) => store.airDCPPClientConfiguration);
|
const {
|
||||||
console.log("chinnga", airDCPPSettings);
|
airDCPPSocketConnected,
|
||||||
|
disconnectionInfo,
|
||||||
|
socketConnectionInformation,
|
||||||
|
airDCPPClientConfiguration,
|
||||||
|
} = useStore(
|
||||||
|
useShallow((state) => ({
|
||||||
|
airDCPPSocketConnected: state.airDCPPSocketConnected,
|
||||||
|
disconnectionInfo: state.disconnectionInfo,
|
||||||
|
airDCPPClientConfiguration: state.airDCPPClientConfiguration,
|
||||||
|
socketConnectionInformation: state.socketConnectionInformation,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
const onSubmit = useCallback(async (values) => {
|
const onSubmit = useCallback(async (values) => {
|
||||||
try {
|
try {
|
||||||
airDCPPSettings.setSettings(values);
|
// airDCPPSettings.setSettings(values);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
const removeSettings = useCallback(async () => {
|
const removeSettings = useCallback(async () => {
|
||||||
airDCPPSettings.setSettings({});
|
// airDCPPSettings.setSettings({});
|
||||||
}, []);
|
}, []);
|
||||||
//
|
//
|
||||||
const initFormData = !isUndefined(airDCPPSettings)
|
const initFormData = !isUndefined(airDCPPClientConfiguration)
|
||||||
? airDCPPSettings
|
? airDCPPClientConfiguration
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -36,13 +44,11 @@ export const AirDCPPSettingsForm = (): ReactElement => {
|
|||||||
formHeading={"Configure AirDC++"}
|
formHeading={"Configure AirDC++"}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!isEmpty(airDCPPSettings.airDCPPState.socketConnectionInformation) ? (
|
{!isEmpty(socketConnectionInformation) ? (
|
||||||
<AirDCPPSettingsConfirmation
|
<AirDCPPSettingsConfirmation settings={socketConnectionInformation} />
|
||||||
settings={airDCPPSettings.airDCPPState.socketConnectionInformation}
|
|
||||||
/>
|
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{!isEmpty(airDCPPSettings.airDCPPState.socketConnectionInformation) ? (
|
{!isEmpty(airDCPPClientConfiguration) ? (
|
||||||
<p className="control mt-4">
|
<p className="control mt-4">
|
||||||
<button className="button is-danger" onClick={removeSettings}>
|
<button className="button is-danger" onClick={removeSettings}>
|
||||||
Delete
|
Delete
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import { isUndefined, map } from "lodash";
|
|||||||
interface ISettingsProps {}
|
interface ISettingsProps {}
|
||||||
|
|
||||||
export const Settings = (props: ISettingsProps): ReactElement => {
|
export const Settings = (props: ISettingsProps): ReactElement => {
|
||||||
console.log("Asd");
|
|
||||||
const [active, setActive] = useState("gen-db");
|
const [active, setActive] = useState("gen-db");
|
||||||
const settingsContent = [
|
const settingsContent = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export const useStore = create((set, get) => ({
|
|||||||
airDCPPSocketConnected: false,
|
airDCPPSocketConnected: false,
|
||||||
disconnectionInfo: {},
|
disconnectionInfo: {},
|
||||||
airDCPPClientConfiguration: {},
|
airDCPPClientConfiguration: {},
|
||||||
|
socketConnectionInformation: {},
|
||||||
setAirDCPPSocketConnectionStatus: () =>
|
setAirDCPPSocketConnectionStatus: () =>
|
||||||
set((value) => ({
|
set((value) => ({
|
||||||
airDCPPSocketConnected: value,
|
airDCPPSocketConnected: value,
|
||||||
@@ -45,6 +46,9 @@ const initializeAirDCPPSocket = async (configuration) => {
|
|||||||
};
|
};
|
||||||
// Attempt connection
|
// Attempt connection
|
||||||
const socketConnectionInformation = await initializedAirDCPPSocket.connect();
|
const socketConnectionInformation = await initializedAirDCPPSocket.connect();
|
||||||
|
setState({
|
||||||
|
socketConnectionInformation,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. get settings from mongo
|
// 1. get settings from mongo
|
||||||
|
|||||||
Reference in New Issue
Block a user