chore(reorder): add client debug logs; refresh playlist after reorder; backend keeps missing ids at end when reordering
This commit is contained in:
parent
50a486f6d8
commit
5a21243f5b
@ -96,7 +96,11 @@ router.post('/reorder', async (req: Request, res: Response) => {
|
|||||||
if (node.type === 'playlist' && node.name === playlistName) {
|
if (node.type === 'playlist' && node.name === playlistName) {
|
||||||
// Ensure unique order and only include known IDs
|
// Ensure unique order and only include known IDs
|
||||||
const unique = Array.from(new Set(orderedIds));
|
const unique = Array.from(new Set(orderedIds));
|
||||||
node.tracks = unique;
|
// If tracks exist, keep only ids present in unique, and append any tracks not included to preserve membership
|
||||||
|
const current: string[] = Array.isArray(node.tracks) ? node.tracks : [];
|
||||||
|
const orderedKnown = unique.filter(id => current.includes(id));
|
||||||
|
const missing = current.filter(id => !unique.includes(id));
|
||||||
|
node.tracks = [...orderedKnown, ...missing];
|
||||||
updated = true;
|
updated = true;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,8 @@ const RekordboxReader: React.FC = () => {
|
|||||||
totalDuration,
|
totalDuration,
|
||||||
loadNextPage,
|
loadNextPage,
|
||||||
searchSongs,
|
searchSongs,
|
||||||
searchQuery
|
searchQuery,
|
||||||
|
refresh
|
||||||
} = usePaginatedSongs({ pageSize: 100, playlistName: currentPlaylist });
|
} = usePaginatedSongs({ pageSize: 100, playlistName: currentPlaylist });
|
||||||
|
|
||||||
// Export library to XML
|
// Export library to XML
|
||||||
@ -656,11 +657,7 @@ const RekordboxReader: React.FC = () => {
|
|||||||
// Persist order in backend
|
// Persist order in backend
|
||||||
await api.reorderPlaylist(currentPlaylist, orderedIds);
|
await api.reorderPlaylist(currentPlaylist, orderedIds);
|
||||||
// Refresh the current playlist view
|
// Refresh the current playlist view
|
||||||
// Easiest: refetch page 1 to reflect new order
|
refresh();
|
||||||
// Future: keep local order optimistic
|
|
||||||
// For now, force reload songs by navigating to same route
|
|
||||||
// and resetting pagination via usePaginatedSongs hook
|
|
||||||
// noop here as hook likely fetches by API sort; backend will serve correct order when playlist songs endpoint respects track order
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@ -282,20 +282,33 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
|||||||
if (!onReorder || !currentPlaylist || selectedSongs.size > 0) return;
|
if (!onReorder || !currentPlaylist || selectedSongs.size > 0) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const fromId = e.dataTransfer.getData('text/song-id');
|
const fromId = e.dataTransfer.getData('text/song-id');
|
||||||
if (!fromId) return;
|
if (!fromId) {
|
||||||
|
console.debug('[Reorder] missing fromId');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const fromIndex = songs.findIndex(s => s.id === fromId);
|
const fromIndex = songs.findIndex(s => s.id === fromId);
|
||||||
const toIndex = index;
|
const toIndex = index;
|
||||||
if (fromIndex < 0 || toIndex < 0 || fromIndex === toIndex) return;
|
if (fromIndex < 0 || toIndex < 0) {
|
||||||
|
console.debug('[Reorder] invalid indexes', { fromIndex, toIndex });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fromIndex === toIndex) {
|
||||||
|
console.debug('[Reorder] same index drop');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const ordered = [...songs];
|
const ordered = [...songs];
|
||||||
const [moved] = ordered.splice(fromIndex, 1);
|
const [moved] = ordered.splice(fromIndex, 1);
|
||||||
ordered.splice(toIndex, 0, moved);
|
ordered.splice(toIndex, 0, moved);
|
||||||
await onReorder(ordered.map(s => s.id));
|
const orderedIds = ordered.map(s => s.id);
|
||||||
|
console.debug('[Reorder] persisting order', { fromIndex, toIndex, fromId, toId: songs[index].id });
|
||||||
|
await onReorder(orderedIds);
|
||||||
setDragHoverIndex(null);
|
setDragHoverIndex(null);
|
||||||
}}
|
}}
|
||||||
onRowDragStartCapture={(e: React.DragEvent) => {
|
onRowDragStartCapture={(e: React.DragEvent) => {
|
||||||
// Provide a simple id for intra-list reorder
|
// Provide a simple id for intra-list reorder
|
||||||
if (!currentPlaylist || selectedSongs.size > 0) return;
|
if (!currentPlaylist || selectedSongs.size > 0) return;
|
||||||
e.dataTransfer.setData('text/song-id', song.id);
|
e.dataTransfer.setData('text/song-id', song.id);
|
||||||
|
console.debug('[Reorder] drag start', { id: song.id, index });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user