Skip to content

Add drag-and-drop site reordering with sortOrder persistence#2498

Open
mikaoelitiana wants to merge 25 commits intoAutomattic:trunkfrom
mikaoelitiana:588-reorder-sites-list
Open

Add drag-and-drop site reordering with sortOrder persistence#2498
mikaoelitiana wants to merge 25 commits intoAutomattic:trunkfrom
mikaoelitiana:588-reorder-sites-list

Conversation

@mikaoelitiana
Copy link

@mikaoelitiana mikaoelitiana commented Jan 28, 2026

Summary

This PR implements drag-and-drop site reordering functionality. Users can now reorder sites in the sidebar by dragging and dropping them, with the new sort order being saved to disk. Existing sites without a sort order will be sorted alphabetically after those with an explicit order.

The main changes involve making site items draggable and updating sortOrder property upon item drop. This new field is added to the data stored locally.

Enregistrement.de.l.ecran.2026-02-06.a.10.40.16.mov

Resolves #588

@mikaoelitiana mikaoelitiana marked this pull request as ready for review February 3, 2026 09:28
@profucius
Copy link

Hi there, thanks for taking this feature! I watched your video above and it looks great so far.

@wojtekn wojtekn mentioned this pull request Feb 4, 2026
@wojtekn
Copy link
Contributor

wojtekn commented Feb 4, 2026

Thanks for working on that @mikaoelitiana .

I think we could drop the drag indicator to keep the interface cleaner.

I opened #2531 to trigger CI.

@wojtekn wojtekn requested a review from a team February 4, 2026 12:39
@mikaoelitiana
Copy link
Author

Thanks for working on that @mikaoelitiana .

I think we could drop the drag indicator to keep the interface cleaner.

I opened #2531 to trigger CI.

OK I will remove it

@mikaoelitiana
Copy link
Author

@wojtekn I have remove the drag icon and updated the video on the PR description

Copy link
Contributor

@bcotrim bcotrim left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @mikaoelitiana and welcome to the project!

I added some comments, please let me know what you think.

setSites( updatedSites );
}, [] );

const reorderSites = useCallback( async ( updates: { siteId: string; sortOrder: number }[] ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The reorder should update the UI optimistically — call setSites with the new order immediately, then persist to the ipc in the background (ideally debounced to avoid excessive writes during rapid drag-and-drop). Right now the list waits for the full IPC roundtrip before reflecting the new order, which causes a visible delay.

Copy link
Author

Choose a reason for hiding this comment

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

@bcotrim I made some refactoring to address your comments. For the debounce part, I checked if we already do that somewhere in the project but I don't seem to find anything. Do you think we should install a dependency for that or create it in-house?

Copy link
Contributor

@bcotrim bcotrim Feb 11, 2026

Choose a reason for hiding this comment

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

No need for an external dependency, a simple setTimeout/clearTimeout with a useRef does the trick. The key is to keep setSites immediate (optimistic) and only debounce the IPC persist:

const saveTimeoutRef = useRef< ReturnType< typeof setTimeout > >();
const DEBOUNCE_SAVE_MS = 300;

const updateSitesSortOrder = useCallback( ( sites: SiteDetails[] ) => {
    setSites( sites );

    const updates = sites.map( ( site, index ) => ( {
        siteId: site.id,
        sortOrder: ( index + 1 ) * 1000,
    } ) );

    clearTimeout( saveTimeoutRef.current );
    saveTimeoutRef.current = setTimeout( () => {
        getIpcApi().updateSitesSortOrder( updates );
    }, DEBOUNCE_SAVE_MS );
}, [] );

- rename function to updateSitesSortOrder
- optimistically call setSites first then call IPC method
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

4 participants

Comments