diff --git a/api/src/docker/aws-emulator.js b/api/src/docker/aws-emulator.js index 9885cc1..fae018d 100644 --- a/api/src/docker/aws-emulator.js +++ b/api/src/docker/aws-emulator.js @@ -1,6 +1,7 @@ const express = require('express') var cors = require('cors') const axios = require('axios') +const { restart } = require('nodemon') const app = express() const port = 8080 app.use(express.json()) @@ -10,19 +11,29 @@ const invocationURL = (port) => `http://localhost:${port}/2015-03-31/functions/function/invocations` app.post('/openscad/preview', async (req, res) => { - const { data } = await axios.post(invocationURL(5052), { - body: Buffer.from(JSON.stringify(req.body)).toString('base64'), - }) - res.status(data.statusCode) - res.send(data.body) + try { + const { data } = await axios.post(invocationURL(5052), { + body: Buffer.from(JSON.stringify(req.body)).toString('base64'), + }) + res.status(data.statusCode) + res.send(data.body) + } catch (e) { + res.status(500) + res.send() + } }) app.post('/cadquery/stl', async (req, res) => { console.log('making post request to 5060') - const { data } = await axios.post(invocationURL(5060), { - body: Buffer.from(JSON.stringify(req.body)).toString('base64'), - }) - res.status(data.statusCode) - res.send(data.body) + try { + const { data } = await axios.post(invocationURL(5060), { + body: Buffer.from(JSON.stringify(req.body)).toString('base64'), + }) + res.status(data.statusCode) + res.send(data.body) + } catch (e) { + res.status(500) + res.send() + } }) app.listen(port, () => { diff --git a/web/package.json b/web/package.json index 1c627c8..7aa3247 100644 --- a/web/package.json +++ b/web/package.json @@ -13,6 +13,7 @@ ] }, "dependencies": { + "@headlessui/react": "^1.0.0", "@material-ui/core": "^4.11.0", "@monaco-editor/react": "^4.0.11", "@redwoodjs/auth": "^0.30.1", diff --git a/web/src/Routes.js b/web/src/Routes.js index dd9d3dc..e7ec58d 100644 --- a/web/src/Routes.js +++ b/web/src/Routes.js @@ -35,7 +35,7 @@ const Routes = () => { ) return ( - + diff --git a/web/src/components/IdeEditor/IdeEditor.js b/web/src/components/IdeEditor/IdeEditor.js index bbc0edd..498ba9d 100644 --- a/web/src/components/IdeEditor/IdeEditor.js +++ b/web/src/components/IdeEditor/IdeEditor.js @@ -12,25 +12,6 @@ const IdeEditor = () => { openScad: 'cpp', } - const scriptKey = 'encoded_script' - useEffect(() => { - // load code from hash if it's there - let hash - if (isBrowser) { - hash = window.location.hash - } - const [key, scriptBase64] = hash.slice(1).split('=') - if (key === scriptKey) { - const script = atob(scriptBase64) - thunkDispatch({ type: 'updateCode', payload: script }) - } - }, []) - useEffect(() => { - if (isBrowser) { - window.location.hash = '' - } - }, [state.code]) - function handleCodeChange(value, _event) { thunkDispatch({ type: 'updateCode', payload: value }) } @@ -61,6 +42,7 @@ const IdeEditor = () => { . . . loading}> { +const IdeToolbarNew = ({ cadPackage }) => { const [state, thunkDispatch] = useIdeState() - function setIdeType(ide) { - thunkDispatch({ type: 'setIdeType', payload: { message: ide } }) - } + const scriptKey = 'encoded_script' + useEffect(() => { + thunkDispatch({ + type: 'initIde', + payload: { cadPackage }, + }) + // load code from hash if it's there + let hash + if (isBrowser) { + hash = window.location.hash + } + const [key, scriptBase64] = hash.slice(1).split('=') + if (key === scriptKey) { + const script = atob(scriptBase64) + thunkDispatch({ type: 'updateCode', payload: script }) + } + window.location.hash = '' + setTimeout(() => handleRender()) // definitely a little hacky, timeout with no delay is just to push it into the next event loop. + }, [cadPackage]) function handleRender() { thunkDispatch((dispatch, getState) => { const state = getState() @@ -37,14 +53,6 @@ const IdeToolbarNew = () => {