diff --git a/api/anime/handler.go b/api/anime/handler.go index ef94a6d..7a17d48 100644 --- a/api/anime/handler.go +++ b/api/anime/handler.go @@ -12,6 +12,8 @@ import ( "mal/integrations/jikan" "mal/internal/db" "mal/internal/middleware" + animecomponents "mal/web/components/anime" + watchcomponents "mal/web/components/watch" "mal/web/templates" ) @@ -164,7 +166,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) { h.jikanClient.EnqueueAnimeFetchRetry(r.Context(), id, err) if jikan.IsRetryableError(err) { - templates.AnimePending(id).Render(r.Context(), w) + animecomponents.Pending(id).Render(r.Context(), w) return } @@ -220,7 +222,7 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) { writeInlineLoadError(w, "Failed to load relations.") return } - templates.AnimeRelationsList(relations).Render(r.Context(), w) + animecomponents.RelationsList(relations).Render(r.Context(), w) case "recommendations": recs, err := h.jikanClient.GetRecommendations(r.Context(), id, 12) if err != nil { @@ -228,7 +230,7 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) { writeInlineLoadError(w, "Failed to load recommendations.") return } - templates.AnimeRecommendations(recs).Render(r.Context(), w) + animecomponents.Recommendations(recs).Render(r.Context(), w) case "episodes": currentEpisode := r.URL.Query().Get("current") episodes, err := h.getEpisodes(r.Context(), id) @@ -237,7 +239,7 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) { writeInlineLoadError(w, "Failed to load episodes.") return } - templates.EpisodeList(episodes, currentEpisode, id).Render(r.Context(), w) + watchcomponents.EpisodeList(episodes, currentEpisode, id).Render(r.Context(), w) default: renderNotFoundPage(r, w) } @@ -261,7 +263,7 @@ func (h *Handler) HandleAPIEpisodes(w http.ResponseWriter, r *http.Request) { return } - templates.EpisodeList(episodes, currentEpisode, id).Render(r.Context(), w) + watchcomponents.EpisodeList(episodes, currentEpisode, id).Render(r.Context(), w) } func (h *Handler) getEpisodes(ctx context.Context, animeID int) ([]jikan.Episode, error) { diff --git a/api/playback/handler.go b/api/playback/handler.go index eaa3a40..5560160 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -17,6 +17,7 @@ import ( "mal/integrations/jikan" "mal/internal/db" "mal/internal/middleware" + "mal/web/shared" "mal/web/templates" ) @@ -96,8 +97,8 @@ func (h *Handler) HandleWatchPage(w http.ResponseWriter, r *http.Request) { return } - // Convert playback.WatchPageData to templates.WatchPageData - pageData := templates.WatchPageData{ + // Convert playback.WatchPageData to shared.WatchPageData + pageData := shared.WatchPageData{ MalID: data.MalID, Title: data.Title, TitleEnglish: anime.TitleEnglish, @@ -155,17 +156,17 @@ func playbackTitleCandidates(anime jikan.Anime) []string { return out } -func convertModeSources(sources map[string]ModeSource) map[string]templates.ModeSource { - result := make(map[string]templates.ModeSource, len(sources)) +func convertModeSources(sources map[string]ModeSource) map[string]shared.ModeSource { + result := make(map[string]shared.ModeSource, len(sources)) for k, v := range sources { - subtitles := make([]templates.SubtitleItem, len(v.Subtitles)) + subtitles := make([]shared.SubtitleItem, len(v.Subtitles)) for i, s := range v.Subtitles { - subtitles[i] = templates.SubtitleItem{ + subtitles[i] = shared.SubtitleItem{ Lang: s.Lang, Token: s.Token, } } - result[k] = templates.ModeSource{ + result[k] = shared.ModeSource{ Token: v.Token, Subtitles: subtitles, } @@ -173,10 +174,10 @@ func convertModeSources(sources map[string]ModeSource) map[string]templates.Mode return result } -func convertSegments(segments []SkipSegment) []templates.SkipSegment { - result := make([]templates.SkipSegment, len(segments)) +func convertSegments(segments []SkipSegment) []shared.SkipSegment { + result := make([]shared.SkipSegment, len(segments)) for i, s := range segments { - result[i] = templates.SkipSegment{ + result[i] = shared.SkipSegment{ Type: s.Type, Start: s.Start, End: s.End, diff --git a/api/watchlist/handler.go b/api/watchlist/handler.go index 94d68ce..f087734 100644 --- a/api/watchlist/handler.go +++ b/api/watchlist/handler.go @@ -10,6 +10,7 @@ import ( "mal/internal/db" "mal/internal/middleware" + "mal/web/components/watchlist" "mal/web/templates" ) @@ -84,7 +85,7 @@ func (h *Handler) HandleUpdateWatchlist(w http.ResponseWriter, r *http.Request) return } - templates.WatchlistDropdown(int(animeID), animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, status, airing).Render(r.Context(), w) + watchlist.WatchlistDropdown(int(animeID), animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, status, airing).Render(r.Context(), w) } func (h *Handler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.Request) { @@ -128,7 +129,7 @@ func (h *Handler) HandleDeleteWatchlist(w http.ResponseWriter, r *http.Request) airing = anime.Airing.Bool } - templates.WatchlistDropdown(int(animeID), anime.TitleOriginal, title, "", anime.ImageUrl, "", airing).Render(r.Context(), w) + watchlist.WatchlistDropdown(int(animeID), anime.TitleOriginal, title, "", anime.ImageUrl, "", airing).Render(r.Context(), w) } func (h *Handler) HandleGetWatchlist(w http.ResponseWriter, r *http.Request) { diff --git a/web/components/anime/recommendations.templ b/web/components/anime/recommendations.templ index 0b8c670..9cec64a 100644 --- a/web/components/anime/recommendations.templ +++ b/web/components/anime/recommendations.templ @@ -2,14 +2,14 @@ package anime import ( "mal/integrations/jikan" - "mal/web/components" + ui "mal/web/components" ) templ Recommendations(recs []jikan.Anime) { if len(recs) > 0 {
for _, anime := range recs { - @components.AnimeCard(components.AnimeCardProps{ + @ui.AnimeCard(ui.AnimeCardProps{ ID: anime.MalID, Title: anime.DisplayTitle(), ImageURL: anime.ImageURL(), diff --git a/web/components/anime/relations.templ b/web/components/anime/relations.templ index f748b86..3907964 100644 --- a/web/components/anime/relations.templ +++ b/web/components/anime/relations.templ @@ -1,16 +1,15 @@ package anime import ( - "fmt" "mal/integrations/jikan" - "mal/web/components" + ui "mal/web/components" ) templ RelationsList(relations []jikan.RelationEntry) { if len(relations) > 1 {
for _, rel := range relations { - @components.AnimeCard(components.AnimeCardProps{ + @ui.AnimeCard(ui.AnimeCardProps{ ID: rel.Anime.MalID, Title: rel.Anime.DisplayTitle(), ImageURL: rel.Anime.ImageURL(), diff --git a/web/components/watch/video_player.templ b/web/components/watch/video_player.templ index 174d212..ea8bdd3 100644 --- a/web/components/watch/video_player.templ +++ b/web/components/watch/video_player.templ @@ -2,7 +2,6 @@ package watch import ( "fmt" - "mal/web/components" "mal/web/shared" ) @@ -35,7 +34,7 @@ templ VideoPlayer(data shared.WatchPageData) { preload="metadata" crossorigin="anonymous" playsinline - src={ buildStreamURL(data.InitialMode, streamToken) } + src={ shared.BuildStreamURL(data.InitialMode, streamToken) } >
Continue ep { fmt.Sprintf("%d", entry.CurrentEpisode.Int64) } if entry.CurrentTimeSeconds > 0 { - { fmt.Sprintf(" · %s", formatProgressTime(entry.CurrentTimeSeconds)) } + { fmt.Sprintf(" · %s", shared.FormatProgressTime(entry.CurrentTimeSeconds)) } }

} diff --git a/web/templates/continue_watching.templ b/web/templates/continue_watching.templ index 627c21a..63b1a98 100644 --- a/web/templates/continue_watching.templ +++ b/web/templates/continue_watching.templ @@ -2,8 +2,9 @@ package templates import ( "fmt" - "mal/internal/db" - "mal/web/components" + db "mal/internal/db" + ui "mal/web/components" + "mal/web/shared" "mal/web/shared/layout" ) @@ -34,11 +35,11 @@ templ ContinueWatching(entries []db.GetContinueWatchingEntriesRow) { if entry.CurrentEpisode.Valid && entry.CurrentEpisode.Int64 > 0 { Continue ep { fmt.Sprintf("%d", entry.CurrentEpisode.Int64) } } - if entry.CurrentTimeSeconds > 0 { - { formatProgressTime(entry.CurrentTimeSeconds) } - } -
+ if entry.CurrentTimeSeconds > 0 { + { shared.FormatProgressTime(entry.CurrentTimeSeconds) } + }
+
}