131 lines
3.9 KiB
Plaintext
131 lines
3.9 KiB
Plaintext
package templates
|
|
|
|
import "mal/internal/jikan"
|
|
import "mal/internal/database"
|
|
import "fmt"
|
|
|
|
type WatchingAnimeWithDetails struct {
|
|
Entry database.GetWatchingAnimeRow
|
|
Anime jikan.Anime
|
|
}
|
|
|
|
templ Notifications(watching []WatchingAnimeWithDetails, upcomingSeasons []database.GetUpcomingSeasonsRow) {
|
|
@Layout("mal - notifications") {
|
|
<div class="notifications-page">
|
|
<h1>upcoming episodes</h1>
|
|
<p class="notifications-subtitle">anime you're watching</p>
|
|
|
|
if len(watching) == 0 {
|
|
<div class="no-notifications">
|
|
<p>no airing anime in your watching list</p>
|
|
<p class="hint">add currently airing shows to your watching list to see upcoming episodes here</p>
|
|
</div>
|
|
} else {
|
|
<div class="notifications-list">
|
|
for _, item := range watching {
|
|
@NotificationCard(item)
|
|
}
|
|
</div>
|
|
}
|
|
|
|
<h1 style="margin-top: var(--space-2xl);">upcoming seasons</h1>
|
|
<p class="notifications-subtitle">because you've watched prequels</p>
|
|
|
|
if len(upcomingSeasons) == 0 {
|
|
<div class="no-notifications">
|
|
<p>no upcoming seasons for anime you've watched</p>
|
|
<p class="hint">as you watch more shows, new seasons will appear here</p>
|
|
</div>
|
|
} else {
|
|
<div class="notifications-list">
|
|
for _, item := range upcomingSeasons {
|
|
@UpcomingSeasonCard(item)
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
}
|
|
|
|
templ UpcomingSeasonCard(item database.GetUpcomingSeasonsRow) {
|
|
<a href={ templ.URL(fmt.Sprintf("/anime/%d", item.ID)) } class="notification-card">
|
|
<div class="notification-image">
|
|
if item.ImageUrl != "" {
|
|
<img src={ item.ImageUrl } alt={ displaySeasonTitle(item) } loading="lazy"/>
|
|
} else {
|
|
<div class="no-image">no image</div>
|
|
}
|
|
</div>
|
|
<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>
|
|
</a>
|
|
}
|
|
|
|
func displaySeasonTitle(entry database.GetUpcomingSeasonsRow) string {
|
|
if entry.TitleEnglish.Valid && entry.TitleEnglish.String != "" {
|
|
return entry.TitleEnglish.String
|
|
}
|
|
if entry.TitleJapanese.Valid && entry.TitleJapanese.String != "" {
|
|
return entry.TitleJapanese.String
|
|
}
|
|
return entry.TitleOriginal
|
|
}
|
|
|
|
templ NotificationCard(item WatchingAnimeWithDetails) {
|
|
<a href={ templ.URL(fmt.Sprintf("/anime/%d", item.Entry.AnimeID)) } class="notification-card">
|
|
<div class="notification-image">
|
|
if item.Entry.ImageUrl != "" {
|
|
<img src={ item.Entry.ImageUrl } alt={ displayTitle(item.Entry) } loading="lazy"/>
|
|
} else {
|
|
<div class="no-image">no image</div>
|
|
}
|
|
</div>
|
|
<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>
|
|
</a>
|
|
}
|
|
|
|
func displayTitle(entry database.GetWatchingAnimeRow) string {
|
|
if entry.TitleEnglish.Valid && entry.TitleEnglish.String != "" {
|
|
return entry.TitleEnglish.String
|
|
}
|
|
if entry.TitleJapanese.Valid && entry.TitleJapanese.String != "" {
|
|
return entry.TitleJapanese.String
|
|
}
|
|
return entry.TitleOriginal
|
|
}
|
|
|
|
func truncate(s string, max int) string {
|
|
if len(s) <= max {
|
|
return s
|
|
}
|
|
return s[:max-3] + "..."
|
|
}
|