Skip to content

Add dnd-kit sorting with wheel scrolling support#14

Closed
0suu wants to merge 1 commit into
suu/10-sort-device-listfrom
codex/add-scroll-support-while-sorting-in-dnd-kit-0z96tq
Closed

Add dnd-kit sorting with wheel scrolling support#14
0suu wants to merge 1 commit into
suu/10-sort-device-listfrom
codex/add-scroll-support-while-sorting-in-dnd-kit-0z96tq

Conversation

@0suu

@0suu 0suu commented Nov 26, 2025

Copy link
Copy Markdown
Owner

Summary

  • add dnd-kit dependencies for sortable drag-and-drop handling
  • migrate device and scene reorder interactions to dnd-kit while keeping existing behaviors
  • ensure mouse wheel scrolling remains available during drag operations

Testing

  • Not run (npm install failed in container due to 403 from registry)

Codex Task

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @0suu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the drag-and-drop reordering capabilities for both device and scene lists. By migrating from a custom implementation to the dnd-kit library, the change aims to leverage a robust and well-maintained solution for sorting UI elements. The refactor ensures that the core reordering behavior remains consistent and that critical features like mouse wheel scrolling during drag operations are preserved.

Highlights

  • Integration of dnd-kit: The pull request introduces the dnd-kit library to manage drag-and-drop functionality for reordering UI elements.
  • Refactored Reordering Logic: Existing custom drag-and-drop implementations for both device and scene lists have been replaced with dnd-kit's sortable components and hooks, improving robustness and maintainability.
  • Preservation of Wheel Scrolling: The functionality for mouse wheel scrolling during drag operations has been explicitly maintained, ensuring a consistent user experience.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

Copy link
Copy Markdown

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 successfully migrates the drag-and-drop reordering functionality to dnd-kit, which is a great improvement for maintainability and user experience. The code is well-structured, particularly with the extraction of sortable item logic into new components. I've identified a few areas for improvement, including a UI bug in the drag-over handling, some unsafe type assertions that could lead to runtime errors, and a suggestion to further improve code organization by extracting large components into their own files. Overall, this is a solid update.

Comment on lines +227 to 233
const handleDragOver = (event: DragOverEvent) => {
if (!isReorderMode) return;
const overId = event.over?.id as string | undefined;
const activeId = event.active.id as string;
if (!overId || activeId === overId) return;
setDragOverId(overId);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The current implementation of handleDragOver has a bug where the drag-over highlight (the outline) can get stuck on an item. This happens if you drag over an item and then drag away to an area with no droppable items, or if you drag over the item that is currently being dragged. To fix this and also improve type safety, I suggest replacing this handler with a more robust version.

  const handleDragOver = (event: DragOverEvent) => {
    if (!isReorderMode) return;
    const { active, over } = event;
    const overId = over ? String(over.id) : null;

    // Do not highlight the item being dragged
    if (String(active.id) === overId) {
      setDragOverId(null);
      return;
    }

    setDragOverId(overId);
  };

Comment on lines +196 to 202
const handleDragOver = (event: DragOverEvent) => {
if (!isReorderMode) return;
const overId = event.over?.id as string | undefined;
const activeId = event.active.id as string;
if (!overId || overId === activeId) return;
setDragOverId(overId);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The current implementation of handleDragOver has a bug where the drag-over highlight (the outline) can get stuck on an item. This happens if you drag over an item and then drag away to an area with no droppable items, or if you drag over the item that is currently being dragged. To fix this and also improve type safety, I suggest replacing this handler with a more robust version.

  const handleDragOver = (event: DragOverEvent) => {
    if (!isReorderMode) return;
    const { active, over } = event;
    const overId = over ? String(over.id) : null;

    // Do not highlight the item being dragged
    if (String(active.id) === overId) {
      setDragOverId(null);
      return;
    }

    setDragOverId(overId);
  };

const handleDragStart = (id: string) => (event: React.DragEvent<HTMLDivElement>) => {
const handleDragStart = (event: DragStartEvent) => {
if (!isReorderMode) return;
const id = event.active.id as string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using as string for the event ID is not type-safe, as dnd-kit's UniqueIdentifier type is string | number. If the ID were ever a number, this could cause issues with functions like moveIdInList that expect strings. It's safer to explicitly convert it to a string using String().

Suggested change
const id = event.active.id as string;
const id = String(event.active.id);

}
const { active, over } = event;
if (over && active.id !== over.id) {
setReorderList((prev) => moveIdInList(prev, active.id as string, over.id as string));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to handleDragStart, using as string here is not type-safe. The IDs from the dnd-kit event should be explicitly converted to strings to ensure they match the expected type for moveIdInList.

      setReorderList((prev) => moveIdInList(prev, String(active.id), String(over.id)));

}
};

const SortableDeviceCard: React.FC<{ device: AnyDevice }> = ({ device }) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better code organization and maintainability, this SortableDeviceCard component should be extracted into its own file (e.g., src/renderer/src/components/SortableDeviceCard.tsx). This component contains significant presentational and behavioral logic, and placing it in a separate file will make DeviceListScreen cleaner and the new component more reusable.

setDraggingId(id);
const handleDragStart = (event: DragStartEvent) => {
if (!isReorderMode) return;
setDraggingId(event.active.id as string);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using as string for the event ID is not type-safe, as dnd-kit's UniqueIdentifier type is string | number. If the ID were ever a number, this would cause issues. It's safer to explicitly convert it to a string using String().

Suggested change
setDraggingId(event.active.id as string);
setDraggingId(String(event.active.id));

}
const { active, over } = event;
if (over && active.id !== over.id) {
setReorderList((prev) => moveIdInList(prev, active.id as string, over.id as string));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to handleDragStart, using as string here is not type-safe. The IDs from the dnd-kit event should be explicitly converted to strings to ensure they match the expected type for moveIdInList.

      setReorderList((prev) => moveIdInList(prev, String(active.id), String(over.id)));

}
};

const SortableSceneCard: React.FC<{ scene: SceneSummary; isExecuting: boolean; sceneError?: string }>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This SortableSceneCard component is quite large (over 100 lines) and contains significant logic. For better code organization, readability, and maintainability, it should be extracted into its own file (e.g., src/renderer/src/components/SortableSceneCard.tsx). This will make the ScenesScreen component much cleaner and easier to understand.

@0suu 0suu closed this Nov 26, 2025
@0suu
0suu deleted the codex/add-scroll-support-while-sorting-in-dnd-kit-0z96tq branch December 29, 2025 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant