Skip to content

refactor(EditorApp, AddHoldModal): improve hold instance handling and…#22

Merged
eloiberlinger1 merged 2 commits into
mainfrom
linter-fix-2
Apr 20, 2026
Merged

refactor(EditorApp, AddHoldModal): improve hold instance handling and…#22
eloiberlinger1 merged 2 commits into
mainfrom
linter-fix-2

Conversation

@eloiberlinger1

Copy link
Copy Markdown
Member

… type safety

Copilot AI review requested due to automatic review settings April 20, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors parts of the editor frontend to improve type safety and avoid mutating hold instance objects derived from session data.

Changes:

  • Remove an unnecessary as number cast when checking addedHoldIds in AddHoldModal.
  • Avoid mutating SessionHoldInstance objects in EditorApp by creating a derived object with hold_instance_id.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontend/src/features/editor/components/AddHoldModal.tsx Uses the native `string
frontend/src/features/editor/EditorApp.tsx Stops mutating session hold instances by pushing a cloned object with hold_instance_id set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the hold model processing in EditorApp.tsx to use immutable object updates and removes an unnecessary type assertion in AddHoldModal.tsx. Feedback suggests using a Set to deduplicate GLB URLs in EditorApp.tsx to avoid redundant processing and improve efficiency.

Comment on lines 86 to 95
const holdModelsGLBURL: string[] = [];
if (session_data?.related_holds_collection) {
session_data.holds_collection_instances?.forEach((hold: SessionHoldInstance) => {
hold.hold_instance_id = hold.id;
holdModels.push(hold);
if (hold.hold_type?.glb_url) {
holdModelsGLBURL.push(hold.hold_type.glb_url);
const holdWithId = { ...hold, hold_instance_id: hold.id };
holdModels.push(holdWithId);
if (holdWithId.hold_type?.glb_url) {
holdModelsGLBURL.push(holdWithId.hold_type.glb_url);
}
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The holdModelsGLBURL array can accumulate many duplicate URLs if multiple hold instances share the same type. While useGLTF.preload likely handles duplicates internally, deduplicating the list here avoids redundant iterations and function calls in the useEffect at line 100. Using a Set is a more efficient way to collect unique URLs.

Suggested change
const holdModelsGLBURL: string[] = [];
if (session_data?.related_holds_collection) {
session_data.holds_collection_instances?.forEach((hold: SessionHoldInstance) => {
hold.hold_instance_id = hold.id;
holdModels.push(hold);
if (hold.hold_type?.glb_url) {
holdModelsGLBURL.push(hold.hold_type.glb_url);
const holdWithId = { ...hold, hold_instance_id: hold.id };
holdModels.push(holdWithId);
if (holdWithId.hold_type?.glb_url) {
holdModelsGLBURL.push(holdWithId.hold_type.glb_url);
}
});
}
const glbUrlSet = new Set<string>();
if (session_data?.related_holds_collection) {
session_data.holds_collection_instances?.forEach((hold: SessionHoldInstance) => {
const holdWithId = { ...hold, hold_instance_id: hold.id };
holdModels.push(holdWithId);
if (holdWithId.hold_type?.glb_url) {
glbUrlSet.add(holdWithId.hold_type.glb_url);
}
});
}
const holdModelsGLBURL = Array.from(glbUrlSet);

@eloiberlinger1 eloiberlinger1 merged commit 7d5c3c0 into main Apr 20, 2026
1 of 2 checks passed
@eloiberlinger1 eloiberlinger1 deleted the linter-fix-2 branch April 20, 2026 20:19
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.

2 participants