/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors
*
* SPDX-License-Identifier: EPL-2.0
*/
import CloudIcon from '@mui/icons-material/Cloud';
import CloudOffIcon from '@mui/icons-material/CloudOff';
import SyncIcon from '@mui/icons-material/Sync';
import SyncProblemIcon from '@mui/icons-material/SyncProblem';
import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
import { keyframes, styled } from '@mui/material/styles';
import { observer } from 'mobx-react-lite';
import type EditorStore from './EditorStore';
const rotateKeyframe = keyframes`
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(-360deg);
}
`;
const AnimatedSyncIcon = styled(SyncIcon)`
animation: ${rotateKeyframe} 1.4s linear infinite;
`;
export default observer(function ConnectButton({
editorStore,
}: {
editorStore: EditorStore | undefined;
}): JSX.Element {
if (
editorStore !== undefined &&
(editorStore.opening || editorStore.opened)
) {
return (
editorStore.disconnect()}
aria-label="Disconnect"
color="inherit"
>
{editorStore.opening ? (
) : (
)}
);
}
let title: string;
let disconnectedIcon: JSX.Element;
if (editorStore === undefined) {
title = 'Connecting';
disconnectedIcon = ;
} else if (editorStore.connectionErrors.length > 0) {
title = 'Connection error (click to retry)';
disconnectedIcon = ;
} else {
title = 'Disconnected (click to connect)';
disconnectedIcon = ;
}
return (
editorStore?.connect()}
aria-label="Connect"
color="inherit"
>
{disconnectedIcon}
);
});