fix(reorder): only show end-of-list drop zone during active reorder drag; reset hover indicators on drag end
This commit is contained in:
parent
d0a83a85f5
commit
ac52441dd1
@ -171,6 +171,7 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const [dragHoverIndex, setDragHoverIndex] = useState<number | null>(null);
|
||||
const [endDropHover, setEndDropHover] = useState<boolean>(false);
|
||||
const [isReorderDragging, setIsReorderDragging] = useState<boolean>(false);
|
||||
|
||||
// Store current values in refs to avoid stale closures
|
||||
const hasMoreRef = useRef(hasMore);
|
||||
@ -258,6 +259,9 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
|
||||
const handleDragEnd = useCallback(() => {
|
||||
setIsDragging(false);
|
||||
setIsReorderDragging(false);
|
||||
setEndDropHover(false);
|
||||
setDragHoverIndex(null);
|
||||
dragSelectionRef.current = null;
|
||||
}, []);
|
||||
|
||||
@ -280,7 +284,7 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
e.preventDefault();
|
||||
setDragHoverIndex(index);
|
||||
}}
|
||||
onRowDrop={async (e: React.DragEvent) => {
|
||||
onRowDrop={async (e: React.DragEvent) => {
|
||||
if (!onReorder || !currentPlaylist || selectedSongs.size > 0) return;
|
||||
e.preventDefault();
|
||||
const fromId = e.dataTransfer.getData('text/song-id');
|
||||
@ -303,7 +307,8 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
console.debug('[Reorder] move request', { playlist: currentPlaylist, fromId, toId });
|
||||
await api.moveTrackInPlaylist(currentPlaylist, fromId, toId);
|
||||
await onReorder(songs.map(s => s.id)); // trigger refresh via parent
|
||||
setDragHoverIndex(null);
|
||||
setDragHoverIndex(null);
|
||||
setIsReorderDragging(false);
|
||||
}}
|
||||
onRowDragStartCapture={(e: React.DragEvent) => {
|
||||
// Provide a simple id for intra-list reorder
|
||||
@ -313,6 +318,7 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
// Explicitly set effect to move for better UX
|
||||
try { e.dataTransfer.effectAllowed = 'move'; } catch {}
|
||||
try { e.dataTransfer.dropEffect = 'move'; } catch {}
|
||||
setIsReorderDragging(true);
|
||||
}}
|
||||
/>
|
||||
));
|
||||
@ -503,7 +509,7 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
</Box>
|
||||
|
||||
{/* Drop zone to move item to end of playlist */}
|
||||
{onReorder && currentPlaylist && selectedSongs.size === 0 && (
|
||||
{onReorder && currentPlaylist && selectedSongs.size === 0 && isReorderDragging && (
|
||||
<Box
|
||||
onDragOver={(e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
@ -521,7 +527,9 @@ export const PaginatedSongList: React.FC<PaginatedSongListProps> = memo(({
|
||||
await api.moveTrackInPlaylist(currentPlaylist, fromId);
|
||||
await onReorder(songs.map(s => s.id));
|
||||
setEndDropHover(false);
|
||||
setIsReorderDragging(false);
|
||||
}}
|
||||
onDragEnd={handleDragEnd}
|
||||
position="relative"
|
||||
height="28px"
|
||||
mt={1}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user