diff --git a/src/client/actions/settings.actions.tsx b/src/client/actions/settings.actions.tsx index d7b8c60..0585c9a 100644 --- a/src/client/actions/settings.actions.tsx +++ b/src/client/actions/settings.actions.tsx @@ -1,13 +1,31 @@ import axios from "axios"; import { IExtractionOptions } from "threetwo-ui-typings"; -import {} from "../constants/action-types"; +import { SETTINGS_OBJECT_FETCHED } from "../constants/action-types"; import { SETTINGS_SERVICE_BASE_URI } from "../constants/endpoints"; -export const saveSettings = (settingsObject) => async (dispatch) => { +export const saveSettings = + (settingsObject, airdcppUserSettings) => async (dispatch) => { + const result = await axios({ + url: `${SETTINGS_SERVICE_BASE_URI}/saveSettings`, + method: "POST", + data: { settingsObject, airdcppUserSettings }, + }); + dispatch({ + type: SETTINGS_OBJECT_FETCHED, + data: result.data, + }); + }; + +export const getSettings = (settingsKey?) => async (dispatch) => { const result = await axios({ - url: `${SETTINGS_SERVICE_BASE_URI}/saveSettings`, + url: `${SETTINGS_SERVICE_BASE_URI}/getSettings`, method: "POST", - data: settingsObject, + data: settingsKey, }); - console.log(result); + { + dispatch({ + type: SETTINGS_OBJECT_FETCHED, + data: result.data, + }); + } }; diff --git a/src/client/components/AirDCPPSettingsForm.tsx b/src/client/components/AirDCPPSettingsForm.tsx index 030b0c2..baaa75f 100644 --- a/src/client/components/AirDCPPSettingsForm.tsx +++ b/src/client/components/AirDCPPSettingsForm.tsx @@ -1,91 +1,180 @@ -import React, { ReactElement } from "react"; +import React, { ReactElement, useEffect } from "react"; import { Form, Field } from "react-final-form"; -import { useDispatch } from "react-redux"; -import { saveSettings } from "../actions/settings.actions"; +import { useDispatch, useSelector } from "react-redux"; +import { saveSettings, getSettings } from "../actions/settings.actions"; import axios from "axios"; +import { isUndefined, isEmpty } from "lodash"; export const AirDCPPSettingsForm = (): ReactElement => { + const airdcppClientSettings = useSelector( + (state: RootState) => state.settings.data[0], + ); + const dispatch = useDispatch(); + useEffect(() => { + dispatch(getSettings()); + }, [dispatch]); + const onSubmit = async (values) => { try { + const fqdn = values.protocol + values.hostname; const airdcppResponse = await axios({ - url: `https://${values.airdcpp_hostname}/api/v1/sessions/authorize`, + url: `${fqdn}/api/v1/sessions/authorize`, method: "POST", data: { - username: values.airdcpp_username, - password: values.airdcpp_password, + username: values.username, + password: values.password, }, }); if (airdcppResponse.status === 200) { - dispatch(saveSettings(values)); + dispatch(saveSettings(values, airdcppResponse.data)); } } catch (error) { console.log(error); } }; const validate = async () => {}; + const initFormData = !isUndefined(airdcppClientSettings) + ? airdcppClientSettings.directConnect.client + : null; return ( -
( - -

AirDC++ Connection Information

-
+ <> + ( + +

AirDC++ Connection Information

-
- +
+

+ + + + + + +

+

+ +

-
-
-
- -
-
-
-

- - - - -

+
+
+
-
-

- - - - - - - -

+
+
+

+ + + + +

+
+
+

+ + + + + + + +

+
-
- - - )} - /> + + + )} + /> + {!isUndefined(airdcppClientSettings) && + !isEmpty(airdcppClientSettings) ? ( +
+
+
+ + + +
+
+
{airdcppClientSettings._id}
+
+ Client version:{" "} + { + airdcppClientSettings.directConnect.client + .airdcppUserSettings.system_info.client_version + } +
+
+ Hostname:{" "} + { + airdcppClientSettings.directConnect.client + .airdcppUserSettings.system_info.hostname + } +
+
+ Platform:{" "} + { + airdcppClientSettings.directConnect.client + .airdcppUserSettings.system_info.platform + } +
+ +
+ Username:{" "} + { + airdcppClientSettings.directConnect.client + .airdcppUserSettings.user.username + } +
+ +
+ Active Sessions:{" "} + { + airdcppClientSettings.directConnect.client + .airdcppUserSettings.user.active_sessions + } +
+
+ Permissions:{" "} +
+                      {JSON.stringify(
+                        airdcppClientSettings.directConnect.client
+                          .airdcppUserSettings.user.permissions,
+                        undefined,
+                        2,
+                      )}
+                    
+
+
+
+
+
+
+ ) : null} + ); }; diff --git a/src/client/components/Library.tsx b/src/client/components/Library.tsx index badecbf..724ae93 100644 --- a/src/client/components/Library.tsx +++ b/src/client/components/Library.tsx @@ -14,6 +14,7 @@ import { Form, Field } from "react-final-form"; import { getComicBooks } from "../actions/fileops.actions"; import { isNil } from "lodash"; import { IMPORT_SERVICE_HOST } from "../constants/endpoints"; +import { Link } from "react-router-dom"; interface IComicBookLibraryProps { matches?: unknown; @@ -142,6 +143,26 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => {
)} /> +
+
+

+ +

+

+ +

+
+
); }; @@ -292,6 +313,7 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => {

Library

+
diff --git a/src/client/components/Navbar.tsx b/src/client/components/Navbar.tsx index c71f2a6..af2defc 100644 --- a/src/client/components/Navbar.tsx +++ b/src/client/components/Navbar.tsx @@ -46,9 +46,7 @@ const Navbar: React.FunctionComponent = (props) => { Library - - Library Grid - + Search diff --git a/src/client/components/Settings.tsx b/src/client/components/Settings.tsx index 8dc6cf8..3c8dbf7 100644 --- a/src/client/components/Settings.tsx +++ b/src/client/components/Settings.tsx @@ -34,10 +34,8 @@ export const Settings = (props: ISettingsProps): ReactElement => { diff --git a/src/client/reducers/settings.reducer.ts b/src/client/reducers/settings.reducer.ts index 8894e14..bfd892f 100644 --- a/src/client/reducers/settings.reducer.ts +++ b/src/client/reducers/settings.reducer.ts @@ -4,7 +4,7 @@ import { SETTINGS_CALL_IN_PROGRESS, } from "../constants/action-types"; const initialState = { - settings: {}, + data: {}, inProgress: false, };