Bunch of tweaks

Resolves #225 and # 226
a weird state issue and some formatting
This commit is contained in:
Kurt Hutten
2021-03-10 20:47:40 +11:00
parent 3058170057
commit 02de0927ba
5 changed files with 60 additions and 17 deletions

View File

@@ -31,7 +31,8 @@ function Controls({ onCameraChange }) {
})
}
controls.current.addEventListener('end', callback)
return () => controls.current.removeEventListener('end', callback)
const oldCurrent = controls.current
return () => oldCurrent.removeEventListener('end', callback)
}
}, [])
@@ -69,7 +70,7 @@ function Box(props) {
</mesh>
)
}
let currentCode // I have no idea why this works and using state.code is the dispatch doesn't but it was always stale
const IdeViewer = () => {
const { state, dispatch } = useContext(IdeContext)
const [isDragging, setIsDragging] = useState(false)
@@ -81,6 +82,7 @@ const IdeViewer = () => {
window.URL.createObjectURL(state.objectData?.data),
[state.objectData]
)
currentCode = state.code
return (
<div className="p-8 border-2 m-2">
<div className="pb-4">
@@ -113,7 +115,7 @@ const IdeViewer = () => {
dispatch({
type: 'render',
payload: {
code: state.code,
code: currentCode,
camera: {
position,
rotation,