feat: implement deletion of continue watching items

This commit is contained in:
2026-05-02 18:09:13 +02:00
committed by Mikkel Elvers
parent b7c041940e
commit 2d9d75d18d
3 changed files with 37 additions and 13 deletions

View File

@@ -82,7 +82,26 @@ func (h *Handler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.Request)
}
func (h *Handler) HandleDeleteContinueWatching(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Not implemented", http.StatusNotImplemented)
user := middleware.GetUser(r.Context())
if user == nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
animeIDStr := r.URL.Path[len("/api/continue-watching/"):]
animeID, err := strconv.ParseInt(animeIDStr, 10, 64)
if err != nil {
http.Error(w, "invalid anime id", http.StatusBadRequest)
return
}
if err := h.service.DeleteContinueWatching(r.Context(), user.ID, animeID); err != nil {
log.Printf("failed to remove from continue watching: %v", err)
http.Error(w, "failed to remove from continue watching", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
func (h *Handler) HandleGetWatchlist(w http.ResponseWriter, r *http.Request) {

View File

@@ -101,6 +101,7 @@ func NewRouter(cfg Config) http.Handler {
mux.HandleFunc("/api/watchlist/card", watchlistHandler.HandleCardWatchlist)
mux.HandleFunc("/api/watchlist", watchlistHandler.HandleUpdateWatchlist)
mux.HandleFunc("/api/watchlist/", watchlistHandler.HandleDeleteWatchlist)
mux.HandleFunc("/api/continue-watching/", watchlistHandler.HandleDeleteContinueWatching)
mux.HandleFunc("/watchlist", watchlistHandler.HandleGetWatchlist)
// Wrap mux with global CSRF origin verification and auth checking

View File

@@ -7,13 +7,15 @@
{{$title := .TitleOriginal}}
{{if .TitleEnglish.Valid}}{{$title = .TitleEnglish.String}}{{end}}
<a href="/anime/{{.AnimeID}}/watch" class="group relative w-70 shrink-0 snap-start cursor-pointer space-y-2 2xl:w-lg">
<div id="continue-watching-{{.AnimeID}}" class="group relative w-70 shrink-0 snap-start space-y-2 2xl:w-lg">
<div class="bg-background/80 relative aspect-video w-full overflow-hidden">
<img src="{{if .ImageUrl}}{{.ImageUrl}}{{else}}https://placehold.co/500x500{{end}}" alt="{{$title}}" class="h-full w-full object-cover" />
<a href="/anime/{{.AnimeID}}/watch" class="block h-full w-full">
<img src="{{if .ImageUrl}}{{.ImageUrl}}{{else}}https://placehold.co/500x500{{end}}" alt="{{$title}}" class="h-full w-full object-cover" />
</a>
<div class="absolute inset-0 z-10 flex flex-col p-3 opacity-0 transition-opacity duration-300 group-hover:opacity-100 bg-black/40">
<div class="flex justify-end">
<button class="bg-black/60 hover:bg-black/80 rounded-full p-1.5 text-white transition-colors focus:outline-none disabled:opacity-50 backdrop-blur-sm" aria-label="Remove from Continue Watching">
<div class="absolute inset-0 z-10 flex flex-col p-3 opacity-0 transition-opacity duration-300 group-hover:opacity-100 bg-black/40 pointer-events-none">
<div class="flex justify-end pointer-events-auto">
<button hx-delete="/api/continue-watching/{{.AnimeID}}" hx-target="#continue-watching-{{.AnimeID}}" hx-swap="outerHTML" class="bg-black/60 hover:bg-black/80 rounded-full p-1.5 text-white transition-colors focus:outline-none disabled:opacity-50 backdrop-blur-sm" aria-label="Remove from Continue Watching">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-5"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
</button>
</div>
@@ -28,14 +30,16 @@
</div>
<div>
<h3 class="text-foreground truncate text-lg font-normal">
{{$title}}
</h3>
<p class="text-foreground-muted mt-0.5 text-base">
{{if .CurrentEpisode.Valid}}Episode {{.CurrentEpisode.Int64}}{{end}}
</p>
<a href="/anime/{{.AnimeID}}/watch" class="block">
<h3 class="text-foreground truncate text-lg font-normal">
{{$title}}
</h3>
<p class="text-foreground-muted mt-0.5 text-base">
{{if .CurrentEpisode.Valid}}Episode {{.CurrentEpisode.Int64}}{{end}}
</p>
</a>
</div>
</a>
</div>
{{end}}
</div>
</section>