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++ { for i := 0; i < 7; i++ {
days[i] = &utils.CalendarDay{ days[i] = &utils.CalendarDay{
Name: weekdayNames[(weekdayIndex+i)%7], Name: weekdayNames[(weekdayIndex+i)%7],
Class: "weekday",
Entries: []*utils.CalendarEntry{}, Entries: []*utils.CalendarEntry{},
} }
if days[i].Name == "Saturday" || days[i].Name == "Sunday" {
days[i].Class += " weekend"
}
} }
// Add anime episodes to the days // Add anime episodes to the days
@ -66,14 +71,14 @@ func Get(ctx *aero.Context) string {
entry := &utils.CalendarEntry{ entry := &utils.CalendarEntry{
Anime: animeEpisodes.Anime(), Anime: animeEpisodes.Anime(),
Episode: episode, Episode: episode,
Class: "calendar-entry mountable", Added: false,
} }
if user != nil { if user != nil {
animeListItem := user.AnimeList().Find(entry.Anime.ID) animeListItem := user.AnimeList().Find(entry.Anime.ID)
if animeListItem != nil && (animeListItem.Status == arn.AnimeListStatusWatching || animeListItem.Status == arn.AnimeListStatusPlanned) { 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) component Calendar(days []*utils.CalendarDay, user *arn.User)
h1.mountable Calendar 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 .week
each day in days each day in days
.weekday div(class=day.Class)
h3.weekday-name.mountable(data-mountable-type=day.Name)= day.Name h3.weekday-name.mountable(data-mountable-type=day.Name)= day.Name
.calendar-entries .calendar-entries
each entry in day.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()) 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)) 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()) a.ajax(href=entry.Anime.Link())

View File

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

View File

@ -18,3 +18,12 @@ export function hideAddedAnime() {
} }
} }
} }
// 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. // CalendarDay is a calendar day.
type CalendarDay struct { type CalendarDay struct {
Name string Name string
Class string
Entries []*CalendarEntry Entries []*CalendarEntry
} }
@ -12,5 +13,5 @@ type CalendarDay struct {
type CalendarEntry struct { type CalendarEntry struct {
Anime *arn.Anime Anime *arn.Anime
Episode *arn.AnimeEpisode Episode *arn.AnimeEpisode
Class string Added bool
} }