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) {
|
||||
// Ensure unique order and only include known IDs
|
||||
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;
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -129,7 +129,8 @@ const RekordboxReader: React.FC = () => {
|
||||
totalDuration,
|
||||
loadNextPage,
|
||||
searchSongs,
|
||||
searchQuery
|
||||
searchQuery,
|
||||
refresh
|
||||
} = usePaginatedSongs({ pageSize: 100, playlistName: currentPlaylist });
|
||||
|
||||
// Export library to XML
|
||||
@ -656,11 +657,7 @@ const RekordboxReader: React.FC = () => {
|
||||
// Persist order in backend
|
||||
await api.reorderPlaylist(currentPlaylist, orderedIds);
|
||||
// Refresh the current playlist view
|
||||
// Easiest: refetch page 1 to reflect new order
|
||||
// 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
|
||||
refresh();
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
@ -282,20 +282,33 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
if (!onReorder || !currentPlaylist || selectedSongs.size > 0) return;
|
||||
e.preventDefault();
|
||||
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 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 [moved] = ordered.splice(fromIndex, 1);
|
||||
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);
|
||||
}}
|
||||
onRowDragStartCapture={(e: React.DragEvent) => {
|
||||
// Provide a simple id for intra-list reorder
|
||||
if (!currentPlaylist || selectedSongs.size > 0) return;
|
||||
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