fix(queue): correct remove-from-queue index and add history context menu

- Add remove_upcoming_track command that correctly maps upcoming index
  to actual queue index (handles shuffle mode properly)
- Update frontend to use remove_upcoming_track instead of remove_from_queue
- Add working context menu for history tracks (Add to Playlist, Track Info)
- Remove unused .track-menu CSS class
This commit is contained in:
vicrodh committed 2026-02-13 13:29:30 -06:00
1 parent 3a8ef43227
commit 8dcad203c7
5 files changed
+91 -28

No files matched your search

+8
View File
@@ -95,6 +95,14 @@ pub fn remove_from_queue(index: usize, state: State<'_, AppState>) -> Result<Opt
Ok(state.queue.remove_track(index)) Ok(state.queue.remove_track(index))
} }
/// Remove a track from the upcoming queue by its position in the upcoming list
/// (0 = first upcoming track, handles shuffle mode correctly)
#[tauri::command]
pub fn remove_upcoming_track(upcoming_index: usize, state: State<'_, AppState>) -> Result<Option<QueueTrack>, String> {
log::info!("Command: remove_upcoming_track - upcoming_index {}", upcoming_index);
Ok(state.queue.remove_upcoming_track(upcoming_index))
}
/// Move a track from one position to another in the queue /// Move a track from one position to another in the queue
#[tauri::command] #[tauri::command]
pub fn move_queue_track(from_index: usize, to_index: usize, state: State<'_, AppState>) -> Result<bool, String> { pub fn move_queue_track(from_index: usize, to_index: usize, state: State<'_, AppState>) -> Result<bool, String> {
+1
View File
@@ -555,6 +555,7 @@ pub fn run() {
commands::set_queue, commands::set_queue,
commands::clear_queue, commands::clear_queue,
commands::remove_from_queue, commands::remove_from_queue,
commands::remove_upcoming_track,
commands::move_queue_track, commands::move_queue_track,
commands::get_current_queue_track, commands::get_current_queue_track,
commands::peek_next_track, commands::peek_next_track,
+42
View File
@@ -237,6 +237,48 @@ impl QueueManager {
Some(removed) Some(removed)
} }
/// Remove a track by its position in the upcoming list (0 = first upcoming track)
/// This handles shuffle mode correctly by mapping the upcoming index to the actual track index
pub fn remove_upcoming_track(&self, upcoming_index: usize) -> Option<QueueTrack> {
let mut state = self.state.lock().unwrap();
// Calculate the actual track index based on the upcoming index
let actual_index = if state.shuffle {
// In shuffle mode, upcoming is built from shuffle_order starting at shuffle_position + 1
let shuffle_pos = state.shuffle_position + 1 + upcoming_index;
if shuffle_pos >= state.shuffle_order.len() {
return None;
}
state.shuffle_order[shuffle_pos]
} else {
// In normal mode, upcoming starts at current_index + 1
let curr_idx = state.current_index.unwrap_or(0);
curr_idx + 1 + upcoming_index
};
if actual_index >= state.tracks.len() {
return None;
}
log::info!("remove_upcoming_track: upcoming_index={} -> actual_index={}", upcoming_index, actual_index);
let removed = state.tracks.remove(actual_index);
// Adjust current index if needed
if let Some(curr_idx) = state.current_index {
if actual_index < curr_idx {
state.current_index = Some(curr_idx - 1);
} else if actual_index == curr_idx {
if curr_idx >= state.tracks.len() {
state.current_index = if state.tracks.is_empty() { None } else { Some(state.tracks.len() - 1) };
}
}
}
Self::regenerate_shuffle_order_internal(&mut state);
Some(removed)
}
/// Move a track from one position to another /// Move a track from one position to another
pub fn move_track(&self, from_index: usize, to_index: usize) -> bool { pub fn move_track(&self, from_index: usize, to_index: usize) -> bool {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
+37 -25
View File
@@ -78,6 +78,9 @@
// Context menu state for queue tracks // Context menu state for queue tracks
let openMenuIndex = $state<number | null>(null); let openMenuIndex = $state<number | null>(null);
// Context menu state for history tracks
let openHistoryMenuId = $state<string | null>(null);
// Display limit // Display limit
const DISPLAY_LIMIT = 20; const DISPLAY_LIMIT = 20;
let displayCount = $state(DISPLAY_LIMIT); let displayCount = $state(DISPLAY_LIMIT);
@@ -226,14 +229,23 @@
onClose(); onClose();
} }
// Context menu handlers // Context menu handlers for queue tracks
function toggleTrackMenu(e: MouseEvent, index: number) { function toggleTrackMenu(e: MouseEvent, index: number) {
e.stopPropagation(); e.stopPropagation();
openHistoryMenuId = null; // Close any open history menu
openMenuIndex = openMenuIndex === index ? null : index; openMenuIndex = openMenuIndex === index ? null : index;
} }
// Context menu handlers for history tracks
function toggleHistoryMenu(e: MouseEvent, trackId: string) {
e.stopPropagation();
openMenuIndex = null; // Close any open queue menu
openHistoryMenuId = openHistoryMenuId === trackId ? null : trackId;
}
function closeMenu() { function closeMenu() {
openMenuIndex = null; openMenuIndex = null;
openHistoryMenuId = null;
} }
function handleRemoveFromQueue(e: MouseEvent, index: number) { function handleRemoveFromQueue(e: MouseEvent, index: number) {
@@ -256,7 +268,7 @@
// Close menu when clicking outside // Close menu when clicking outside
function handlePanelClick() { function handlePanelClick() {
if (openMenuIndex !== null) { if (openMenuIndex !== null || openHistoryMenuId !== null) {
closeMenu(); closeMenu();
} }
} }
@@ -422,11 +434,28 @@
<div class="track-artist">{track.artist}</div> <div class="track-artist">{track.artist}</div>
</div> </div>
<span class="track-duration">{track.duration}</span> <span class="track-duration">{track.duration}</span>
{#if hoveredHistoryTrack === track.id} <div class="track-menu-container">
<button class="track-menu" onclick={(e) => e.stopPropagation()}> <button
class="track-menu-btn"
class:visible={hoveredHistoryTrack === track.id || openHistoryMenuId === track.id}
onclick={(e) => toggleHistoryMenu(e, track.id)}
title={$t('actions.more')}
>
<MoreVertical size={16} /> <MoreVertical size={16} />
</button> </button>
{/if} {#if openHistoryMenuId === track.id}
<div class="track-context-menu">
<button class="menu-item" onclick={(e) => handleAddToPlaylist(e, track.id)}>
<ListPlus size={14} />
<span>{$t('actions.addToPlaylist')}</span>
</button>
<button class="menu-item" onclick={(e) => handleShowTrackInfo(e, track.id)}>
<Info size={14} />
<span>{$t('player.trackInfo')}</span>
</button>
</div>
{/if}
</div>
</div> </div>
{/each} {/each}
{#if historyTracks.length > historyDisplayCount} {#if historyTracks.length > historyDisplayCount}
@@ -851,7 +880,9 @@
transition: all 150ms ease; transition: all 150ms ease;
} }
.queue-track:hover .track-menu-btn { .queue-track:hover .track-menu-btn,
.history-track:hover .track-menu-btn,
.track-menu-btn.visible {
opacity: 1; opacity: 1;
} }
@@ -950,25 +981,6 @@
flex-shrink: 0; flex-shrink: 0;
} }
.track-menu {
position: absolute;
right: 6px;
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
background: var(--bg-secondary);
border: none;
color: var(--text-muted);
cursor: pointer;
border-radius: 4px;
}
.track-menu:hover {
color: var(--text-primary);
}
/* Empty State */ /* Empty State */
.empty-state { .empty-state {
display: flex; display: flex;
+3 -3
View File
@@ -1630,10 +1630,10 @@
} }
} }
// Remove a track from the queue by index // Remove a track from the upcoming queue by its position in the upcoming list
async function handleRemoveFromQueue(index: number) { async function handleRemoveFromQueue(upcomingIndex: number) {
try { try {
await invoke('remove_from_queue', { index }); await invoke('remove_upcoming_track', { upcomingIndex });
showToast($t('toast.removedFromQueue'), 'info'); showToast($t('toast.removedFromQueue'), 'info');
} catch (err) { } catch (err) {
console.error('Failed to remove from queue:', err); console.error('Failed to remove from queue:', err);