Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
Update packages; add TSX support
Browse files Browse the repository at this point in the history
  • Loading branch information
Reselim committed Nov 19, 2021
1 parent 762bece commit 6798e7c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 48 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/lodash": "^4.14.177",
"@types/ms": "^0.7.31",
"@types/react": "^17.0.35",
"@types/styled-components": "^5.1.15",
"axios": "^0.21.4",
"babel-plugin-styled-components": "^1.13.3",
"binary-parser": "^1.9.2",
Expand All @@ -35,9 +36,9 @@
"react-reduce-motion": "^2.0.2",
"react-router": "^5.2.1",
"react-router-dom": "^5.3.0",
"react-spring": "^9.3.0",
"react-spring": "^9.3.1",
"react-window": "^1.8.6",
"socket.io-client": "^4.3.2",
"socket.io-client": "^4.4.0",
"styled-components": "^5.3.3",
"url-join": "^4.0.1"
},
Expand Down
87 changes: 51 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"
import styled from "styled-components"

import { Vector2 } from "@free-draw/moderation-client"
import ViewerContext from "./ViewerContext"

const ViewerPositionalOverlayElement = styled.div`
Expand All @@ -16,21 +16,28 @@ const ViewerPositionalOverlayElement = styled.div`
}
`

function ViewerPositionalOverlay(props) {
const { camera } = React.useContext(ViewerContext)
const ref = React.useRef()
function ViewerPositionalOverlay(props: {
position: Vector2,
ignoreScale?: boolean,
}) {
const context = React.useContext(ViewerContext)
if (!context) throw new Error("ViewerPositionalOverlay must be inside of a ViewerCanvas")
const { camera } = context

const ref = React.useRef() as React.RefObject<HTMLDivElement>

React.useEffect(() => {
const updatePosition = () => {
const onUpdate = () => {
const position = camera.position.inverse().add(props.position).multiplyScalar(camera.scale)
const scale = props.ignoreScale ? 1 : camera.scale
ref.current.style.transform = `translate(${position.x}px, ${position.y}px) scale(${scale})`
ref.current!.style.transform = `translate(${position.x}px, ${position.y}px) scale(${scale})`
}

updatePosition()

const listener = camera.on("update", updatePosition, { objectify: true })
return () => listener.off()
onUpdate()
camera.on("update", onUpdate)
return () => {
camera.off("update", onUpdate)
}
}, [ props.position, props.ignoreScale ])

return (
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"jsx": "react",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
Expand Down

0 comments on commit 6798e7c

Please sign in to comment.