import {FC, useRef, useState} from 'react'; import {observer} from 'mobx-react-lite'; import {Trans} from '@lingui/react'; import { Button, Form, FormError, FormRow, Panel, PanelContent, PanelHeader, PanelFooter, Select, SelectItem, } from '@client/ui'; import AuthActions from '@client/actions/AuthActions'; import AuthStore from '@client/stores/AuthStore'; import ClientActions from '@client/actions/ClientActions'; import FloodActions from '@client/actions/FloodActions'; import type {ClientConnectionSettings} from '@shared/schema/ClientConnectionSettings'; import ClientConnectionSettingsForm from './connection-settings/ClientConnectionSettingsForm'; const ClientConnectionInterruption: FC = observer(() => { const [error, setError] = useState(null); const [isSubmitting, setSubmitting] = useState(false); const [selection, setSelection] = useState('retry'); const clientConnectionSettingsRef = useRef(null); return (
{ setSubmitting(true); if (selection === 'config') { const currentUsername = AuthStore.currentUser.username; const connectionSettings = clientConnectionSettingsRef.current; if (currentUsername == null || connectionSettings == null) { setError('connection.settings.error.empty'); setSubmitting(false); return; } try { await AuthActions.updateUser(currentUsername, { client: connectionSettings, }) .then(() => { // do nothing. }) .catch((e) => { setError('general.error.unknown'); throw e; }); } catch { setSubmitting(false); return; } } await ClientActions.testConnection() .then(() => { FloodActions.restartActivityStream(); }) .catch(() => { setError('connection-interruption.verification-error'); }); setSubmitting(false); }} >

{error && ( )} {AuthStore.currentUser.isAdmin ? ( ) : (

)} {selection === 'config' && ( { clientConnectionSettingsRef.current = settings; }} /> )}
{selection === 'retry' && ( )} {selection === 'config' && ( )}
); }); export default ClientConnectionInterruption;