import Button from '@mui/material/Button'; import { observer } from 'mobx-react-lite'; import { type SnackbarKey, useSnackbar } from 'notistack'; import React, { useEffect } from 'react'; import { ContrastThemeProvider } from '../theme/ThemeProvider'; import type EditorStore from './EditorStore'; const CONNECTING_DEBOUNCE_TIMEOUT = 250; export default observer(function ConnectionStatusNotification({ editorStore, }: { editorStore: EditorStore; }): null { const { opened, opening, connectionErrors } = editorStore; const { enqueueSnackbar, closeSnackbar } = useSnackbar(); useEffect(() => { if (opening) { let key: SnackbarKey | undefined; let timeout: number | undefined = setTimeout(() => { timeout = undefined; key = enqueueSnackbar('Connecting to Refinery', { persist: true, action: ( ), }); }, CONNECTING_DEBOUNCE_TIMEOUT); return () => { if (timeout !== undefined) { clearTimeout(timeout); } if (key !== undefined) { closeSnackbar(key); } }; } if (connectionErrors.length >= 1) { const key = enqueueSnackbar(
Connection error: {connectionErrors[0]} {connectionErrors.length >= 2 && ( <> {' '} and {connectionErrors.length - 1} more{' '} {connectionErrors.length >= 3 ? 'errors' : 'error'} )}
, { persist: !opened, variant: 'error', action: opened ? ( ) : ( ), }, ); return () => closeSnackbar(key); } if (!opened) { const key = enqueueSnackbar(
Not connected to Refinery: Some editing features might be degraded
, { action: ( ), }, ); return () => closeSnackbar(key); } return () => {}; }, [ editorStore, opened, opening, connectionErrors, closeSnackbar, enqueueSnackbar, ]); return null; });