diff --git a/.opencode/plans/clear-queue-button.md b/.opencode/plans/clear-queue-button.md new file mode 100644 index 0000000..e7aa99d --- /dev/null +++ b/.opencode/plans/clear-queue-button.md @@ -0,0 +1,175 @@ +# Plan: Clear Queue Button + +## Goal +Add a "Clear Queue" button (trash icon) next to the existing "Add queue to playlist" button in the queue panel header. The button clears all tracks from the queue, stops playback, and resets queue state. + +## Architecture Overview +The backend already has a `Queue.Clear()` method (`backend/queue/queue.go:1540`) that handles everything — clearing tracks, stopping playback, resetting state, persisting, and emitting `QueueChanged`. The only missing piece is wiring it to the frontend via the event system and adding the UI button. + +## Changes Required (5 files) + +### 1. `backend/events/events.go` — Add new event constant +Add `RequestClearQueue` to the queue events const block. + +```go + RequestMoveQueueTracks = "RequestMoveQueueTracks" + RequestClearQueue = "RequestClearQueue" +) +``` + +### 2. `frontend/src/events.ts` — Add matching TypeScript event constant +Add `RequestClearQueue` to the queue events section. + +```typescript + RequestMoveQueueTracks: "RequestMoveQueueTracks", + RequestClearQueue: "RequestClearQueue", +``` + +### 3. `backend/queue/queue.go` — Wire event handler in `registerEventHandlers()` +Add a new `runtime.EventsOn` call at the end of `registerEventHandlers()` (after the existing `RequestMoveQueueTracks` handler around line 289): + +```go + runtime.EventsOn( + q.ctx, + events.RequestClearQueue, + func(_ ...any) { + q.logger.Info("Received RequestClearQueue") + q.Clear() + }, + ) +``` + +### 4. `frontend/src/store/queue-store.ts` — Add `clearQueue()` action +Add after the existing `moveTracksInQueue()` method (around line 250): + +```typescript + clearQueue(): void { + EventsEmit(Events.RequestClearQueue); + } +``` + +### 5. `frontend/src/components/queue-panel/queue-panel.ts` — Add UI button, styles, and handler + +#### 5a. Add handler method +Add a new handler method near the other handlers (around line 518, near `handleAddToPlaylist`): + +```typescript + private handleClearQueue = () => { + queueStore.clearQueue(); + }; +``` + +Note: Import `queueStore` — check if it's already imported (it likely is via the controller). + +#### 5b. Add CSS styles for shared header button class +Add a `.header-actions` container style and refactor the button styles. Replace the existing `.add-to-playlist-button` styles: + +**Replace:** +```css + .add-to-playlist-button { + background: none; + border: none; + color: inherit; + cursor: pointer; + padding: 4px; + display: flex; + align-items: center; + } + + .add-to-playlist-button:hover { + color: #ffd43b; + } + + .add-to-playlist-button:disabled { + color: #555; + cursor: not-allowed; + } +``` + +**With:** +```css + .header-actions { + display: flex; + align-items: center; + gap: 4px; + } + + .header-action-button { + background: none; + border: none; + color: inherit; + cursor: pointer; + padding: 4px; + display: flex; + align-items: center; + } + + .header-action-button:hover { + color: #ffd43b; + } + + .header-action-button:disabled { + color: #555; + cursor: not-allowed; + } +``` + +#### 5c. Update the header HTML +Replace the header section (around lines 1183-1193): + +**Replace:** +```html +
+

Queue

+ +
+``` + +**With:** +```html +
+

Queue

+
+ + +
+
+``` + +**Important:** The `add-to-playlist-button` class must remain on the playlist button because it's referenced by `@query` selectors and the `closePickerHandler` (lines 84-85, 527). The new class `header-action-button` provides the shared visual style. + +#### 5d. Update CSS selector references +Check that the `.add-to-playlist-button` query selector references still work. Since we're keeping `add-to-playlist-button` as a class on the playlist button, the existing `@query('.add-to-playlist-button')` and `querySelector('.add-to-playlist-button')` calls will continue to work unchanged. + +### 6. Import check +Verify that `queueStore` is accessible in `queue-panel.ts`. The component uses a `QueueController` which wraps the store, but the `clearQueue()` call needs to go through the store directly. Check if `queueStore` is already imported; if not, add: + +```typescript +import { queueStore } from '@store/queue-store'; +``` + +## Testing +- Run `make lint` to verify Go code passes linting +- Run `cd frontend && pnpm exec tsc --noEmit` to verify TypeScript compiles +- Manual testing: click the trash button when queue has tracks → queue should clear, playback should stop, button should become disabled diff --git a/backend/events/events.go b/backend/events/events.go index e35fe19..12fc7e4 100644 --- a/backend/events/events.go +++ b/backend/events/events.go @@ -49,6 +49,7 @@ const ( RequestRemoveTracksFromQueue = "RequestRemoveTracksFromQueue" RequestInsertTracksAtIndex = "RequestInsertTracksAtIndex" RequestMoveQueueTracks = "RequestMoveQueueTracks" + RequestClearQueue = "RequestClearQueue" ) // Config events. diff --git a/backend/queue/queue.go b/backend/queue/queue.go index 6dee597..1754947 100644 --- a/backend/queue/queue.go +++ b/backend/queue/queue.go @@ -294,6 +294,15 @@ func (q *Queue) registerEventHandlers() { q.handleMoveQueueTracks(data...) }, ) + + runtime.EventsOn( + q.ctx, + events.RequestClearQueue, + func(_ ...any) { + q.logger.Info("Received RequestClearQueue") + q.Clear() + }, + ) } // handleSetQueue processes the RequestSetQueue event payload. diff --git a/frontend/src/components/cover-grid/album-dropdown.ts b/frontend/src/components/cover-grid/album-dropdown.ts index b49093f..a768535 100644 --- a/frontend/src/components/cover-grid/album-dropdown.ts +++ b/frontend/src/components/cover-grid/album-dropdown.ts @@ -53,17 +53,35 @@ export class AlbumDropdown extends LitElement { @property({ type: Number }) containerWidth = 800; + /** Width of the album row in pixels (cards + gaps, no outer padding). */ + @property({ type: Number }) + gridRowWidth = 800; + + /** Horizontal offset of the carat from the dropdown's left edge. */ + @property({ type: Number }) + caratOffset = 0; + static override styles = css` :host { display: block; } .album-dropdown { - background-color: #212529; - border: 2px solid #ffd43b; - border-radius: 4px; + background-color: #343a40; + border-radius: 0 0 4px 4px; padding: 12px 16px; box-sizing: border-box; + position: relative; + } + + .carat { + position: absolute; + top: -8px; + width: 0; + height: 0; + border-left: 9px solid transparent; + border-right: 9px solid transparent; + border-bottom: 8px solid #343a40; } .dropdown-tracks { @@ -366,7 +384,14 @@ export class AlbumDropdown extends LitElement { override render() { return html` -
+
+
`} +
+ ${selected + ? html` + ✓ + ` + : nothing} +
{ + this.queue.clearQueue(); + }; + private async handleAddToPlaylist() { if (this.queue.tracks.length === 0) return; @@ -1182,14 +1192,28 @@ export class QueuePanel >

Queue

- +
+ + +