311 lines
13 KiB
Plaintext
311 lines
13 KiB
Plaintext
package templates
|
|
|
|
import "mal/internal/jikan"
|
|
import "mal/internal/shared/ui"
|
|
import "fmt"
|
|
import "strings"
|
|
|
|
templ AnimeDetails(anime jikan.Anime, currentStatus string) {
|
|
@Layout("mal - " + anime.DisplayTitle(), true) {
|
|
<div class="grid grid-cols-[minmax(0,1fr)_300px] items-start gap-5 max-[1040px]:grid-cols-[minmax(0,1fr)]">
|
|
<div class="grid min-w-0 gap-8">
|
|
<div class="grid grid-cols-[220px_minmax(0,1fr)] gap-5 max-[860px]:grid-cols-[minmax(0,1fr)]">
|
|
<div class="w-[220px] max-[860px]:w-[min(230px,58vw)]">
|
|
if anime.ImageURL() != "" {
|
|
<img class="w-full" src={ anime.ImageURL() } alt={ anime.DisplayTitle() }/>
|
|
} else {
|
|
<div class="flex aspect-[2/3] max-h-[var(--poster-max-height)] w-full items-end justify-center overflow-hidden text-[0] text-transparent">No image</div>
|
|
}
|
|
</div>
|
|
<div>
|
|
<h1>{ anime.DisplayTitle() }</h1>
|
|
if anime.TitleJapanese != "" {
|
|
<p class="my-2 mb-3 text-[0.9rem] text-[var(--text-muted)]">{ anime.TitleJapanese }</p>
|
|
}
|
|
<div class="flex flex-wrap gap-2">
|
|
if anime.ShortRating() != "" {
|
|
<span class="text-[0.67rem] text-[var(--text-faint)]">{ anime.ShortRating() }</span>
|
|
}
|
|
if anime.Type != "" {
|
|
<span class="text-[0.67rem] text-[var(--text-faint)]">{ anime.Type }</span>
|
|
}
|
|
if anime.Episodes > 0 {
|
|
<span class="text-[0.67rem] text-[var(--text-faint)]">{ fmt.Sprintf("%d ep", anime.Episodes) }</span>
|
|
}
|
|
if anime.ShortDuration() != "" {
|
|
<span class="text-[0.67rem] text-[var(--text-faint)]">{ anime.ShortDuration() }</span>
|
|
}
|
|
</div>
|
|
<div class="mt-3">
|
|
@WatchlistDropdown(anime.MalID, anime.Title, anime.TitleEnglish, anime.TitleJapanese, anime.ImageURL(), currentStatus, anime.Airing)
|
|
</div>
|
|
<section class="mt-4 max-w-[100ch]">
|
|
if anime.Synopsis != "" {
|
|
<p>{ anime.Synopsis }</p>
|
|
} else {
|
|
<p class="text-[var(--text-faint)]">No synopsis available.</p>
|
|
}
|
|
</section>
|
|
</div>
|
|
</div>
|
|
<section>
|
|
<h3>Related</h3>
|
|
<div hx-get={ string(templ.URL(fmt.Sprintf("/api/anime/%d/relations", anime.MalID))) } hx-trigger="load">
|
|
@ui.LoadingIndicator("Loading relations")
|
|
</div>
|
|
</section>
|
|
<section>
|
|
<h3>Recommendations</h3>
|
|
<div hx-get={ string(templ.URL(fmt.Sprintf("/api/anime/%d/recommendations", anime.MalID))) } hx-trigger="load">
|
|
@ui.LoadingIndicator("Loading recommendations")
|
|
</div>
|
|
</section>
|
|
</div>
|
|
<aside class="sticky top-[74px] grid gap-4 bg-[var(--panel)] p-3 max-[1040px]:static">
|
|
<div class="grid gap-3">
|
|
<h3 class="mb-2 text-[0.78rem] text-[var(--text-faint)]">Details</h3>
|
|
if anime.Aired.String != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Aired</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ anime.Aired.String }</span>
|
|
</div>
|
|
}
|
|
if anime.Premiered() != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Premiered</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ anime.Premiered() }</span>
|
|
</div>
|
|
}
|
|
if anime.Status != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Status</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ anime.Status }</span>
|
|
</div>
|
|
}
|
|
if anime.Duration != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Duration</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ anime.Duration }</span>
|
|
</div>
|
|
}
|
|
if len(anime.Genres) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Genres</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ joinNames(anime.Genres) }</span>
|
|
</div>
|
|
}
|
|
</div>
|
|
if hasExtraSidebarDetails(anime) {
|
|
<details class="grid gap-3">
|
|
<summary class="cursor-pointer text-[0.82rem] text-[var(--text-muted)]">More metadata</summary>
|
|
if anime.TitleJapanese != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Japanese</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ anime.TitleJapanese }</span>
|
|
</div>
|
|
}
|
|
if len(anime.TitleSynonyms) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Synonyms</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ strings.Join(anime.TitleSynonyms, ", ") }</span>
|
|
</div>
|
|
}
|
|
if len(anime.Studios) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Studios</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ joinNames(anime.Studios) }</span>
|
|
</div>
|
|
}
|
|
if len(anime.Producers) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Producers</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ joinNames(anime.Producers) }</span>
|
|
</div>
|
|
}
|
|
if anime.Source != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Source</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ anime.Source }</span>
|
|
</div>
|
|
}
|
|
if len(anime.Demographics) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Demographics</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ joinNames(anime.Demographics) }</span>
|
|
</div>
|
|
}
|
|
if len(anime.Themes) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Themes</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ joinNames(anime.Themes) }</span>
|
|
</div>
|
|
}
|
|
if anime.Broadcast.String != "" {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Broadcast</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]" data-jst-text={ anime.Broadcast.String }>{ anime.Broadcast.String }</span>
|
|
</div>
|
|
}
|
|
if len(anime.Streaming) > 0 {
|
|
<div class="mt-1 grid gap-1">
|
|
<span class="mt-[2px] text-[0.84rem] text-[var(--text-faint)]">Streaming</span>
|
|
<span class="text-[0.84rem] text-[var(--text-muted)]">{ joinStreamingNames(anime) }</span>
|
|
</div>
|
|
}
|
|
</details>
|
|
}
|
|
</aside>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
templ AnimePending(id int) {
|
|
@Layout("mal - anime pending", true) {
|
|
<div class="grid grid-cols-[minmax(0,1fr)_300px] items-start gap-5 max-[1040px]:grid-cols-[minmax(0,1fr)]">
|
|
<div class="grid min-w-0 gap-8">
|
|
<section>
|
|
<h1>Anime data is being fetched</h1>
|
|
<p class="text-[0.9rem] text-[var(--text-muted)]">We could not load this anime right now. A background worker is retrying data fetch for anime #{ fmt.Sprintf("%d", id) }.</p>
|
|
<p class="text-[0.9rem] text-[var(--text-muted)]">Refresh this page in a few seconds.</p>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
setTimeout(function() {
|
|
window.location.reload()
|
|
}, 10000)
|
|
</script>
|
|
}
|
|
}
|
|
|
|
func joinNames(entities []jikan.NamedEntity) string {
|
|
names := make([]string, len(entities))
|
|
for i, e := range entities {
|
|
names[i] = e.Name
|
|
}
|
|
return strings.Join(names, ", ")
|
|
}
|
|
|
|
func joinStreamingNames(anime jikan.Anime) string {
|
|
names := make([]string, len(anime.Streaming))
|
|
for i, s := range anime.Streaming {
|
|
names[i] = s.Name
|
|
}
|
|
return strings.Join(names, ", ")
|
|
}
|
|
|
|
templ WatchlistDropdown(animeID int, animeTitle string, animeTitleEnglish string, animeTitleJapanese string, animeImage string, currentStatus string, airing bool) {
|
|
<div class="relative inline-block" id="watchlist-dropdown">
|
|
<button class="inline-flex h-8 cursor-pointer items-center gap-2 bg-[var(--panel-soft)] px-2 text-[0.8rem] text-[var(--text)]" onclick="toggleDropdown()" data-dropdown-trigger>
|
|
if currentStatus != "" {
|
|
{ formatStatus(currentStatus) }
|
|
} else {
|
|
Add to watchlist
|
|
}
|
|
<span class="text-[0.64rem]">▾</span>
|
|
</button>
|
|
<div class="invisible absolute left-0 top-[calc(100%+2px)] z-[110] min-w-[210px] bg-[var(--panel)] opacity-0 transition-opacity duration-150" data-dropdown-menu data-dropdown-open-classes="visible opacity-100" data-dropdown-closed-classes="invisible opacity-0">
|
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "watching", currentStatus, airing)
|
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "completed", currentStatus, airing)
|
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "on_hold", currentStatus, airing)
|
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "dropped", currentStatus, airing)
|
|
@dropdownStatusOption(animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, "plan_to_watch", currentStatus, airing)
|
|
if currentStatus != "" {
|
|
<button
|
|
class="flex w-full cursor-pointer items-center justify-between bg-transparent px-[0.62rem] py-2 text-left text-[0.78rem] text-[var(--text-muted)] hover:bg-[var(--panel-soft)] hover:text-[var(--danger)]"
|
|
hx-delete={ string(templ.URL(fmt.Sprintf("/api/watchlist/%d", animeID))) }
|
|
hx-target="#watchlist-dropdown"
|
|
hx-swap="outerHTML swap:150ms"
|
|
>Remove from list</button>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
templ dropdownStatusOption(animeID int, animeTitle string, animeTitleEnglish string, animeTitleJapanese string, animeImage string, status string, currentStatus string, airing bool) {
|
|
<button
|
|
class={
|
|
"flex w-full cursor-pointer items-center justify-between bg-transparent px-[0.62rem] py-2 text-left text-[0.78rem] text-[var(--text-muted)] hover:bg-[var(--panel-soft)] hover:text-[var(--text)]",
|
|
templ.KV("bg-[var(--panel-soft)] text-[var(--text)]", status == currentStatus),
|
|
}
|
|
hx-post="/api/watchlist"
|
|
hx-vals={ fmt.Sprintf(`{"anime_id": "%d", "anime_title": "%s", "anime_title_english": "%s", "anime_title_japanese": "%s", "anime_image": "%s", "status": "%s", "airing": "%v"}`, animeID, animeTitle, animeTitleEnglish, animeTitleJapanese, animeImage, status, airing) }
|
|
hx-target="#watchlist-dropdown"
|
|
hx-swap="outerHTML swap:150ms"
|
|
>
|
|
{ formatStatus(status) }
|
|
</button>
|
|
}
|
|
|
|
func formatStatus(status string) string {
|
|
switch status {
|
|
case "watching":
|
|
return "Watching"
|
|
case "completed":
|
|
return "Completed"
|
|
case "on_hold":
|
|
return "On hold"
|
|
case "dropped":
|
|
return "Dropped"
|
|
case "plan_to_watch":
|
|
return "Plan to watch"
|
|
default:
|
|
return status
|
|
}
|
|
}
|
|
|
|
templ AnimeRelationsList(relations []jikan.RelationEntry) {
|
|
if len(relations) > 1 {
|
|
<div class="grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-4 max-[680px]:grid-cols-2 max-[680px]:gap-3" id="relations-grid">
|
|
for _, rel := range relations {
|
|
@ui.AnimeCard(ui.AnimeCardProps{
|
|
ID: rel.Anime.MalID,
|
|
Title: rel.Anime.DisplayTitle(),
|
|
ImageURL: rel.Anime.ImageURL(),
|
|
Class: relationCardClass(rel),
|
|
ImgClass: "relation-thumb",
|
|
TitleClass: "relation-title",
|
|
CurrentNode: rel.IsCurrent,
|
|
}) {
|
|
if rel.Relation != "" && rel.Relation != "Current" {
|
|
<div class="mt-1 text-[0.76rem] text-[var(--text-faint)]">{ rel.Relation }</div>
|
|
}
|
|
}
|
|
}
|
|
</div>
|
|
} else {
|
|
<p class="text-[0.9rem] text-[var(--text-muted)]">No related anime found.</p>
|
|
}
|
|
}
|
|
|
|
func relationCardClass(rel jikan.RelationEntry) string {
|
|
base := "relation-card"
|
|
if rel.IsCurrent {
|
|
base += " current"
|
|
}
|
|
return base
|
|
}
|
|
|
|
templ AnimeRecommendations(recs []jikan.Anime) {
|
|
if len(recs) > 0 {
|
|
<div class="grid grid-cols-[repeat(auto-fill,minmax(190px,1fr))] gap-4 max-[680px]:grid-cols-2 max-[680px]:gap-3">
|
|
for _, anime := range recs {
|
|
@ui.AnimeCard(ui.AnimeCardProps{
|
|
ID: anime.MalID,
|
|
Title: anime.DisplayTitle(),
|
|
ImageURL: anime.ImageURL(),
|
|
Class: "relation-card",
|
|
ImgClass: "relation-thumb",
|
|
TitleClass: "relation-title",
|
|
})
|
|
}
|
|
</div>
|
|
} else {
|
|
<p class="text-[0.9rem] text-[var(--text-muted)]">No recommendations available.</p>
|
|
}
|
|
}
|
|
|
|
func hasExtraSidebarDetails(anime jikan.Anime) bool {
|
|
return anime.TitleJapanese != "" || len(anime.TitleSynonyms) > 0 || len(anime.Studios) > 0 || len(anime.Producers) > 0 || anime.Source != "" || len(anime.Demographics) > 0 || len(anime.Themes) > 0 || anime.Broadcast.String != "" || len(anime.Streaming) > 0
|
|
}
|