add now playing to history

This commit is contained in:
2026-02-27 23:49:40 -08:00
parent 9979456719
commit d2d325ba46
2 changed files with 15 additions and 0 deletions

View File

@@ -20,6 +20,13 @@
<th>Title</th> <th>Title</th>
<th>Timestamp</th> <th>Timestamp</th>
</tr> </tr>
{{if .NowPlayingTitle}}
<tr>
<td>{{.NowPlayingArtist}}</td>
<td>{{.NowPlayingTitle}}</td>
<td>Now Playing</td>
</tr>
{{end}}
{{$artists := .Artists}} {{$artists := .Artists}}
{{$times := .Times}} {{$times := .Times}}
{{range $index, $title := .Titles}} {{range $index, $title := .Titles}}

View File

@@ -10,6 +10,7 @@ import (
"time" "time"
"muzi/db" "muzi/db"
"muzi/scrobble"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/jackc/pgtype" "github.com/jackc/pgtype"
@@ -29,6 +30,8 @@ type ProfileData struct {
Title string Title string
LoggedInUsername string LoggedInUsername string
TemplateName string TemplateName string
NowPlayingArtist string
NowPlayingTitle string
} }
// Render a page of the profile in the URL // Render a page of the profile in the URL
@@ -79,6 +82,11 @@ func profilePageHandler() http.HandlerFunc {
return return
} }
if np, ok := scrobble.GetNowPlaying(userId); ok {
profileData.NowPlayingArtist = np.Artist
profileData.NowPlayingTitle = np.SongName
}
rows, err := db.Pool.Query( rows, err := db.Pool.Query(
r.Context(), r.Context(),
"SELECT artist, song_name, timestamp FROM history WHERE user_id = $1 ORDER BY timestamp DESC LIMIT $2 OFFSET $3;", "SELECT artist, song_name, timestamp FROM history WHERE user_id = $1 ORDER BY timestamp DESC LIMIT $2 OFFSET $3;",