refactor(striker-ui): migrate MUI v4->5 on Display/FullSize

main
Tsu-ba-me 3 years ago
parent a887a03b33
commit 61438a8de4
  1. 69
      striker-ui/components/Display/FullSize.tsx

@ -1,11 +1,16 @@
import { useState, useRef, useEffect, Dispatch, SetStateAction } from 'react'; import { useState, useRef, useEffect, Dispatch, SetStateAction } from 'react';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { Box, Menu, MenuItem, Button } from '@material-ui/core'; import {
import Typography from '@mui/material/Typography'; Box,
import { makeStyles } from '@material-ui/core/styles'; Button,
import CloseIcon from '@material-ui/icons/Close'; IconButton,
import KeyboardIcon from '@material-ui/icons/Keyboard'; Menu,
import IconButton from '@material-ui/core/IconButton'; MenuItem,
Typography,
} from '@mui/material';
import { styled } from '@mui/material/styles';
import CloseIcon from '@mui/icons-material/Close';
import KeyboardIcon from '@mui/icons-material/Keyboard';
import RFB from '@novnc/novnc/core/rfb'; import RFB from '@novnc/novnc/core/rfb';
import { Panel } from '../Panels'; import { Panel } from '../Panels';
import { BLACK, RED, TEXT } from '../../lib/consts/DEFAULT_THEME'; import { BLACK, RED, TEXT } from '../../lib/consts/DEFAULT_THEME';
@ -15,10 +20,21 @@ import putFetchWithTimeout from '../../lib/fetchers/putFetchWithTimeout';
import { HeaderText } from '../Text'; import { HeaderText } from '../Text';
import Spinner from '../Spinner'; import Spinner from '../Spinner';
const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false }); const PREFIX = 'FullSize';
const classes = {
displayBox: `${PREFIX}-displayBox`,
spinnerBox: `${PREFIX}-spinnerBox`,
closeButton: `${PREFIX}-closeButton`,
keyboardButton: `${PREFIX}-keyboardButton`,
closeBox: `${PREFIX}-closeBox`,
buttonsBox: `${PREFIX}-buttonsBox`,
keysItem: `${PREFIX}-keysItem`,
buttonText: `${PREFIX}-buttonText`,
};
const useStyles = makeStyles(() => ({ const StyledDiv = styled('div')(() => ({
displayBox: { [`& .${classes.displayBox}`]: {
width: '75vw', width: '75vw',
height: '75vh', height: '75vh',
paddingTop: '1em', paddingTop: '1em',
@ -26,47 +42,56 @@ const useStyles = makeStyles(() => ({
paddingLeft: 0, paddingLeft: 0,
paddingRight: 0, paddingRight: 0,
}, },
spinnerBox: {
[`& .${classes.spinnerBox}`]: {
flexDirection: 'column', flexDirection: 'column',
width: '75vw', width: '75vw',
height: '75vh', height: '75vh',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}, },
closeButton: {
[`& .${classes.closeButton}`]: {
borderRadius: 8, borderRadius: 8,
backgroundColor: RED, backgroundColor: RED,
'&:hover': { '&:hover': {
backgroundColor: RED, backgroundColor: RED,
}, },
}, },
keyboardButton: {
[`& .${classes.keyboardButton}`]: {
borderRadius: 8, borderRadius: 8,
backgroundColor: TEXT, backgroundColor: TEXT,
'&:hover': { '&:hover': {
backgroundColor: TEXT, backgroundColor: TEXT,
}, },
}, },
closeBox: {
[`& .${classes.closeBox}`]: {
paddingBottom: '1em', paddingBottom: '1em',
paddingLeft: '.7em', paddingLeft: '.7em',
paddingRight: 0, paddingRight: 0,
}, },
buttonsBox: {
[`& .${classes.buttonsBox}`]: {
paddingTop: 0, paddingTop: 0,
}, },
keysItem: {
[`& .${classes.keysItem}`]: {
backgroundColor: TEXT, backgroundColor: TEXT,
paddingRight: '3em', paddingRight: '3em',
'&:hover': { '&:hover': {
backgroundColor: TEXT, backgroundColor: TEXT,
}, },
}, },
buttonText: {
[`& .${classes.buttonText}`]: {
color: BLACK, color: BLACK,
}, },
})); }));
const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false });
interface FullSizeProps { interface FullSizeProps {
setMode: Dispatch<SetStateAction<boolean>>; setMode: Dispatch<SetStateAction<boolean>>;
uuid: string; uuid: string;
@ -90,7 +115,6 @@ const FullSize = ({
VncConnectionProps | undefined VncConnectionProps | undefined
>(undefined); >(undefined);
const [isError, setIsError] = useState<boolean>(false); const [isError, setIsError] = useState<boolean>(false);
const classes = useStyles();
useEffect(() => { useEffect(() => {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
@ -146,6 +170,7 @@ const FullSize = ({
return ( return (
<Panel> <Panel>
<StyledDiv>
<Box flexGrow={1}> <Box flexGrow={1}>
<HeaderText text={`Server: ${serverName}`} /> <HeaderText text={`Server: ${serverName}`} />
</Box> </Box>
@ -213,7 +238,9 @@ const FullSize = ({
<Box display="flex" className={classes.spinnerBox}> <Box display="flex" className={classes.spinnerBox}>
{!isError ? ( {!isError ? (
<> <>
<HeaderText text={`Establishing connection with ${serverName}`} /> <HeaderText
text={`Establishing connection with ${serverName}`}
/>
<HeaderText text="This may take a few minutes" /> <HeaderText text="This may take a few minutes" />
<Spinner /> <Spinner />
</> </>
@ -229,7 +256,10 @@ const FullSize = ({
}} }}
style={{ textTransform: 'none' }} style={{ textTransform: 'none' }}
> >
<Typography className={classes.buttonText} variant="subtitle1"> <Typography
className={classes.buttonText}
variant="subtitle1"
>
Reconnect Reconnect
</Typography> </Typography>
</Button> </Button>
@ -237,6 +267,7 @@ const FullSize = ({
)} )}
</Box> </Box>
)} )}
</StyledDiv>
</Panel> </Panel>
); );
}; };

Loading…
Cancel
Save