Add drag-and-drop site reordering with sortOrder persistence#2498
Add drag-and-drop site reordering with sortOrder persistence#2498mikaoelitiana wants to merge 25 commits intoAutomattic:trunkfrom
Conversation
|
Hi there, thanks for taking this feature! I watched your video above and it looks great so far. |
|
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 |
|
@wojtekn I have remove the drag icon and updated the video on the PR description |
bcotrim
left a comment
There was a problem hiding this comment.
Thanks for the contribution @mikaoelitiana and welcome to the project!
I added some comments, please let me know what you think.
src/hooks/use-site-details.tsx
Outdated
| setSites( updatedSites ); | ||
| }, [] ); | ||
|
|
||
| const reorderSites = useCallback( async ( updates: { siteId: string; sortOrder: number }[] ) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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 );
}, [] );cd7226a to
d74908e
Compare
Co-authored-by: Bernardo Cotrim <bmmcotrim@gmail.com>
d74908e to
de143e7
Compare
- rename function to updateSitesSortOrder - optimistically call setSites first then call IPC method
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
sortOrderproperty 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