Skip to content

Conversation

@mikaoelitiana
Copy link

@mikaoelitiana mikaoelitiana commented Jan 28, 2026

Summary

This PR implements drag-and-drop site reordering functionality as requested in #588. Users can now reorder sites in the sidebar by dragging and dropping them.

Resolves #588

Changes

Core Implementation

  1. Added sortOrder field to site data model (src/ipc-types.d.ts)

    • Optional sortOrder?: number field on StoppedSiteDetails
    • Sites without sortOrder are sorted alphabetically at the end
  2. Updated sorting logic (common/lib/sort-sites.ts)

    • Modified sortSites() to prioritize sortOrder over name
    • Sites with sortOrder appear before those without
  3. Added IPC handler for persistence (src/ipc-handlers.ts)

    • New updateSitesSortOrder handler to save sort order atomically
    • Uses file locking for safe concurrent access
  4. Updated data persistence (src/storage/user-data.ts)

    • Added sortOrder to toDiskFormat() to persist the field to disk
  5. Exposed IPC method (src/preload.ts)

    • Added updateSitesSortOrder to the renderer API

UI Implementation

  1. Added drag-and-drop handlers (src/components/site-menu.tsx)

    • handleDragStart, handleDragOver, handleDrop, handleDragEnd
    • Drag handle icon from @wordpress/icons
    • Visual hover effect when dragging over items (bg-[#ffffff26])
    • Drop zone at bottom of list for dragging to end
  2. Added context method (src/hooks/use-site-details.tsx)

    • New reorderSites() method in context
    • Automatically refreshes sites after reordering

Testing

  1. Added comprehensive tests (common/lib/tests/sort-sites.test.ts)
    • Test sorting by sortOrder
    • Test prioritization of sortOrder over name
    • Test mixed sites with and without sortOrder

How It Works

  1. Sparse Integer Strategy: Uses values like 1000, 2000, 3000... to allow inserting between items without renumbering
  2. Immediate Feedback: Local state updates for instant visual feedback during drag
  3. Persistence: Sort order saved to appdata-v1.json immediately on drop
  4. Context Refresh: Sites re-fetched from disk after save to keep UI in sync

Backward Compatibility

  • Existing sites without sortOrder continue to work
  • They sort alphabetically after sites with explicit ordering
  • Gradual adoption as users reorder sites

Fixes #588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Reorder sites on the left sidebar

1 participant