Skip to content

Commit

Permalink
use editor ref
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggi committed Jan 9, 2024
1 parent a4dfd62 commit 7b4345b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions editor/src/components/inspector/sections/comment-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import {
useMyThreadReadStatus,
useReadThreads,
} from '../../../core/commenting/comment-hooks'
import { Substores, useEditorState, useSelectorWithCallback } from '../../editor/store/store-hook'
import {
Substores,
useEditorState,
useRefEditorState,
useSelectorWithCallback,
} from '../../editor/store/store-hook'
import { when } from '../../../utils/react-conditionals'
import {
getFirstComment,
Expand Down Expand Up @@ -231,16 +236,10 @@ const ThreadPreview = React.memo(({ thread }: ThreadPreviewProps) => {
const isOnAnotherRoute =
remixLocationRoute != null && remixLocationRoute !== remixState?.location.pathname

const canvasScale = useEditorState(
Substores.canvasOffset,
(store) => store.editor.canvas.scale,
'ThreadPreview canvasScale',
)
const canvasOffset = useEditorState(
Substores.canvasOffset,
(store) => store.editor.canvas.roundedCanvasOffset,
'ThreadPreview canvasOffset',
)
const editorRef = useRefEditorState((store) => ({
canvasScale: store.editor.canvas.scale,
canvasOffset: store.editor.canvas.roundedCanvasOffset,
}))

const onClick = React.useCallback(() => {
if (isOnAnotherRoute) {
Expand All @@ -262,7 +261,11 @@ const ThreadPreview = React.memo(({ thread }: ThreadPreviewProps) => {
height: canvasArea.height,
})

const windowLocation = canvasPointToWindowPoint(location, canvasScale, canvasOffset)
const windowLocation = canvasPointToWindowPoint(
location,
editorRef.current.canvasScale,
editorRef.current.canvasOffset,
)

// adds a padding of 250px around `location`
const windowRect = canvasRectangle({
Expand Down Expand Up @@ -291,8 +294,7 @@ const ThreadPreview = React.memo(({ thread }: ThreadPreviewProps) => {
location,
thread.id,
commentScene,
canvasScale,
canvasOffset,
editorRef,
])

const resolveThread = useResolveThread()
Expand Down

0 comments on commit 7b4345b

Please sign in to comment.