Skip to content

Commit

Permalink
Simpler constructor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gbalint committed Jan 26, 2024
1 parent ed128ac commit 22f3b2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
34 changes: 20 additions & 14 deletions editor/src/components/canvas/controls/comment-popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ import { RemixNavigationAtom } from '../remix/utopia-remix-root-component'
import { getIdOfScene } from './comment-mode/comment-mode-hooks'
import { motion, useAnimation } from 'framer-motion'
import type { EditorDispatch } from '../../editor/action-types'
import { utopiaThreadMetadataToLiveblocks } from '../../../core/commenting/comment-types'
import {
canvasThreadMetadata,
sceneThreadMetadata,
utopiaThreadMetadataToLiveblocks,
} from '../../../core/commenting/comment-types'

export const ComposerEditorClassName = 'lb-composer-editor'

Expand Down Expand Up @@ -153,11 +157,12 @@ const CommentThread = React.memo(({ comment }: CommentThreadProps) => {
case 'canvas':
const newThreadOnCanvas = createThread({
body,
metadata: utopiaThreadMetadataToLiveblocks({
type: 'canvas',
resolved: false,
position: comment.location.position,
}),
metadata: utopiaThreadMetadataToLiveblocks(
canvasThreadMetadata({
resolved: false,
position: comment.location.position,
}),
),
})
return [newThreadOnCanvas, []]
case 'scene':
Expand All @@ -181,14 +186,15 @@ const CommentThread = React.memo(({ comment }: CommentThreadProps) => {

const newThreadOnScene = createThread({
body,
metadata: utopiaThreadMetadataToLiveblocks({
type: 'scene',
resolved: false,
position: comment.location.position,
sceneId: sceneId,
scenePosition: comment.location.offset,
remixLocationRoute: remixRoute != null ? remixRoute.location.pathname : undefined,
}),
metadata: utopiaThreadMetadataToLiveblocks(
sceneThreadMetadata({
resolved: false,
position: comment.location.position,
sceneId: sceneId,
scenePosition: comment.location.offset,
remixLocationRoute: remixRoute != null ? remixRoute.location.pathname : undefined,
}),
),
})
return [newThreadOnScene, addSceneIdPropAction]
default:
Expand Down
36 changes: 8 additions & 28 deletions editor/src/core/commenting/comment-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,13 @@ export type SceneThreadMetadata = BaseThreadMetadata & {
}

export function canvasThreadMetadata(
position: CanvasPoint,
resolved: boolean = false,
data: Omit<CanvasThreadMetadata, 'type'>,
): CanvasThreadMetadata {
return {
type: 'canvas',
position: position,
resolved: resolved,
}
return { ...data, type: 'canvas' }
}

export function sceneThreadMetadata(
position: CanvasPoint,
sceneId: string,
scenePosition: LocalPoint,
remixLocationRoute?: string,
resolved: boolean = false,
): SceneThreadMetadata {
return {
type: 'scene',
position: position,
sceneId: sceneId,
scenePosition: scenePosition,
remixLocationRoute: remixLocationRoute,
resolved: resolved,
}
export function sceneThreadMetadata(data: Omit<SceneThreadMetadata, 'type'>): SceneThreadMetadata {
return { ...data, type: 'scene' }
}

export function isSceneThreadMetadata(
Expand All @@ -63,19 +45,17 @@ export function isCanvasThreadMetadata(

export function liveblocksThreadMetadataToUtopia(metadata: ThreadMetadata): UtopiaThreadMetadata {
if (metadata.sceneId != null && metadata.sceneX != null && metadata.sceneY != null) {
return {
type: 'scene',
return sceneThreadMetadata({
position: canvasPoint(metadata),
sceneId: metadata.sceneId,
scenePosition: localPoint({ x: metadata.sceneX, y: metadata.sceneY }),
resolved: metadata.resolved,
}
})
} else {
return {
type: 'canvas',
return canvasThreadMetadata({
position: canvasPoint(metadata),
resolved: metadata.resolved,
}
})
}
}

Expand Down

0 comments on commit 22f3b2b

Please sign in to comment.