diff --git a/internal/anime/catalog_handler.go b/internal/anime/catalog_handler.go index 18c65268..b99695c2 100644 --- a/internal/anime/catalog_handler.go +++ b/internal/anime/catalog_handler.go @@ -4,6 +4,7 @@ import ( "mal/internal/observability" "mal/internal/server" "net/http" + "net/url" "strings" "time" @@ -11,6 +12,14 @@ import ( ) func (h *AnimeHandler) HandleSimulcast(c *gin.Context) { + c.HTML(http.StatusOK, "simulcast.gohtml", gin.H{ + "CurrentPath": "/simulcast", + "User": server.CurrentUser(c), + "SimulcastURL": simulcastURL(c), + }) +} + +func (h *AnimeHandler) HandleSimulcastContent(c *gin.Context) { now := time.Now() current := calendarSeason(now.Year(), int(now.Month())) latest := h.discoverySvc.LatestAvailableSeason(c.Request.Context(), current) @@ -24,6 +33,7 @@ func (h *AnimeHandler) HandleSimulcast(c *gin.Context) { watchlistMap := h.watchlistMapForAnimes(c.Request.Context(), server.CurrentUserID(c), data.Animes) previous, next := seasonNavigation(selected, 2018, latest) c.HTML(http.StatusOK, "simulcast.gohtml", gin.H{ + "_fragment": "simulcast_content", "CurrentPath": "/simulcast", "User": server.CurrentUser(c), "Animes": data.Animes, @@ -37,6 +47,21 @@ func (h *AnimeHandler) HandleSimulcast(c *gin.Context) { }) } +func simulcastURL(c *gin.Context) string { + query := url.Values{} + if season := c.Query("season"); season != "" { + query.Set("season", season) + } + if year := c.Query("year"); year != "" { + query.Set("year", year) + } + + if encoded := query.Encode(); encoded != "" { + return "/api/simulcast?" + encoded + } + return "/api/simulcast" +} + func (h *AnimeHandler) HandleSearch(c *gin.Context) { c.HTML(http.StatusOK, "search.gohtml", gin.H{ "User": server.CurrentUser(c), diff --git a/internal/anime/handler.go b/internal/anime/handler.go index 1c9ad2ae..48781beb 100644 --- a/internal/anime/handler.go +++ b/internal/anime/handler.go @@ -62,6 +62,7 @@ func (h *AnimeHandler) Register(r *gin.Engine) { r.GET("/top-picks", h.HandleTopPicks) r.GET("/browse", h.HandleBrowse) r.GET("/simulcast", h.HandleSimulcast) + r.GET("/api/simulcast", h.HandleSimulcastContent) r.GET("/anime/:id", h.HandleAnimeDetails) r.GET("/anime/:id/reviews", h.HandleAnimeReviews) r.GET("/api/watch-order", h.HandleHTMLWatchOrder) diff --git a/templates/simulcast.gohtml b/templates/simulcast.gohtml index 70e1a5d3..ecc9afaf 100644 --- a/templates/simulcast.gohtml +++ b/templates/simulcast.gohtml @@ -1,6 +1,18 @@ {{define "title"}}Simulcast{{end}} {{define "content"}} -