🐛 Fixed bug on the AirDC++ settings page
This commit is contained in:
@@ -16,7 +16,6 @@ export const saveSettings =
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
data: { settingsPayload, settingsObjectId },
|
data: { settingsPayload, settingsObjectId },
|
||||||
});
|
});
|
||||||
console.log(result.data);
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: SETTINGS_OBJECT_FETCHED,
|
type: SETTINGS_OBJECT_FETCHED,
|
||||||
data: result.data,
|
data: result.data,
|
||||||
|
|||||||
@@ -4,11 +4,25 @@ import { useDispatch } from "react-redux";
|
|||||||
import { saveSettings, deleteSettings } from "../../actions/settings.actions";
|
import { saveSettings, deleteSettings } from "../../actions/settings.actions";
|
||||||
import { AirDCPPSettingsConfirmation } from "./AirDCPPSettingsConfirmation";
|
import { AirDCPPSettingsConfirmation } from "./AirDCPPSettingsConfirmation";
|
||||||
import { AirDCPPSocketContext } from "../../context/AirDCPPSocket";
|
import { AirDCPPSocketContext } from "../../context/AirDCPPSocket";
|
||||||
import { isUndefined, isEmpty } from "lodash";
|
import { isUndefined, isEmpty, isNil } from "lodash";
|
||||||
|
|
||||||
export const AirDCPPSettingsForm = (): ReactElement => {
|
export const AirDCPPSettingsForm = (): ReactElement => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const airDCPPSettings = useContext(AirDCPPSocketContext);
|
const airDCPPSettings = useContext(AirDCPPSocketContext);
|
||||||
|
|
||||||
|
const hostValidator = (hostname: string): string | null => {
|
||||||
|
const hostnameRegex = /[\W]+/gm;
|
||||||
|
try {
|
||||||
|
if (!isUndefined(hostname)) {
|
||||||
|
const matches = hostname.match(hostnameRegex);
|
||||||
|
return (isNil(matches) && matches.length !== 0) ? hostname : "Invalid hostname; it should not contain special characters";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
const onSubmit = useCallback(async (values) => {
|
const onSubmit = useCallback(async (values) => {
|
||||||
try {
|
try {
|
||||||
airDCPPSettings.setSettings(values);
|
airDCPPSettings.setSettings(values);
|
||||||
@@ -52,14 +66,18 @@ export const AirDCPPSettingsForm = (): ReactElement => {
|
|||||||
</Field>
|
</Field>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p className="control is-expanded">
|
<div className="control is-expanded">
|
||||||
<Field
|
<Field
|
||||||
name="hostname"
|
name="hostname"
|
||||||
component="input"
|
validate={hostValidator}>
|
||||||
className="input"
|
{({ input, meta }) => (
|
||||||
placeholder="AirDC++ host IP / hostname"
|
<div>
|
||||||
/>
|
<input {...input} type="text" placeholder="AirDC++ hostname" className="input" />
|
||||||
</p>
|
{meta.error && meta.touched && <span className="is-size-7 has-text-danger">{meta.error}</span>}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
<p className="control">
|
<p className="control">
|
||||||
<Field
|
<Field
|
||||||
name="port"
|
name="port"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const AirDCPPSocketContextProvider = ({ children }) => {
|
|||||||
} = configuration;
|
} = configuration;
|
||||||
const initializedAirDCPPSocket = new AirDCPPSocket({
|
const initializedAirDCPPSocket = new AirDCPPSocket({
|
||||||
protocol: `${host.protocol}`,
|
protocol: `${host.protocol}`,
|
||||||
hostname: `${host.hostname}`,
|
hostname: `${host.hostname}:${host.port}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const socketConnectionInformation = await initializedAirDCPPSocket.connect(
|
const socketConnectionInformation = await initializedAirDCPPSocket.connect(
|
||||||
|
|||||||
Reference in New Issue
Block a user