-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added diagram preview and edit functionality
- Loading branch information
Showing
10 changed files
with
269 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/client/preview-diagram-dialog/components/preview-diagram-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { buildUrl } from '../../utils/helpers'; | ||
import useAuth from '../../hooks/useAuth'; | ||
import { CircularProgress, Container, Typography } from '@mui/material'; | ||
|
||
const previewUrl = localStorage.getItem('previewUrl'); | ||
|
||
const PreviewDiagramDialog = () => { | ||
const { authState, authStatus } = useAuth(); | ||
const [diagramsUrl, setDiagramsUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
if (!authState?.authorized || !previewUrl) return; | ||
const url = buildUrl(previewUrl, authState.token); | ||
setDiagramsUrl(url); | ||
}, [authState, previewUrl]); | ||
Check warning on line 16 in src/client/preview-diagram-dialog/components/preview-diagram-dialog.tsx GitHub Actions / lint
|
||
|
||
if (authStatus === 'idle' || authStatus === 'loading') { | ||
return ( | ||
<Container | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
height: '96.5vh', | ||
}} | ||
> | ||
<CircularProgress /> | ||
</Container> | ||
); | ||
} | ||
|
||
if (authStatus === 'error') { | ||
return ( | ||
<Container | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
height: '96.5vh', | ||
}} | ||
> | ||
<Typography variant="h5" gutterBottom my={2} textAlign="center"> | ||
Error | ||
</Typography> | ||
<Typography paragraph textAlign="center"> | ||
Something went wrong. Please try again later. | ||
</Typography> | ||
</Container> | ||
); | ||
} | ||
|
||
return ( | ||
<div style={{ padding: '3px', overflowX: 'hidden', height: '100%' }}> | ||
<iframe | ||
src={diagramsUrl} | ||
title="diagrams" | ||
style={{ | ||
border: 'none', | ||
width: '100%', | ||
height: '96.5vh', | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PreviewDiagramDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<base target="_top" /> | ||
<!-- Add any external scripts and stylesheets here --> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/[email protected]/umd/react.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/@mui/[email protected]/umd/material-ui.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/[email protected]/dist/index.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/@types/[email protected]/index.d.ts" | ||
></script> | ||
</head> | ||
<body> | ||
<section id="index"> | ||
<script type="module" src="./index.jsx"></script> | ||
<!-- bundled js and css will get inlined here during build--> | ||
</section> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import ReactDOM from 'react-dom'; | ||
import PreviewDiagramDialog from './components/preview-diagram-dialog'; | ||
import './styles.css'; | ||
|
||
const container = document.getElementById('index'); | ||
const root = ReactDOM.createRoot(container); | ||
root.render(<PreviewDiagramDialog />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* needed to make consistent test snapshots across OSs */ | ||
body { | ||
font-family: Arial !important; | ||
} |
Oops, something went wrong.