Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store canvas position of scene comments. #4791

Merged
merged 16 commits into from
Jan 25, 2024

Conversation

gbalint
Copy link
Contributor

@gbalint gbalint commented Jan 24, 2024

Problem:
When a scene is deleted, the scene comments are orphaned, and we are not able to position them on the canvas.

Fix:
Change the liveblocks thread representation to store the local position of the thread in the scene (sceneX and sceneY) and the canvas position (x and y) both.

Note, that we can only add strings/numbers/booleans to the thread metadata type, so there is no way to create a more structured typing.

The advantage of this representation is that x and y always represents the canvas position of the thread, which was a more ambiguous earlier (canvas position for canvas comments and local position for scene comments).

So we do the best effort to position the comment thread in its scene, but if the scene is not available for some reason (e.g. it has been deleted), we still put it on the same canvas position. We do not delete the scene information, so when the user presses undo to put back the scene, the comment thread automatically becomes a scene thread again.

When the scene is moved, we update the canvas location of its scene comments using a React component called CommentMaintainer (which doesn't render anything, its role is just this maintenance step).

@gbalint gbalint marked this pull request as ready for review January 24, 2024 14:42
Copy link
Contributor

github-actions bot commented Jan 24, 2024

Try me

Copy link

relativeci bot commented Jan 24, 2024

Job #10064: Bundle Size — 62.38MiB (~+0.01%).

d4344c9(current) vs 8f5e3ac master#10060(baseline)

Warning

Bundle contains 66 duplicate packages – View duplicate packages

Bundle metrics  Change 3 changes Regression 1 regression
                 Current
Job #10064
     Baseline
Job #10060
Regression  Initial JS 45.57MiB(~+0.01%) 45.57MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 20.05% 19.94%
No change  Chunks 26 26
No change  Assets 30 30
Change  Modules 4396(+0.02%) 4395
No change  Duplicate Modules 475 475
No change  Duplicate Code 30.74% 30.74%
No change  Packages 462 462
No change  Duplicate Packages 65 65
Bundle size by type  Change 1 change Regression 1 regression
                 Current
Job #10064
     Baseline
Job #10060
Regression  JS 62.37MiB (~+0.01%) 62.36MiB
Not changed  HTML 11.54KiB 11.54KiB

View job #10064 reportView feature/autoconvert-scene-commen... branch activityView project dashboard

Copy link
Contributor

Performance test results:
(Chart1)
(Chart2)

y: number
sceneId?: string
sceneX?: number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this! what's the point of these being optional here and then have a separate SceneThreadMetadata where they are declared as non optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that canvas comments don't have these properties (sceneId, sceneX, sceneY), and we are only allowed to have string, number and boolean properties here, so no way to create a structured type.

Copy link
Contributor

@balazsbajorics balazsbajorics Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not CanvasThreadMetadata without these fields and SceneThreadMetadata with these fields, and then ThreadMetadata = CanvasThreadMetadata | SceneThreadMetadata

but better yet, why not make it a discriminated union type with a type: 'canvas' | 'scene'? I see on master there was some notion to do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not use discriminated union types because I can only add string/boolean/number fields.
Undiscrimated union types are not that nice to work with, but you can be right maybe this solution is better: 68b2418

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turned out the problem was not discriminated union types, but that I used interfaces and not types.... Here is the proper solution: dcc67bd

const scenes = useScenes()
const editThreadMetadata = useEditThreadMetadata()

threads.forEach(async (t): Promise<void> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to ask if subsequent calls to this can trample over each other, but I don't think they will because the promises would all be queued up in order.

@gbalint gbalint merged commit 03a218e into master Jan 25, 2024
11 of 12 checks passed
@gbalint gbalint deleted the feature/autoconvert-scene-comments branch January 25, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants