fix: play count display and live update after playback

- Column accessor shows '0' instead of empty string for unplayed tracks
- recordPlay emits TrackMetadataChanged event after updating DB
- Frontend library store invalidates on that event, refreshing play counts
This commit is contained in:
2026-03-22 09:42:18 -04:00
parent e1bfe12903
commit 7cde7cc7b8
2 changed files with 15 additions and 2 deletions
+14 -1
View File
@@ -1,6 +1,12 @@
package queue package queue
import "time" import (
"time"
"github.com/wailsapp/wails/v2/pkg/runtime"
"yellowjacket/backend/events"
)
// recordPlay inserts a play_history row and updates the denormalized // recordPlay inserts a play_history row and updates the denormalized
// play_count / last_played columns on audio_files. Called from // play_count / last_played columns on audio_files. Called from
@@ -54,4 +60,11 @@ func (q *Queue) recordPlay(audioFileID int64) {
"Play recorded", "Play recorded",
"audioFileId", audioFileID, "audioFileId", audioFileID,
) )
// Notify frontend so the track list refreshes play count.
if q.ctx != nil {
runtime.EventsEmit(
q.ctx, events.TrackMetadataChanged,
)
}
} }
@@ -190,7 +190,7 @@ export const COLUMN_DEFS: Record<string, ColumnDef> = {
id: 'playCount', id: 'playCount',
label: 'Play Count', label: 'Play Count',
accessor: (t) => accessor: (t) =>
t.PlayCount ? String(t.PlayCount) : '', String(t.PlayCount ?? 0),
defaultWidth: '80px', defaultWidth: '80px',
align: 'right', align: 'right',
comparator: (a, b) => comparator: (a, b) =>