🔧 Fixing state and context issues WIP for ADCPP socket
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {
|
import {
|
||||||
SETTINGS_OBJECT_FETCHED,
|
SETTINGS_OBJECT_FETCHED,
|
||||||
SETTINGS_OBJECT_DELETED,
|
|
||||||
SETTINGS_CALL_IN_PROGRESS,
|
SETTINGS_CALL_IN_PROGRESS,
|
||||||
SETTINGS_DB_FLUSH_SUCCESS,
|
SETTINGS_DB_FLUSH_SUCCESS,
|
||||||
} from "../constants/action-types";
|
} from "../constants/action-types";
|
||||||
@@ -10,18 +9,19 @@ import {
|
|||||||
SETTINGS_SERVICE_BASE_URI,
|
SETTINGS_SERVICE_BASE_URI,
|
||||||
} from "../constants/endpoints";
|
} from "../constants/endpoints";
|
||||||
|
|
||||||
export const saveSettings = (settingsPayload) => async (dispatch) => {
|
export const saveSettings =
|
||||||
const result = await axios({
|
(settingsPayload, settingsObjectId?: string) => async (dispatch) => {
|
||||||
url: `${SETTINGS_SERVICE_BASE_URI}/saveSettings`,
|
const result = await axios({
|
||||||
method: "POST",
|
url: `${SETTINGS_SERVICE_BASE_URI}/saveSettings`,
|
||||||
data: { settingsPayload },
|
method: "POST",
|
||||||
});
|
data: { settingsPayload, settingsObjectId },
|
||||||
console.log(result.data);
|
});
|
||||||
dispatch({
|
console.log(result.data);
|
||||||
type: SETTINGS_OBJECT_FETCHED,
|
dispatch({
|
||||||
data: result.data,
|
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({
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export const AirDCPPHubsForm = (airDCPPClientUserSettings): ReactElement => {
|
|||||||
|
|
||||||
const onSubmit = (values) => {
|
const onSubmit = (values) => {
|
||||||
if (!isUndefined(values.hubs)) {
|
if (!isUndefined(values.hubs)) {
|
||||||
dispatch(saveSettings({ hubs: values.hubs }, settings._id));
|
dispatch(saveSettings({ ...settings, hubs: values.hubs }, settings._id));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export const AirDCPPSettingsForm = (): ReactElement => {
|
|||||||
dispatch(deleteSettings());
|
dispatch(deleteSettings());
|
||||||
}, []);
|
}, []);
|
||||||
const validate = async () => {};
|
const validate = async () => {};
|
||||||
console.log(airDCPPSettings.airDCPPState);
|
|
||||||
const initFormData = !isUndefined(
|
const initFormData = !isUndefined(
|
||||||
airDCPPSettings.airDCPPState.settings.directConnect,
|
airDCPPSettings.airDCPPState.settings.directConnect,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ const AirDCPPSocketComponent = (): ReactElement => {
|
|||||||
const foo = async () => {
|
const foo = async () => {
|
||||||
if (
|
if (
|
||||||
!isUndefined(airDCPPConfiguration.airDCPPState) &&
|
!isUndefined(airDCPPConfiguration.airDCPPState) &&
|
||||||
!isEmpty(airDCPPConfiguration.airDCPPState.settings)
|
!isEmpty(airDCPPConfiguration.airDCPPState.settings) &&
|
||||||
|
!isEmpty(airDCPPConfiguration.airDCPPState.socket)
|
||||||
) {
|
) {
|
||||||
await airDCPPConfiguration.airDCPPState.socket.addListener(
|
await airDCPPConfiguration.airDCPPState.socket.addListener(
|
||||||
"queue",
|
"queue",
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ export const DownloadsPanel = (
|
|||||||
|
|
||||||
// AirDCPP Socket initialization
|
// AirDCPP Socket initialization
|
||||||
const userSettings = useSelector((state: RootState) => state.settings.data);
|
const userSettings = useSelector((state: RootState) => state.settings.data);
|
||||||
const { ADCPPSocket } = useContext(AirDCPPSocketContext);
|
const airDCPPConfiguration = useContext(AirDCPPSocketContext);
|
||||||
|
|
||||||
|
const {
|
||||||
|
airDCPPState: { socket, settings },
|
||||||
|
} = airDCPPConfiguration;
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
// Fetch the downloaded files and currently-downloading file(s) from AirDC++
|
// Fetch the downloaded files and currently-downloading file(s) from AirDC++
|
||||||
@@ -33,16 +37,16 @@ export const DownloadsPanel = (
|
|||||||
try {
|
try {
|
||||||
if (!isEmpty(userSettings)) {
|
if (!isEmpty(userSettings)) {
|
||||||
dispatch(
|
dispatch(
|
||||||
getBundlesForComic(props.comicObjectId, ADCPPSocket, {
|
getBundlesForComic(props.comicObjectId, socket, {
|
||||||
username: `${userSettings.directConnect.client.host.username}`,
|
username: `${settings.directConnect.client.host.username}`,
|
||||||
password: `${userSettings.directConnect.client.host.password}`,
|
password: `${settings.directConnect.client.host.password}`,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
}, [dispatch]);
|
}, [dispatch, airDCPPConfiguration]);
|
||||||
|
|
||||||
const Bundles = (props) => {
|
const Bundles = (props) => {
|
||||||
return !isEmpty(props.data) ? (
|
return !isEmpty(props.data) ? (
|
||||||
@@ -81,7 +85,7 @@ export const DownloadsPanel = (
|
|||||||
return !isNil(props.data) ? (
|
return !isNil(props.data) ? (
|
||||||
<>
|
<>
|
||||||
<div className="columns is-multiline">
|
<div className="columns is-multiline">
|
||||||
{!isEmpty(ADCPPSocket) ? (
|
{!isEmpty(socket) ? (
|
||||||
<Bundles data={bundles} />
|
<Bundles data={bundles} />
|
||||||
) : (
|
) : (
|
||||||
<div className="column is-three-fifths">
|
<div className="column is-three-fifths">
|
||||||
|
|||||||
@@ -12,22 +12,22 @@ export const Settings = (props: ISettingsProps): ReactElement => {
|
|||||||
const settingsContent = [
|
const settingsContent = [
|
||||||
{
|
{
|
||||||
id: "adc-hubs",
|
id: "adc-hubs",
|
||||||
content: <>{<AirDCPPHubsForm />}</>,
|
content: <div key="adc-hubs">{<AirDCPPHubsForm />}</div>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "adc-connection",
|
id: "adc-connection",
|
||||||
content: (
|
content: (
|
||||||
<>
|
<div key="adc-connection">
|
||||||
<AirDCPPSettingsForm />
|
<AirDCPPSettingsForm />
|
||||||
</>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "flushdb",
|
id: "flushdb",
|
||||||
content: (
|
content: (
|
||||||
<>
|
<div key="flushdb">
|
||||||
<SystemSettingsForm />
|
<SystemSettingsForm />
|
||||||
</>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -46,7 +46,7 @@ export const Settings = (props: ISettingsProps): ReactElement => {
|
|||||||
<ul className="menu-list" key={settingObject.id}>
|
<ul className="menu-list" key={settingObject.id}>
|
||||||
{map(settingObject.children, (item, idx) => {
|
{map(settingObject.children, (item, idx) => {
|
||||||
return (
|
return (
|
||||||
<li key={item.id}>
|
<li key={idx}>
|
||||||
<a
|
<a
|
||||||
className={
|
className={
|
||||||
item.id.toString() === active ? "is-active" : ""
|
item.id.toString() === active ? "is-active" : ""
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isEmpty } from "lodash";
|
import { isEmpty, isUndefined } from "lodash";
|
||||||
import React, { createContext, useEffect, useState } from "react";
|
import React, { createContext, useEffect, useState } from "react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { getSettings } from "../actions/settings.actions";
|
import { getSettings } from "../actions/settings.actions";
|
||||||
@@ -18,7 +18,11 @@ const AirDCPPSocketContextProvider = ({ children }) => {
|
|||||||
};
|
};
|
||||||
// 1. default zero-state for AirDC++ configuration
|
// 1. default zero-state for AirDC++ configuration
|
||||||
const initState = {
|
const initState = {
|
||||||
airDCPPState: { settings: {}, socket: {}, socketConnectionInformation: {} },
|
airDCPPState: {
|
||||||
|
settings: {},
|
||||||
|
socket: {},
|
||||||
|
socketConnectionInformation: {},
|
||||||
|
},
|
||||||
setSettings: setSettings,
|
setSettings: setSettings,
|
||||||
};
|
};
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -41,6 +45,7 @@ const AirDCPPSocketContextProvider = ({ children }) => {
|
|||||||
|
|
||||||
// Method to init AirDC++ Socket with supplied settings
|
// Method to init AirDC++ Socket with supplied settings
|
||||||
const initializeAirDCPPSocket = async (configuration) => {
|
const initializeAirDCPPSocket = async (configuration) => {
|
||||||
|
console.log("[AirDCPP]: Initializing socket...");
|
||||||
const {
|
const {
|
||||||
directConnect: {
|
directConnect: {
|
||||||
client: { host },
|
client: { host },
|
||||||
|
|||||||
Reference in New Issue
Block a user