diff --git a/internal/handlers/watchlist.go b/internal/handlers/watchlist.go
index 7e33adf..e329aae 100644
--- a/internal/handlers/watchlist.go
+++ b/internal/handlers/watchlist.go
@@ -101,14 +101,15 @@ func (h *WatchlistHandler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.
return
}
- animeIDStr := r.URL.Path[len("/api/watchlist/"):]
- animeID, err := strconv.ParseInt(animeIDStr, 10, 64)
+ // Parse the path to get anime ID (path is /api/watchlist/{id} possibly with query params)
+ path := r.URL.Path[len("/api/watchlist/"):]
+ animeID, err := strconv.ParseInt(path, 10, 64)
if err != nil {
http.Error(w, "invalid anime ID", http.StatusBadRequest)
return
}
- // Get anime info before deleting
+ // Get anime info before deleting (for dropdown refresh on anime page)
anime, err := h.db.GetAnime(r.Context(), animeID)
if err != nil {
http.Error(w, "anime not found", http.StatusNotFound)
@@ -125,6 +126,14 @@ func (h *WatchlistHandler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.
}
w.Header().Set("HX-Trigger", `{"toast": "removed from watchlist"}`)
+
+ // If called from watchlist page, just return empty (hx-swap="delete" handles removal)
+ if r.URL.Query().Get("from") == "watchlist" {
+ w.WriteHeader(http.StatusOK)
+ return
+ }
+
+ // Otherwise return updated dropdown for anime page
templates.WatchlistDropdown(int(animeID), anime.Title, anime.ImageUrl, "").Render(r.Context(), w)
}
diff --git a/internal/templates/watchlist.templ b/internal/templates/watchlist.templ
index 1c95ceb..c78d86c 100644
--- a/internal/templates/watchlist.templ
+++ b/internal/templates/watchlist.templ
@@ -58,9 +58,9 @@ templ Watchlist(entries []database.GetUserWatchListRow, layout string, currentSt
{ entry.Status }
}
@@ -92,9 +92,9 @@ templ Watchlist(entries []database.GetUserWatchListRow, layout string, currentSt
|
diff --git a/internal/templates/watchlist_templ.go b/internal/templates/watchlist_templ.go
index 90ce5cd..2946103 100644
--- a/internal/templates/watchlist_templ.go
+++ b/internal/templates/watchlist_templ.go
@@ -455,9 +455,9 @@ func Watchlist(entries []database.GetUserWatchListRow, layout string, currentSta
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var33 string
- templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/api/watchlist/%d", entry.AnimeID))))
+ templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/api/watchlist/%d?from=watchlist", entry.AnimeID))))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/watchlist.templ`, Line: 61, Col: 86}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/watchlist.templ`, Line: 61, Col: 101}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
if templ_7745c5c3_Err != nil {
@@ -476,7 +476,7 @@ func Watchlist(entries []database.GetUserWatchListRow, layout string, currentSta
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "\" hx-swap=\"outerHTML\">×")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "\" hx-swap=\"delete\">×")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -587,9 +587,9 @@ func Watchlist(entries []database.GetUserWatchListRow, layout string, currentSta
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var42 string
- templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/api/watchlist/%d", entry.AnimeID))))
+ templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/api/watchlist/%d?from=watchlist", entry.AnimeID))))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/watchlist.templ`, Line: 95, Col: 88}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/watchlist.templ`, Line: 95, Col: 103}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42))
if templ_7745c5c3_Err != nil {
@@ -608,7 +608,7 @@ func Watchlist(entries []database.GetUserWatchListRow, layout string, currentSta
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "\" hx-swap=\"outerHTML\" style=\"background: none; border: none; cursor: pointer;\">remove")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "\" hx-swap=\"delete\" style=\"background: none; border: none; cursor: pointer;\">remove")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}