-
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.
- Loading branch information
Showing
23 changed files
with
822 additions
and
1,239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/dist | ||
/node_modules | ||
/node_modules | ||
|
||
tailwind.config.js | ||
vite.config.ts |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
{ | ||
"timeZone": "America/New_York", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"libraries": [ | ||
{ | ||
"userSymbol": "OAuth2", | ||
"version": "43", | ||
"libraryId": "1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF" | ||
} | ||
] | ||
}, | ||
"exceptionLogging": "STACKDRIVER", | ||
"oauthScopes": [ | ||
"https://www.googleapis.com/auth/script.container.ui", | ||
"https://www.googleapis.com/auth/spreadsheets" | ||
"https://www.googleapis.com/auth/script.external_request", | ||
"https://www.googleapis.com/auth/documents" | ||
], | ||
"addOns": { | ||
"common": { | ||
"name": "Mermaid Chart", | ||
"logoUrl": "https://www.mermaidchart.com/img/mermaid-chart-48.png", | ||
"useLocaleFromApp": true, | ||
"universalActions": [ | ||
{ | ||
"label": "Learn more about Mermaid Chart", | ||
"openLink": "www.mermaidchart.com" | ||
} | ||
], | ||
"layoutProperties": { | ||
"primaryColor": "#424242", | ||
"secondaryColor": "#ff3670" | ||
} | ||
} | ||
}, | ||
"runtimeVersion": "V8" | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { serverFunctions } from '../../utils/serverFunctions'; | ||
import { buildUrl, handleDialogClose } from '../../utils/helpers'; | ||
import useAuth from '../../hooks/useAuth'; | ||
|
||
const EditDialog = () => { | ||
const { authState, authStatus } = useAuth(); | ||
const [diagramsUrl, setDiagramsUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
if (!authState) return; | ||
const getMetadata = async () => { | ||
try { | ||
const metadata = await serverFunctions.readSelectedImageMetadata(); | ||
console.log(metadata, 'metadata'); | ||
if (typeof metadata === 'string') { | ||
const params = new URLSearchParams(metadata); | ||
const projectID = params.get('projectID'); | ||
const documentID = params.get('documentID'); | ||
const major = params.get('major'); | ||
const minor = params.get('minor'); | ||
if (projectID && documentID && major && minor && authState?.token) { | ||
const iframeUrl = buildUrl( | ||
`/app/projects/${projectID}/diagrams/${documentID}/version/v.${major}.${minor}/edit`, | ||
authState.token | ||
); | ||
setDiagramsUrl(iframeUrl); | ||
} | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
getMetadata(); | ||
}, [authState]); | ||
|
||
useEffect(() => { | ||
const handleMessage = async (e: MessageEvent) => { | ||
const action = e.data.action; | ||
console.log('action', action); | ||
if (action === 'save') { | ||
const data = e.data.data; | ||
const metadata = new URLSearchParams({ | ||
projectID: data.projectID, | ||
documentID: data.documentID, | ||
major: data.major, | ||
minor: data.minor, | ||
}); | ||
try { | ||
await serverFunctions.replaceSelectedImageWithBase64AndSize( | ||
data.diagramImage, | ||
metadata.toString() | ||
); | ||
handleDialogClose(); | ||
} catch (error) { | ||
console.error('Error updating image with metadata', error); | ||
} | ||
} | ||
}; | ||
|
||
window.addEventListener('message', handleMessage); | ||
|
||
return () => { | ||
window.removeEventListener('message', handleMessage); | ||
}; | ||
}, []); | ||
|
||
if (authStatus !== 'success' || !diagramsUrl) { | ||
return null; | ||
} | ||
|
||
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 EditDialog; |
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/react@18.2.0/umd/react.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/@mui/material@5.11.11/umd/material-ui.production.min.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/gas-client@1.1.1/dist/index.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/@types/react@18.2.66/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,6 @@ | ||
import ReactDOM from 'react-dom'; | ||
import EditDialog from './components/EditDialog'; | ||
|
||
import './styles.css'; | ||
|
||
ReactDOM.render(<EditDialog />, document.getElementById('index')); |
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; | ||
} |
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,40 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { serverFunctions } from '../utils/serverFunctions'; | ||
|
||
interface AuthState { | ||
authorized: boolean; | ||
token?: string; | ||
message?: string; | ||
} | ||
|
||
type Status = 'idle' | 'loading' | 'success' | 'error'; | ||
|
||
const useAuth = () => { | ||
const [authState, setAuthState] = useState<null | AuthState>(null); | ||
const [authStatus, setAuthStatus] = useState<Status>('idle'); | ||
|
||
const getAuth = useCallback(async () => { | ||
setAuthStatus('loading'); | ||
try { | ||
const state = await serverFunctions.getAuthorizationState(); | ||
setAuthState(state); | ||
setAuthStatus('success'); | ||
} catch (error) { | ||
console.log('Error getting auth data', error); | ||
setAuthStatus('error'); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
getAuth(); | ||
}, [getAuth]); | ||
|
||
const signOut = async () => { | ||
serverFunctions.resetOAuth(); | ||
setTimeout(getAuth, 2000); | ||
}; | ||
|
||
return { authState, authStatus, signOut }; | ||
}; | ||
|
||
export default useAuth; |
Oops, something went wrong.