From ace5205724694cf6848ca222b9697afaf1d7b075 Mon Sep 17 00:00:00 2001 From: riwiwa Date: Tue, 3 Mar 2026 01:31:52 -0800 Subject: [PATCH] improve song title editing --- db/entities.go | 6 ++++++ static/menu.js | 17 ++++++----------- web/entity.go | 9 ++++++++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/db/entities.go b/db/entities.go index 0d271e8..26bdf2a 100644 --- a/db/entities.go +++ b/db/entities.go @@ -451,6 +451,12 @@ func UpdateSong(id int, title string, durationMs int, spotifyId, musicbrainzId s _, err := Pool.Exec(context.Background(), `UPDATE songs SET title = $1, duration_ms = $2, spotify_id = $3, musicbrainz_id = $4 WHERE id = $5`, title, durationMs, spotifyId, musicbrainzId, id) + if err != nil { + return err + } + _, err = Pool.Exec(context.Background(), + `UPDATE history SET song_name = $1 WHERE song_id = $2`, + title, id) return err } diff --git a/static/menu.js b/static/menu.js index dca6ba5..06b4bd9 100644 --- a/static/menu.js +++ b/static/menu.js @@ -169,18 +169,13 @@ document.addEventListener('DOMContentLoaded', function() { xhr.onreadystatechange = function() { if (xhr.readyState === 4) { if (xhr.status === 200) { - // Update bio display if it exists - var bioDisplay = document.getElementById('bio-display'); - if (bioDisplay && data.bio !== undefined) { - bioDisplay.textContent = data.bio; + var response = JSON.parse(xhr.responseText); + if (response.success && entityType === 'song' && response.artist && response.title && response.username) { + var newUrl = '/profile/' + response.username + '/song/' + encodeURIComponent(response.artist) + '/' + encodeURIComponent(response.title); + window.location.href = newUrl; + } else { + location.reload(); } - // Update info display if it exists - var infoDisplay = document.getElementById('info-display'); - if (infoDisplay && data.title !== undefined) { - // Will be reloaded anyway, but close modal first - } - closeEditModal(); - location.reload(); } else { alert('Error saving: ' + xhr.responseText); } diff --git a/web/entity.go b/web/entity.go index 8798665..b11e6d7 100644 --- a/web/entity.go +++ b/web/entity.go @@ -735,8 +735,15 @@ func songBatchEditHandler() http.HandlerFunc { return } + artist, _ := db.GetArtistById(song.ArtistId) + w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]string{"success": "true"}) + json.NewEncoder(w).Encode(map[string]string{ + "success": "true", + "artist": artist.Name, + "title": title, + "username": username, + }) } }