mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
[web] add disconnected state to offline indicator (#35378)
GitOrigin-RevId: 692dc16cee738a8b05353717044a4063c3dd8e8a
This commit is contained in:
+36
-8
@@ -1,6 +1,7 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import MaterialIcon from '@/shared/components/material-icon'
|
||||
import OLTooltip from '@/shared/components/ol/ol-tooltip'
|
||||
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
||||
|
||||
export function OfflineIndicatorContent() {
|
||||
const { t } = useTranslation()
|
||||
@@ -18,22 +19,49 @@ export function OfflineIndicatorContent() {
|
||||
)
|
||||
}
|
||||
|
||||
export function DisconnectedIndicatorContent() {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<div className="ide-redesign-toolbar-offline-indicator">
|
||||
<MaterialIcon type="wifi_off" />
|
||||
<span>{t('disconnected')}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function OfflineIndicatorVisual({ outOfSync }: { outOfSync: boolean }) {
|
||||
if (outOfSync) {
|
||||
return <DisconnectedIndicatorContent />
|
||||
}
|
||||
return <OfflineIndicatorContent />
|
||||
}
|
||||
|
||||
function OfflineIndicatorStatus({ outOfSync }: { outOfSync: boolean }) {
|
||||
const { t } = useTranslation()
|
||||
if (outOfSync) {
|
||||
return <span>{t('disconnected')}</span>
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<span>{t('you_re_offline')}</span>
|
||||
<span>{t('changes_saved_in_browser_sync_when_online')}</span>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default function OfflineIndicator({
|
||||
isOffline,
|
||||
}: {
|
||||
isOffline: boolean
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
const { outOfSync } = useIdeReactContext()
|
||||
// The live region div below must stay mounted at all times so screen
|
||||
// readers announce its contents when the offline state changes.
|
||||
return (
|
||||
<>
|
||||
{isOffline && <OfflineIndicatorContent />}
|
||||
{isOffline && <OfflineIndicatorVisual outOfSync={outOfSync} />}
|
||||
<div className="visually-hidden" role="status">
|
||||
{isOffline && (
|
||||
<>
|
||||
<span>{t('you_re_offline')}</span>
|
||||
<span>{t('changes_saved_in_browser_sync_when_online')}</span>
|
||||
</>
|
||||
)}
|
||||
{isOffline && <OfflineIndicatorStatus outOfSync={outOfSync} />}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user