Page MenuHomePhabricator

D12054.diff
No OneTemporary

D12054.diff

diff --git a/web/modals/keyserver-selection/add-keyserver-modal.react.js b/web/modals/keyserver-selection/add-keyserver-modal.react.js
--- a/web/modals/keyserver-selection/add-keyserver-modal.react.js
+++ b/web/modals/keyserver-selection/add-keyserver-modal.react.js
@@ -16,6 +16,14 @@
import Input from '../input.react.js';
import Modal from '../modal.react.js';
+type KeyserverCheckStatus =
+ | { +status: 'inactive' }
+ | { +status: 'loading' }
+ | { +status: 'error' };
+const keyserverCheckStatusInactive = { status: 'inactive' };
+const keyserverCheckStatusLoading = { status: 'loading' };
+const keyserverCheckStatusError = { status: 'error' };
+
function AddKeyserverModal(): React.Node {
const { popModal } = useModalContext();
@@ -29,8 +37,9 @@
const [keyserverURL, setKeyserverURL] = React.useState<string>(
customServer && staffCanSee ? customServer : '',
);
- const [showErrorMessage, setShowErrorMessage] =
- React.useState<boolean>(false);
+ const [status, setStatus] = React.useState<KeyserverCheckStatus>(
+ keyserverCheckStatusInactive,
+ );
const onChangeKeyserverURL = React.useCallback(
(event: SyntheticEvent<HTMLInputElement>) =>
@@ -41,16 +50,17 @@
const isKeyserverURLValidCallback = useIsKeyserverURLValid(keyserverURL);
const onClickAddKeyserver = React.useCallback(async () => {
- setShowErrorMessage(false);
if (!currentUserID || !keyserverURL) {
return;
}
+ setStatus(keyserverCheckStatusLoading);
const keyserverVersionData = await isKeyserverURLValidCallback();
if (!keyserverVersionData) {
- setShowErrorMessage(true);
+ setStatus(keyserverCheckStatusError);
return;
}
+ setStatus(keyserverCheckStatusInactive);
const newKeyserverInfo: KeyserverInfo = defaultKeyserverInfo(keyserverURL);
@@ -71,6 +81,7 @@
isKeyserverURLValidCallback,
]);
+ const showErrorMessage = status.status === 'error';
const errorMessage = React.useMemo(() => {
let errorText;
if (showErrorMessage) {
@@ -81,6 +92,7 @@
return <div className={css.errorMessage}>{errorText}</div>;
}, [showErrorMessage]);
+ const buttonDisabled = !keyserverURL || status.status === 'loading';
const addKeyserverButton = React.useMemo(
() => (
<Button
@@ -88,12 +100,12 @@
buttonColor={buttonThemes.primary}
className={css.button}
onClick={onClickAddKeyserver}
- disabled={!keyserverURL}
+ disabled={buttonDisabled}
>
Add keyserver
</Button>
),
- [keyserverURL, onClickAddKeyserver],
+ [buttonDisabled, onClickAddKeyserver],
);
const addKeyserverModal = React.useMemo(

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 4:27 AM (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2610208
Default Alt Text
D12054.diff (2 KB)

Event Timeline