diff --git a/internal/features/anime/handler.go b/internal/features/anime/handler.go index 99ba187..f61bd74 100644 --- a/internal/features/anime/handler.go +++ b/internal/features/anime/handler.go @@ -155,7 +155,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) { userID := userIDFromRequest(r) - anime, currentStatus, err := h.svc.GetAnimeDetails(r.Context(), id, userID) + anime, currentStatus, nextEpisode, err := h.svc.GetAnimeDetails(r.Context(), id, userID) if err != nil { if errors.Is(err, ErrAnimePendingFetch) { templates.AnimePending(id).Render(r.Context(), w) @@ -172,7 +172,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) { return } - templates.AnimeDetails(anime, currentStatus).Render(r.Context(), w) + templates.AnimeDetails(anime, currentStatus, nextEpisode).Render(r.Context(), w) } func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) { diff --git a/internal/features/anime/service.go b/internal/features/anime/service.go index 9c84f80..faf6bf6 100644 --- a/internal/features/anime/service.go +++ b/internal/features/anime/service.go @@ -54,22 +54,23 @@ func (s *Service) GetUpcomingAnime(ctx context.Context, page int) (jikan.TopAnim return s.jikanClient.GetSeasonsUpcoming(ctx, page) } -func (s *Service) GetAnimeDetails(ctx context.Context, id int, userID string) (jikan.Anime, string, error) { +func (s *Service) GetAnimeDetails(ctx context.Context, id int, userID string) (jikan.Anime, string, int, error) { anime, err := s.jikanClient.GetAnimeByID(ctx, id) if err != nil { if jikan.IsNotFoundError(err) { - return jikan.Anime{}, "", err + return jikan.Anime{}, "", 1, err } s.jikanClient.EnqueueAnimeFetchRetry(ctx, id, err) if jikan.IsRetryableError(err) { - return jikan.Anime{}, "", ErrAnimePendingFetch + return jikan.Anime{}, "", 1, ErrAnimePendingFetch } - return jikan.Anime{}, "", fmt.Errorf("failed to fetch anime details: %w", err) + return jikan.Anime{}, "", 1, fmt.Errorf("failed to fetch anime details: %w", err) } currentStatus := "" + nextEpisode := 1 if userID != "" { entry, err := s.db.GetWatchListEntry(ctx, database.GetWatchListEntryParams{ UserID: userID, @@ -77,10 +78,16 @@ func (s *Service) GetAnimeDetails(ctx context.Context, id int, userID string) (j }) if err == nil { currentStatus = entry.Status + if entry.CurrentEpisode.Valid { + value := int(entry.CurrentEpisode.Int64) + if value > 0 { + nextEpisode = value + } + } } } - return anime, currentStatus, nil + return anime, currentStatus, nextEpisode, nil } func (s *Service) GetRelations(ctx context.Context, id int) ([]jikan.RelationEntry, error) { diff --git a/internal/templates/anime.templ b/internal/templates/anime.templ index 5b8dd14..4bc84bf 100644 --- a/internal/templates/anime.templ +++ b/internal/templates/anime.templ @@ -5,7 +5,7 @@ import "mal/internal/shared/ui" import "fmt" import "strings" -templ AnimeDetails(anime jikan.Anime, currentStatus string) { +templ AnimeDetails(anime jikan.Anime, currentStatus string, nextEpisode int) { @Layout("mal - " + anime.DisplayTitle(), true) {
@@ -40,7 +40,7 @@ templ AnimeDetails(anime jikan.Anime, currentStatus string) {
@WatchlistDropdown(anime.MalID, anime.Title, anime.TitleEnglish, anime.TitleJapanese, anime.ImageURL(), currentStatus, anime.Airing) Watch
@@ -167,6 +167,14 @@ templ AnimeDetails(anime jikan.Anime, currentStatus string) { } } +func watchTargetEpisode(currentStatus string, nextEpisode int) int { + if currentStatus == "watching" && nextEpisode > 0 { + return nextEpisode + } + + return 1 +} + templ AnimePending(id int) { @Layout("mal - anime pending", true) {
diff --git a/internal/templates/watchlist.templ b/internal/templates/watchlist.templ index e33db35..ec39b49 100644 --- a/internal/templates/watchlist.templ +++ b/internal/templates/watchlist.templ @@ -4,6 +4,7 @@ import ( "fmt" "mal/internal/database" "mal/internal/shared/ui" + "math" ) templ Watchlist(entries []database.GetUserWatchListRow, layout string, currentStatus string, sortBy string, sortOrder string) { @@ -50,11 +51,15 @@ templ Watchlist(entries []database.GetUserWatchListRow, layout string, currentSt
for _, entry := range entries {
- @ui.AnimeCard(ui.AnimeCardProps{ - ID: int(entry.AnimeID), - Title: entry.DisplayTitle(), - ImageURL: entry.ImageUrl, - }) + +
+ { +
+
+ { entry.DisplayTitle() } +
+ @ifHasProgress(entry) +