Skip to content

Commit 446d618

Browse files
committed
Update text fields when query params change
1 parent b5cda81 commit 446d618

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

frontend/src/api/hooks/useAddressInput.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, {useState, useEffect} from "react";
22
import AddressTextField from "../../components/AddressTextField";
33
import {isValidAccountAddress} from "../../pages/utils";
44

5-
const useAddressInput = () => {
6-
const [addr, setAddr] = useState<string>("");
5+
const useAddressInput = (initialValue: string) => {
6+
const [addr, setAddr] = useState<string>(initialValue);
77
const [addrIsValid, setAddrIsValid] = useState<boolean>(true);
88

99
useEffect(() => {
@@ -35,7 +35,7 @@ const useAddressInput = () => {
3535
return isValid;
3636
}
3737

38-
return {addr, clearAddr, renderAddressTextField, validateAddressInput};
38+
return {addr, setAddr, renderAddressTextField, validateAddressInput};
3939
};
4040

4141
export default useAddressInput;

frontend/src/pages/NodeChecker/ConfigurationSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function ConfigurationSelect({
6969
updateBaselineConfiguration(undefined);
7070
updateValidConfigurations(undefined);
7171
});
72-
}, [state.network_name]);
72+
}, [state.network_name, searchParams]);
7373

7474
function DropdownIcon(props: SvgIconProps) {
7575
return (

frontend/src/pages/NodeChecker/Index.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,34 @@ export function NodeCheckerPage() {
3434
// URL text input field.
3535
const {
3636
url,
37-
clearUrl: _clearUrl,
37+
setUrl,
3838
renderUrlTextField,
3939
validateUrlInput,
4040
} = useUrlInput(searchParams.get("url") || "");
4141

4242
// API port text input field.
4343
const {
4444
port: apiPort,
45-
clearPort: _clearApiPort,
45+
setPort: setApiPort,
4646
renderPortTextField: renderApiPortTextField,
4747
validatePortInput: validateApiPortInput,
4848
} = usePortInput(searchParams.get("apiPort") || "443");
4949

5050
// Noise port text input field.
5151
const {
5252
port: noisePort,
53-
clearPort: _clearNoisePort,
53+
setPort: setNoisePort,
5454
renderPortTextField: renderNoisePortTextField,
5555
validatePortInput: validateNoisePortInput,
5656
} = usePortInput(searchParams.get("noisePort") || "6180");
5757

5858
// Public key text input field.
5959
const {
6060
addr: publicKey,
61-
clearAddr: _clearPublicKey,
61+
setAddr: setPublicKey,
6262
renderAddressTextField: renderPublicKeyTextField,
6363
validateAddressInput: validatePublicKeyAddressInput,
64-
} = useAddressInput();
64+
} = useAddressInput(searchParams.get("publicKey") || "");
6565

6666
const nhcUrl = determineNhcUrl(state);
6767

@@ -105,6 +105,7 @@ export function NodeCheckerPage() {
105105
url: url,
106106
apiPort: apiPort,
107107
noisePort: noisePort,
108+
publicKey: publicKey,
108109
baselineConfiguration: baselineConfiguration!.name,
109110
});
110111
try {
@@ -129,11 +130,16 @@ export function NodeCheckerPage() {
129130
updateChecking(false);
130131
};
131132

132-
// Clear the results if the user changes the network.
133+
// Clear the results if the user changes the network or the search params.
134+
// Update the fields.
133135
useEffect(() => {
134136
updateEvaluationSummary(undefined);
135137
updateErrorMessage(undefined);
136-
}, [state.network_name]);
138+
setUrl(searchParams.get("url") || "");
139+
setApiPort(searchParams.get("apiPort") || "443");
140+
setNoisePort(searchParams.get("noisePort") || "6180");
141+
setPublicKey(searchParams.get("publicKey") || "");
142+
}, [state.network_name, searchParams]);
137143

138144
// Conditionally build an input field for the public key if the selected
139145
// baseline configuration has an evaluator that requires it.

frontend/src/pages/NodeChecker/hooks/usePortInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const usePortInput = (initialValue: string) => {
4646
return isValid;
4747
}
4848

49-
return {port, clearPort, renderPortTextField, validatePortInput};
49+
return {port, setPort, renderPortTextField, validatePortInput};
5050
};
5151

5252
export default usePortInput;

frontend/src/pages/NodeChecker/hooks/useUrlInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const useUrlInput = (initialValue: string) => {
4545
return isValid;
4646
}
4747

48-
return {url, clearUrl, renderUrlTextField, validateUrlInput};
48+
return {url, setUrl, renderUrlTextField, validateUrlInput};
4949
};
5050

5151
export default useUrlInput;

0 commit comments

Comments
 (0)