fix(ui): keep Spotify search feedback visible

This commit is contained in:
Bjarne Øverli
2026-08-20 18:42:52 +02:00
parent d11017c121
commit 86d836cffc
2 changed files with 57 additions and 7 deletions
+19 -7
View File
@@ -93,6 +93,9 @@ func (m Model) renderSpotSearchResults(budget int) string {
break
}
if row.Index < 0 {
if budget == 1 {
continue
}
lines = append(lines, dimStyle.Render(labeledSeparator("", row.Section)))
continue
}
@@ -512,16 +515,21 @@ func (m Model) spotSearchHelpLine() string {
func (m Model) renderSpotSearchBody() string {
budget := m.effectivePlaylistVisible()
showError := m.spotSearch.err != "" && m.spotSearch.screen != spotSearchPlaylist
bodyBudget := budget
if showError {
bodyBudget = max(0, bodyBudget-1)
}
var body string
switch m.spotSearch.screen {
case spotSearchResults:
switch {
case m.spotSearch.albumLoading:
body = bodyLines([]string{loadingLine("Loading album…")}, budget)
body = bodyLines([]string{loadingLine("Loading album…")}, bodyBudget)
case len(m.spotSearch.results) == 0:
body = bodyMessage("No results", budget)
body = bodyMessage("No results", bodyBudget)
default:
body = m.renderSpotSearchResults(budget)
body = m.renderSpotSearchResults(bodyBudget)
}
case spotSearchPlaylist:
if m.spotSearch.loading {
@@ -542,7 +550,7 @@ func (m Model) renderSpotSearchBody() string {
list := windowList(items, m.spotSearch.cursor, m.spotSearch.scroll, max(0, budget-1))
body = strings.Join([]string{head, list}, "\n")
case spotSearchNewName:
body = bodyMessage("Enter a name for the new playlist above.", budget)
body = bodyMessage("Enter a name for the new playlist above.", bodyBudget)
default:
var lines []string
if m.spotSearch.loading {
@@ -550,10 +558,14 @@ func (m Model) renderSpotSearchBody() string {
} else {
lines = append(lines, dimStyle.Render(" Type a query and press Enter to search."))
}
body = bodyLines(lines, budget)
body = bodyLines(lines, bodyBudget)
}
if m.spotSearch.err != "" && m.spotSearch.screen != spotSearchPlaylist {
return strings.Join([]string{body, errorStyle.Render(" " + m.spotSearch.err)}, "\n")
if showError {
errLine := errorStyle.Render(" " + m.spotSearch.err)
if body == "" {
return errLine
}
return strings.Join([]string{body, errLine}, "\n")
}
return body
}
+38
View File
@@ -1,6 +1,7 @@
package model
import (
"strings"
"testing"
"github.com/bjarneo/cliamp/playlist"
@@ -16,6 +17,43 @@ func albumResult(name string) playlist.Track {
}
}
func TestSpotSearchResultVisibleWithOneBodyRow(t *testing.T) {
m := newLayoutTestModel(40, 10)
m.spotSearch = spotSearchState{
visible: true,
screen: spotSearchResults,
results: []playlist.Track{albumResult("Selected Album")},
}
m.recomputeLayout()
if got := m.effectivePlaylistVisible(); got != 1 {
t.Fatalf("body rows = %d, want 1", got)
}
body := stripAnsi(m.renderSpotSearchBody())
if !strings.Contains(body, "Selected Album") {
t.Fatalf("body = %q, want selected result", body)
}
}
func TestSpotSearchErrorFitsBodyBudget(t *testing.T) {
m := newLayoutTestModel(80, 24)
m.spotSearch = spotSearchState{
visible: true,
screen: spotSearchResults,
results: []playlist.Track{albumResult("Album")},
err: "Album cannot be added to a playlist",
}
m.recomputeLayout()
body := stripAnsi(m.renderSpotSearchBody())
if !strings.Contains(body, m.spotSearch.err) {
t.Fatalf("body = %q, want visible error", body)
}
if got, want := len(strings.Split(body, "\n")), m.effectivePlaylistVisible(); got != want {
t.Fatalf("body rows = %d, want %d", got, want)
}
}
func trackResult(name string) playlist.Track {
return playlist.Track{Title: name, Artist: "NOFX"}
}