feat: lazy-load simulcast content via htmx with skeleton

This commit is contained in:
2026-07-06 22:10:24 +02:00
parent 74930976c4
commit 45341ae212
3 changed files with 58 additions and 1 deletions

View File

@@ -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),

View File

@@ -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)