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( customServer && staffCanSee ? customServer : '', ); - const [showErrorMessage, setShowErrorMessage] = - React.useState(false); + const [status, setStatus] = React.useState( + keyserverCheckStatusInactive, + ); const onChangeKeyserverURL = React.useCallback( (event: SyntheticEvent) => @@ -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
{errorText}
; }, [showErrorMessage]); + const buttonDisabled = !keyserverURL || status.status === 'loading'; const addKeyserverButton = React.useMemo( () => ( ), - [keyserverURL, onClickAddKeyserver], + [buttonDisabled, onClickAddKeyserver], ); const addKeyserverModal = React.useMemo(