Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e65c3b413 |
+10
-12
@@ -211,19 +211,17 @@ func (a *App) handleList(w http.ResponseWriter, r *http.Request) {
|
||||
rows := f.apply(allRows)
|
||||
buckets := bucketRows(rows, a.recencyCutoff())
|
||||
|
||||
// hasConnected drives the empty state: a fresh account with a connection but
|
||||
// no discovery pass yet has zero rows, and we want it to read "connected,
|
||||
// summaries land gradually" rather than "nothing here". Only needed when the
|
||||
// list is empty.
|
||||
hasConnected := false
|
||||
if buckets.empty() {
|
||||
conns, err := a.Store.ConnectionsForUser(r.Context(), userID)
|
||||
if err != nil {
|
||||
a.serverError(w, r, "connections for user", err)
|
||||
return
|
||||
}
|
||||
hasConnected = len(conns) > 0
|
||||
// hasConnected drives both the paste box (shown to ANY connected user, #2) and
|
||||
// the empty-state copy (a fresh account with a connection but no discovery pass
|
||||
// yet reads "connected, summaries land gradually" rather than "nothing here").
|
||||
// Computed every render — not only when empty — so a user with videos still
|
||||
// gets the paste box.
|
||||
conns, err := a.Store.ConnectionsForUser(r.Context(), userID)
|
||||
if err != nil {
|
||||
a.serverError(w, r, "connections for user", err)
|
||||
return
|
||||
}
|
||||
hasConnected := len(conns) > 0
|
||||
|
||||
if isHTMX(r) {
|
||||
a.render(w, r, summaryList(buckets, hasConnected))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -111,3 +112,23 @@ func TestPasteDedupNoDuplicate(t *testing.T) {
|
||||
userID).Scan(&count))
|
||||
require.Equal(t, 1, count, "pasting the same video twice must not duplicate the row")
|
||||
}
|
||||
|
||||
func TestListShowsPasteFormForConnectedUserWithVideos(t *testing.T) {
|
||||
app := newApp(t)
|
||||
resetDB(t, rawPool(t))
|
||||
app.Fetcher = &fakeFetcher{title: "x"}
|
||||
p := rawPool(t)
|
||||
|
||||
// Connected user with a non-empty feed (the case the bug missed: hasConnected
|
||||
// was only computed for an empty feed).
|
||||
_, err := p.Exec(context.Background(),
|
||||
`INSERT INTO video_connections (user_id, provider, token_ref, status)
|
||||
VALUES ($1, 'youtube', 'youtube/x/refresh_token', 'active')`, userID)
|
||||
require.NoError(t, err)
|
||||
seedVideo(t, p, "11111111-1111-1111-1111-111111111111", "A talk", "https://youtu.be/aaaaaaaaaaa", time.Now())
|
||||
|
||||
rec := do(t, app, httptest.NewRequest(http.MethodGet, "/", nil))
|
||||
require.Equal(t, http.StatusOK, rec.Code)
|
||||
require.Contains(t, body(t, rec), `action="/paste"`,
|
||||
"a connected user must see the paste box even when the feed has videos")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user