diff --git a/api/playback/handler.go b/api/playback/handler.go index 72c9a1d..1e126db 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -74,6 +74,19 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) { user := middleware.GetUser(r.Context()) + var watchlistIDs []int64 + var watchlistStatus string + if user != nil { + watchlist, _ := h.svc.db.GetUserWatchList(r.Context(), user.ID) + watchlistIDs = make([]int64, len(watchlist)) + for i, entry := range watchlist { + watchlistIDs[i] = entry.AnimeID + if entry.AnimeID == int64(id) { + watchlistStatus = entry.Status + } + } + } + currentEpID := r.URL.Query().Get("ep") if currentEpID == "" { if user != nil { @@ -146,12 +159,14 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) { }) if err := templates.GetRenderer().ExecuteTemplate(r.Context(), w, "watch.gohtml", map[string]any{ - "Anime": anime, - "Episodes": allEpisodes, - "WatchData": watchData, - "User": user, - "CurrentPath": r.URL.Path, - "CurrentEpID": currentEpID, + "Anime": anime, + "Episodes": allEpisodes, + "WatchData": watchData, + "User": user, + "CurrentPath": r.URL.Path, + "CurrentEpID": currentEpID, + "WatchlistIDs": watchlistIDs, + "WatchlistStatus": watchlistStatus, }); err != nil { log.Printf("render error: %v", err) } diff --git a/templates/renderer.go b/templates/renderer.go index c5384cb..0aa6073 100644 --- a/templates/renderer.go +++ b/templates/renderer.go @@ -9,6 +9,7 @@ import ( "log" "path/filepath" "slices" + "strconv" "strings" "sync" ) @@ -91,12 +92,27 @@ func GetRenderer() *Renderer { } return res }, - "min": func(a, b int) int { - if a < b { - return a - } - return b - }, +"min": func(a, b int) int { + if a < b { + return a + } + return b + }, + "int": func(v any) int { + switch n := v.(type) { + case int: + return n + case int64: + return int(n) + case float64: + return int(n) + case string: + i, _ := strconv.Atoi(n) + return i + default: + return 0 + } + }, "percent": func(current, total float64) float64 { if total == 0 { return 0 diff --git a/templates/watch.gohtml b/templates/watch.gohtml index 27747d4..9f0d8d3 100644 --- a/templates/watch.gohtml +++ b/templates/watch.gohtml @@ -1,15 +1,62 @@ {{define "title"}}Watch {{.Anime.Title}} - MyAnimeList{{end}} {{define "content"}} +{{if .WatchlistIDs}}{{end}} {{$anime := .Anime}} {{$episodes := .Episodes}} {{$currentEpID := .CurrentEpID}} {{$totalEpisodes := len $episodes}} -