diff --git a/package.json b/package.json index ae7b1d8..2af6625 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "react-notification-system": "^0.4.0", "react-notification-system-redux": "^2.0.1", "react-responsive-carousel": "^3.2.21", - "react-select": "^4.3.1", + "react-select": "^5.2.1", "react-sliding-pane": "^7.0.0", "react-stickynode": "^4.0.0", "react-table": "^7.7.0", diff --git a/src/client/actions/settings.actions.tsx b/src/client/actions/settings.actions.tsx index 813d0ee..ef3691c 100644 --- a/src/client/actions/settings.actions.tsx +++ b/src/client/actions/settings.actions.tsx @@ -6,11 +6,11 @@ import { import { SETTINGS_SERVICE_BASE_URI } from "../constants/endpoints"; export const saveSettings = - (settingsObject, airdcppUserSettings) => async (dispatch) => { + (settingsPayload, settingsObjectId?) => async (dispatch) => { const result = await axios({ url: `${SETTINGS_SERVICE_BASE_URI}/saveSettings`, method: "POST", - data: { settingsObject, airdcppUserSettings }, + data: { settingsPayload, settingsObjectId }, }); console.log(result.data); dispatch({ diff --git a/src/client/components/AcquisitionPanel.tsx b/src/client/components/AcquisitionPanel.tsx index 63355fd..dcc0744 100644 --- a/src/client/components/AcquisitionPanel.tsx +++ b/src/client/components/AcquisitionPanel.tsx @@ -7,7 +7,7 @@ import { import { useDispatch, useSelector } from "react-redux"; import { RootState, SearchInstance } from "threetwo-ui-typings"; import ellipsize from "ellipsize"; -import { isEmpty, isNil, isUndefined, map } from "lodash"; +import { isEmpty, isNil, isUndefined, map, pick } from "lodash"; import { AirDCPPSocketContext } from "../context/AirDCPPSocket"; interface IAcquisitionPanelProps { comicBookMetadata: any; @@ -43,8 +43,8 @@ export const AcquisitionPanel = ( async (searchQuery) => { dispatch( search(searchQuery, ADCPPSocket, { - username: `${userSettings.directConnect.client.username}`, - password: `${userSettings.directConnect.client.password}`, + username: `${userSettings.directConnect.client.host.username}`, + password: `${userSettings.directConnect.client.host.password}`, }), ); }, @@ -59,7 +59,7 @@ export const AcquisitionPanel = ( extensions: ["cbz", "cbr"], }, // "comic-scans.no-ip.biz:24674", - hub_urls: ["perfection.comichub.org:777"], + hub_urls: map(userSettings.directConnect.client.hubs, (item) => item.value), priority: 5, }; @@ -73,16 +73,16 @@ export const AcquisitionPanel = ( comicBookObjectId, ADCPPSocket, { - username: `${userSettings.directConnect.client.username}`, - password: `${userSettings.directConnect.client.password}`, + username: `${userSettings.directConnect.client.host.username}`, + password: `${userSettings.directConnect.client.host.password}`, }, ), ); // this is to update the download count badge on the downloads tab dispatch( getBundlesForComic(comicBookObjectId, ADCPPSocket, { - username: `${userSettings.directConnect.client.username}`, - password: `${userSettings.directConnect.client.password}`, + username: `${userSettings.directConnect.client.host.username}`, + password: `${userSettings.directConnect.client.host.password}`, }), ); }, @@ -126,6 +126,17 @@ export const AcquisitionPanel = (
+
+
+ {userSettings.directConnect.client.hubs.map( + ({ value }) => ( + + {value} + + ), + )} +
+
Query: {searchInfo.query.pattern}
Extensions: {searchInfo.query.extensions.join(", ")} diff --git a/src/client/components/AirDCPPConnectionForm.tsx b/src/client/components/AirDCPPConnectionForm.tsx deleted file mode 100644 index 02a7bd7..0000000 --- a/src/client/components/AirDCPPConnectionForm.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React, { ReactElement } from "react"; -import { Form, Field } from "react-final-form"; - -export const AirDCPPConnectionForm = (): ReactElement => { - const onSubmit = () => {}; - const validate = async () => {}; - - return ( -
( - -
-

AirDC++ Connection Settings

-
- Configure AirDC++ connection settings such as hostname and - credentials -
-
-
- -
- -
-
- - -
- )} - /> - ); -}; - -export default AirDCPPConnectionForm; diff --git a/src/client/components/AirDCPPSettings/AirDCPPHubsForm.tsx b/src/client/components/AirDCPPSettings/AirDCPPHubsForm.tsx new file mode 100644 index 0000000..230106d --- /dev/null +++ b/src/client/components/AirDCPPSettings/AirDCPPHubsForm.tsx @@ -0,0 +1,98 @@ +import React, { ReactElement, useEffect, useState } from "react"; +import { Form, Field } from "react-final-form"; +import axios from "axios"; +import { useDispatch } from "react-redux"; +import { isEmpty, isUndefined } from "lodash"; +import Select from "react-select"; +import { saveSettings } from "../../actions/settings.actions"; + +export const AirDCPPHubsForm = (airDCPPClientUserSettings): ReactElement => { + const { settings } = airDCPPClientUserSettings; + const dispatch = useDispatch(); + const [hubList, setHubList] = useState([]); + + useEffect(() => { + if (!isEmpty(settings)) { + axios({ + url: `${settings.directConnect.client.host.protocol}://${settings.directConnect.client.host.hostname}/api/v1/hubs`, + method: "GET", + headers: { + Authorization: `${settings.directConnect.client.airDCPPUserSettings.auth_token}`, + }, + }).then((hubs) => { + const hubSelectionOptions = hubs.data.map(({ hub_url, identity }) => ({ + value: hub_url, + label: identity.name, + })); + + setHubList(hubSelectionOptions); + }); + } + }, []); + + const onSubmit = (values) => { + if (!isUndefined(values.hubs)) { + dispatch(saveSettings({ hubs: values.hubs }, settings._id)); + } + }; + + const validate = async () => {}; + + const SelectAdapter = ({ input, ...rest }) => { + return