Refresh the strip and the badge out of band
The "Continue reading" strip and the Updated badge describe the whole library but live outside the #list htmx swaps, so nothing corrected them after a mutation: archiving a series left it sitting in the strip under "Continue reading", with the badge still counting it. A tab switch had the same problem from the other side — the strip was server-gated to All but could not be re-rendered client-side, so /?tab=all reached by htmx and the same URL reloaded produced different DOM. Both regions move into chrome.html and always render, hidden when they have nothing to say, so an out-of-band swap always has an id to target. /ui/list and every mutation append them; the tab the reader is on comes from HX-Current-URL. filter.js keeps only the job the server cannot do — hiding the strip while a filter is active. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+50
-4
@@ -451,8 +451,14 @@ func TestUIDeleteRemovesRow(t *testing.T) {
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("delete status = %d, want 200", rr.Code)
|
||||
}
|
||||
if rr.Body.Len() != 0 {
|
||||
t.Fatalf("delete body = %q, want empty so htmx swaps the card away", rr.Body.String())
|
||||
// The body carries only out-of-band chrome, so htmx has nothing to swap into
|
||||
// the card's place and the row disappears.
|
||||
body := rr.Body.String()
|
||||
if strings.Contains(body, `class="card`) {
|
||||
t.Fatalf("delete body = %q, want no card so htmx swaps it away", body)
|
||||
}
|
||||
if !strings.Contains(body, `id="new-count" hx-swap-oob="true"`) {
|
||||
t.Fatalf("delete body = %q, want the out-of-band badge", body)
|
||||
}
|
||||
if _, ok, _ := store.Get("asura:solo"); ok {
|
||||
t.Fatal("row still present after delete")
|
||||
@@ -635,8 +641,14 @@ func TestRecentStripCarriesUnreadOnlyAndOnlyOnAll(t *testing.T) {
|
||||
if _, err := store.Upsert(reading); err != nil {
|
||||
t.Fatalf("Upsert: %v", err)
|
||||
}
|
||||
if strings.Contains(stripOf(t, srv, cfg, "all"), `class="recent"`) {
|
||||
t.Fatal("strip rendered with no unread chapters anywhere")
|
||||
// The section still ships (an out-of-band swap needs the id to exist) but
|
||||
// carries no cards and is hidden.
|
||||
empty := stripOf(t, srv, cfg, "all")
|
||||
if strings.Contains(empty, "recent-card") {
|
||||
t.Fatal("strip rendered cards with no unread chapters anywhere")
|
||||
}
|
||||
if !strings.Contains(empty, `id="recent" hidden`) {
|
||||
t.Fatalf("strip not hidden with nothing new: %q", empty)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,3 +802,37 @@ func TestAppRendersNewTabs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A mutation has to bring the chrome with it: the strip and the badge live
|
||||
// outside the swapped card, so nothing else would correct them.
|
||||
func TestMutationRefreshesChromeOutOfBand(t *testing.T) {
|
||||
cfg := webConfig()
|
||||
srv, store := newWebTestServer(t, cfg)
|
||||
seed(t, store, Bookmark{
|
||||
Key: "asura:solo", Site: "asura", SeriesID: "solo", Title: "Solo Leveling",
|
||||
Status: statusReading, LastChapterNum: 10, LatestChapter: "Chapter 11",
|
||||
LatestChapterNum: floatPtr(11), UpdatedAt: time.Now().UnixMilli(),
|
||||
})
|
||||
|
||||
before := stripOf(t, srv, cfg, "all")
|
||||
if !strings.Contains(before, "Solo Leveling") || !strings.Contains(before, `id="new-count"`) {
|
||||
t.Fatalf("expected the series in the strip to start with: %q", before)
|
||||
}
|
||||
|
||||
req := uiRequest(t, cfg, http.MethodPost, "/ui/bookmarks/asura:solo/status",
|
||||
url.Values{"status": {statusArchived}})
|
||||
req.Header.Set("HX-Current-URL", "http://localhost/?tab=all")
|
||||
rr := httptest.NewRecorder()
|
||||
srv.ServeHTTP(rr, req)
|
||||
if rr.Code != http.StatusOK {
|
||||
t.Fatalf("status post = %d, want 200", rr.Code)
|
||||
}
|
||||
|
||||
body := rr.Body.String()
|
||||
if !strings.Contains(body, `id="recent" hx-swap-oob="true" hidden`) {
|
||||
t.Fatalf("archiving did not empty the strip out of band: %q", body)
|
||||
}
|
||||
if !strings.Contains(body, `id="new-count" hx-swap-oob="true" hidden`) {
|
||||
t.Fatalf("archiving did not clear the Updated badge out of band: %q", body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user