From d2d325ba468f0c128b73bfe497acb01528553b44 Mon Sep 17 00:00:00 2001 From: riwiwa Date: Fri, 27 Feb 2026 23:49:40 -0800 Subject: [PATCH] add now playing to history --- templates/profile.gohtml | 7 +++++++ web/profile.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/templates/profile.gohtml b/templates/profile.gohtml index 58bdad2..96f09a5 100644 --- a/templates/profile.gohtml +++ b/templates/profile.gohtml @@ -20,6 +20,13 @@ Title Timestamp + {{if .NowPlayingTitle}} + + {{.NowPlayingArtist}} + {{.NowPlayingTitle}} + Now Playing + + {{end}} {{$artists := .Artists}} {{$times := .Times}} {{range $index, $title := .Titles}} diff --git a/web/profile.go b/web/profile.go index 6d7631c..58e8b33 100644 --- a/web/profile.go +++ b/web/profile.go @@ -10,6 +10,7 @@ import ( "time" "muzi/db" + "muzi/scrobble" "github.com/go-chi/chi/v5" "github.com/jackc/pgtype" @@ -29,6 +30,8 @@ type ProfileData struct { Title string LoggedInUsername string TemplateName string + NowPlayingArtist string + NowPlayingTitle string } // Render a page of the profile in the URL @@ -79,6 +82,11 @@ func profilePageHandler() http.HandlerFunc { return } + if np, ok := scrobble.GetNowPlaying(userId); ok { + profileData.NowPlayingArtist = np.Artist + profileData.NowPlayingTitle = np.SongName + } + rows, err := db.Pool.Query( r.Context(), "SELECT artist, song_name, timestamp FROM history WHERE user_id = $1 ORDER BY timestamp DESC LIMIT $2 OFFSET $3;",