Filter own entries in calendar

This commit is contained in:
Eduard Urbach 2017-12-03 19:08:05 +01:00
parent e1277fa734
commit 46e5eb1f33
5 changed files with 29 additions and 6 deletions

View File

@ -39,8 +39,13 @@ func Get(ctx *aero.Context) string {
for i := 0; i < 7; i++ {
days[i] = &utils.CalendarDay{
Name: weekdayNames[(weekdayIndex+i)%7],
Class: "weekday",
Entries: []*utils.CalendarEntry{},
}
if days[i].Name == "Saturday" || days[i].Name == "Sunday" {
days[i].Class += " weekend"
}
}
// Add anime episodes to the days
@ -66,14 +71,14 @@ func Get(ctx *aero.Context) string {
entry := &utils.CalendarEntry{
Anime: animeEpisodes.Anime(),
Episode: episode,
Class: "calendar-entry mountable",
Added: false,
}
if user != nil {
animeListItem := user.AnimeList().Find(entry.Anime.ID)
if animeListItem != nil && (animeListItem.Status == arn.AnimeListStatusWatching || animeListItem.Status == arn.AnimeListStatusPlanned) {
entry.Class += " calendar-entry-personal"
entry.Added = true
}
}

View File

@ -1,13 +1,17 @@
component Calendar(days []*utils.CalendarDay, user *arn.User)
h1.mountable Calendar
.corner-buttons-hide-on-mobile
button.action(data-trigger="click", data-action="calendarShowAddedAnimeOnly", title="Show anime in my collection")
RawIcon("eye")
.week
each day in days
.weekday
div(class=day.Class)
h3.weekday-name.mountable(data-mountable-type=day.Name)= day.Name
.calendar-entries
each entry in day.Entries
div(data-mountable-type=day.Name, class=entry.Class)
.calendar-entry.mountable(data-mountable-type=day.Name, data-added=entry.Added)
a.ajax(href=entry.Anime.Link())
img.calendar-entry-image.lazy(data-src=entry.Anime.Image("large"), data-webp="true", alt=entry.Anime.Title.ByUser(user))
a.ajax(href=entry.Anime.Link())

View File

@ -14,6 +14,10 @@
text-align center
margin-bottom 1rem
.weekend
.weekday-name
font-weight bold
.calendar-entries
vertical
@ -28,7 +32,7 @@
height 4rem
object-fit cover
.calendar-entry-personal
.calendar-entry[data-added="true"]
border 2px solid main-color
:hover

View File

@ -17,4 +17,13 @@ export function hideAddedAnime() {
anime.classList.toggle("anime-grid-cell-hide")
}
}
}
// Hides anime that are not in your list.
export function calendarShowAddedAnimeOnly() {
for(let anime of findAll("calendar-entry")) {
if(anime.dataset.added === "false") {
anime.classList.toggle("hidden")
}
}
}

View File

@ -5,6 +5,7 @@ import "github.com/animenotifier/arn"
// CalendarDay is a calendar day.
type CalendarDay struct {
Name string
Class string
Entries []*CalendarEntry
}
@ -12,5 +13,5 @@ type CalendarDay struct {
type CalendarEntry struct {
Anime *arn.Anime
Episode *arn.AnimeEpisode
Class string
Added bool
}