Enhance ApiServerContext with Improved Reconnection Handling
- Added loading state indication during reconnection attempts in the modal. - Adjusted modal dimensions and styles based on the reconnection status for better user experience. - Streamlined the display logic for connection lost messages and reconnection progress, improving clarity and responsiveness.
This commit is contained in:
parent
56479ea358
commit
6bc81cf90f
@ -12,13 +12,14 @@ import { message, Modal, Space, Button, Typography, Flex } from 'antd'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { AuthContext } from './AuthContext'
|
import { AuthContext } from './AuthContext'
|
||||||
import { useLocation, useNavigate } from 'react-router-dom'
|
import { useLocation, useNavigate } from 'react-router-dom'
|
||||||
|
import { LoadingOutlined } from '@ant-design/icons'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import ExclamationOctagonIcon from '../../Icons/ExclamationOctagonIcon'
|
import ExclamationOctagonIcon from '../../Icons/ExclamationOctagonIcon'
|
||||||
import ReloadIcon from '../../Icons/ReloadIcon'
|
import ReloadIcon from '../../Icons/ReloadIcon'
|
||||||
import LockIcon from '../../Icons/LockIcon'
|
import LockIcon from '../../Icons/LockIcon'
|
||||||
import config from '../../../config'
|
import config from '../../../config'
|
||||||
import loglevel from 'loglevel'
|
import loglevel from 'loglevel'
|
||||||
|
|
||||||
import { getModelByName } from '../../../database/ObjectModels'
|
import { getModelByName } from '../../../database/ObjectModels'
|
||||||
import ProgressDisplay from '../common/ProgressDisplay'
|
import ProgressDisplay from '../common/ProgressDisplay'
|
||||||
const logger = loglevel.getLogger('ApiServerContext')
|
const logger = loglevel.getLogger('ApiServerContext')
|
||||||
@ -2920,42 +2921,59 @@ const ApiServerProvider = ({ children }) => {
|
|||||||
{children}
|
{children}
|
||||||
<Modal
|
<Modal
|
||||||
title={
|
title={
|
||||||
<Space size={'middle'}>
|
!isReconnecting ? (
|
||||||
<ExclamationOctagonIcon />
|
<Space size={'middle'}>
|
||||||
Connection Lost
|
<ExclamationOctagonIcon />
|
||||||
</Space>
|
Connection Lost
|
||||||
|
</Space>
|
||||||
|
) : (
|
||||||
|
false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
open={Boolean(token) && authenticated == true && connectionIssue}
|
open={Boolean(token) && authenticated == true && connectionIssue}
|
||||||
style={{ maxWidth: 480 }}
|
style={{ maxWidth: !isReconnecting ? 480 : 260 }}
|
||||||
zIndex={3000}
|
zIndex={3000}
|
||||||
closable={false}
|
closable={false}
|
||||||
|
height={isReconnecting ? 20 : undefined}
|
||||||
centered
|
centered
|
||||||
|
className={isReconnecting ? 'loading-modal' : undefined}
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
getContainer={() => document.body}
|
getContainer={() => document.body}
|
||||||
footer={[
|
footer={
|
||||||
<Button
|
!isReconnecting
|
||||||
key='reconnect'
|
? [
|
||||||
loading={isReconnecting}
|
<Button
|
||||||
onClick={() => attemptReconnect()}
|
key='reconnect'
|
||||||
>
|
loading={isReconnecting}
|
||||||
Reconnect
|
onClick={() => attemptReconnect()}
|
||||||
</Button>
|
>
|
||||||
]}
|
Reconnect
|
||||||
|
</Button>
|
||||||
|
]
|
||||||
|
: false
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Flex vertical gap='middle'>
|
{!isReconnecting ? (
|
||||||
<Text>
|
<Flex vertical gap='middle'>
|
||||||
{isReconnecting
|
<Text>
|
||||||
? 'Reconnecting to the API server...'
|
{isReconnecting
|
||||||
: `Lost connection to the API server. Reconnecting in ${reconnectSecondsRemaining} second${
|
? 'Reconnecting to the API server...'
|
||||||
reconnectSecondsRemaining === 1 ? '' : 's'
|
: `Lost connection to the API server. Reconnecting in ${reconnectSecondsRemaining} second${
|
||||||
}...`}
|
reconnectSecondsRemaining === 1 ? '' : 's'
|
||||||
</Text>
|
}...`}
|
||||||
<ProgressDisplay
|
</Text>
|
||||||
percent={isReconnecting ? 0 : 100 - reconnectProgress}
|
<ProgressDisplay
|
||||||
showInfo={false}
|
percent={isReconnecting ? 0 : 100 - reconnectProgress}
|
||||||
status={'exception'}
|
showInfo={false}
|
||||||
/>
|
status={'exception'}
|
||||||
</Flex>
|
/>
|
||||||
|
</Flex>
|
||||||
|
) : (
|
||||||
|
<Space size={'middle'}>
|
||||||
|
<LoadingOutlined />
|
||||||
|
<Text style={{ margin: 0 }}>Reconnecting, please wait...</Text>
|
||||||
|
</Space>
|
||||||
|
)}
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal
|
<Modal
|
||||||
title={
|
title={
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user