151 lines
4.7 KiB
Plaintext
151 lines
4.7 KiB
Plaintext
package templates
|
|
|
|
import "mal/internal/jikan"
|
|
import "mal/internal/database"
|
|
import "mal/internal/shared/ui"
|
|
import "fmt"
|
|
|
|
type WatchingAnimeWithDetails struct {
|
|
Entry database.GetWatchingAnimeRow
|
|
Anime jikan.Anime
|
|
}
|
|
|
|
templ Notifications(watching []WatchingAnimeWithDetails) {
|
|
@Layout("mal - notifications") {
|
|
<div class="notifications-page">
|
|
<h1>Airing shows (tracking)</h1>
|
|
<p class="notifications-subtitle">Shows you're currently watching or planning to watch.</p>
|
|
|
|
if len(watching) == 0 {
|
|
@ui.EmptyState("No airing anime in your watching list.") {
|
|
<span style="font-size: var(--text-sm); margin-top: var(--space-sm); display: block;">Add currently airing shows to your watching list to see upcoming episodes here.</span>
|
|
}
|
|
} else {
|
|
<div class="notifications-list">
|
|
for _, item := range watching {
|
|
@NotificationCard(item)
|
|
}
|
|
</div>
|
|
}
|
|
|
|
<h1 style="margin-top: var(--space-2xl);">Discovered sequels</h1>
|
|
<p class="notifications-subtitle">Because you've watched prequels.</p>
|
|
|
|
<div hx-get="/notifications/upcoming" hx-trigger="load, every 15s" hx-swap="innerHTML">
|
|
@ui.LoadingIndicator("Syncing sequel graphs...")
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
func splitUpcomingSeasons(items []database.GetUpcomingSeasonsRow) (airing []database.GetUpcomingSeasonsRow, upcoming []database.GetUpcomingSeasonsRow) {
|
|
for _, item := range items {
|
|
if item.Status.Valid && item.Status.String == "Currently Airing" {
|
|
airing = append(airing, item)
|
|
} else {
|
|
upcoming = append(upcoming, item)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
templ UpcomingSeasonsList(upcomingSeasons []database.GetUpcomingSeasonsRow) {
|
|
if len(upcomingSeasons) == 0 {
|
|
@ui.EmptyState("No upcoming seasons for anime you've watched.") {
|
|
<span style="font-size: var(--text-sm); margin-top: var(--space-sm); display: block;">As you watch more shows, new seasons will appear here.</span>
|
|
}
|
|
} else {
|
|
@renderSplitSeasons(upcomingSeasons)
|
|
}
|
|
}
|
|
|
|
templ renderSplitSeasons(upcomingSeasons []database.GetUpcomingSeasonsRow) {
|
|
if airing, upcoming := splitUpcomingSeasons(upcomingSeasons); true {
|
|
if len(airing) > 0 {
|
|
<h2 style="font-size: var(--text-md); margin-bottom: var(--space-md); color: var(--text-muted);">Airing now (not tracked)</h2>
|
|
<div class="notifications-list" style="margin-bottom: var(--space-xl);">
|
|
for _, item := range airing {
|
|
@UpcomingSeasonCard(item)
|
|
}
|
|
</div>
|
|
}
|
|
|
|
if len(upcoming) > 0 {
|
|
<h2 style="font-size: var(--text-md); margin-bottom: var(--space-md); color: var(--text-muted);">Announced & upcoming</h2>
|
|
<div class="notifications-list">
|
|
for _, item := range upcoming {
|
|
@UpcomingSeasonCard(item)
|
|
}
|
|
</div>
|
|
}
|
|
}
|
|
}
|
|
|
|
templ UpcomingSeasonCard(item database.GetUpcomingSeasonsRow) {
|
|
@ui.AnimeCard(ui.AnimeCardProps{
|
|
ID: int(item.ID),
|
|
Title: displaySeasonTitle(item),
|
|
ImageURL: item.ImageUrl,
|
|
Class: "notification-card",
|
|
ImgClass: "notification-image",
|
|
}) {
|
|
<div class="notification-content">
|
|
<div class="notification-title">
|
|
{ displaySeasonTitle(item) }
|
|
</div>
|
|
<div class="notification-meta">
|
|
<span class="notification-broadcast" style="color: var(--text-muted) !important;">Because you watched { item.PrequelTitle }</span>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
func displaySeasonTitle(entry database.GetUpcomingSeasonsRow) string {
|
|
return database.DisplayTitle(entry.TitleEnglish, entry.TitleJapanese, entry.TitleOriginal)
|
|
}
|
|
|
|
templ NotificationCard(item WatchingAnimeWithDetails) {
|
|
@ui.AnimeCard(ui.AnimeCardProps{
|
|
ID: int(item.Entry.AnimeID),
|
|
Title: displayTitle(item.Entry),
|
|
ImageURL: item.Entry.ImageUrl,
|
|
Class: "notification-card",
|
|
ImgClass: "notification-image",
|
|
}) {
|
|
<div class="notification-content">
|
|
<div class="notification-title">
|
|
{ displayTitle(item.Entry) }
|
|
</div>
|
|
<div class="notification-meta">
|
|
if item.Anime.Broadcast.String != "" {
|
|
<span class="notification-broadcast">{ item.Anime.Broadcast.String }</span>
|
|
}
|
|
if item.Anime.Episodes > 0 {
|
|
<span class="notification-progress">
|
|
if item.Entry.CurrentEpisode.Valid {
|
|
{ fmt.Sprintf("%d / %d eps", item.Entry.CurrentEpisode.Int64, item.Anime.Episodes) }
|
|
} else {
|
|
{ fmt.Sprintf("0 / %d eps", item.Anime.Episodes) }
|
|
}
|
|
</span>
|
|
} else if item.Entry.CurrentEpisode.Valid && item.Entry.CurrentEpisode.Int64 > 0 {
|
|
<span class="notification-progress">
|
|
{ fmt.Sprintf("%d eps watched", item.Entry.CurrentEpisode.Int64) }
|
|
</span>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
func displayTitle(entry database.GetWatchingAnimeRow) string {
|
|
return database.DisplayTitle(entry.TitleEnglish, entry.TitleJapanese, entry.TitleOriginal)
|
|
}
|
|
|
|
func truncate(s string, max int) string {
|
|
if len(s) <= max {
|
|
return s
|
|
}
|
|
return s[:max-3] + "..."
|
|
}
|