From 2ab9ca46d885ff992c0215261138941799822a8e Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 27 Apr 2019 20:23:15 +0900 Subject: [PATCH] Calendar now saves the "show added anime only" setting --- pages/calendar/calendar.pixy | 27 +++++++++++++++++--------- pages/calendar/calendar.scarlet | 6 ++++++ scripts/Actions/Explore.ts | 34 ++++++++++++++++++++------------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/pages/calendar/calendar.pixy b/pages/calendar/calendar.pixy index 92285085..6585e388 100644 --- a/pages/calendar/calendar.pixy +++ b/pages/calendar/calendar.pixy @@ -6,21 +6,30 @@ component Calendar(days []*utils.CalendarDay, user *arn.User) button.action(data-trigger="click", data-action="calendarShowAddedAnimeOnly", data-api="/api/settings/" + user.ID, title="Show anime in my collection") RawIcon("eye-slash") + if user != nil + #calendar(data-show-added-anime-only=user.Settings().Calendar.ShowAddedAnimeOnly) + CalendarWeek(days, user) + else + #calendar + CalendarWeek(days, user) + +component CalendarWeek(days []*utils.CalendarDay, user *arn.User) .week each day in days div(class=day.Class) h3.weekday-name.mountable(data-mountable-type=day.Name)= day.Name - .calendar-entries - each entry in day.Entries - CalendarEntry(day, entry, user) + if user == nil + .calendar-entries + each entry in day.Entries + CalendarEntry(day, entry, user) + else + .calendar-entries + each entry in day.Entries + CalendarEntry(day, entry, user) component CalendarEntry(day *utils.CalendarDay, entry *utils.CalendarEntry, user *arn.User) - if user != nil && user.Settings().CalendarSettings.ShowUserList == false && !entry.Added - a.calendar-entry.hidden.mountable(href=entry.Anime.Link(), data-mountable-type=day.Name, data-added=entry.Added) - CalendarView(day, entry, user) - else - a.calendar-entry.mountable(href=entry.Anime.Link(), data-mountable-type=day.Name, data-added=entry.Added) - CalendarView(day, entry, user) + a.calendar-entry.mountable(href=entry.Anime.Link(), data-mountable-type=day.Name, data-added=entry.Added) + CalendarView(day, entry, user) component CalendarView(day *utils.CalendarDay, entry *utils.CalendarEntry, user *arn.User) img.calendar-entry-image.lazy(data-src=entry.Anime.ImageLink("small"), data-webp="true", data-color=entry.Anime.AverageColor(), alt=entry.Anime.Title.ByUser(user)) diff --git a/pages/calendar/calendar.scarlet b/pages/calendar/calendar.scarlet index c66ae3bf..34e510cc 100644 --- a/pages/calendar/calendar.scarlet +++ b/pages/calendar/calendar.scarlet @@ -1,3 +1,9 @@ +#calendar + [data-show-added-anime-only="true"] + .calendar-entry + [data-added="false"] + display none + .week vertical diff --git a/scripts/Actions/Explore.ts b/scripts/Actions/Explore.ts index a67dbcc6..d6ea4467 100644 --- a/scripts/Actions/Explore.ts +++ b/scripts/Actions/Explore.ts @@ -42,21 +42,29 @@ export function hideAddedAnime() { } // Hides anime that are not in your list. -export function calendarShowAddedAnimeOnly(arn: AnimeNotifier, element: HTMLInputElement) { - for(let anime of findAll("calendar-entry")) { - if(anime.dataset.added === "false") { - anime.classList.toggle("hidden") - } +export async function calendarShowAddedAnimeOnly(arn: AnimeNotifier, element: HTMLInputElement) { + let calendar = document.getElementById("calendar") + + if(!calendar || calendar.dataset.showAddedAnimeOnly === undefined) { + return } - const showUserList = !Array.from(document.getElementsByClassName("calendar-entry")) - .some(value => value.classList.contains("hidden")); - - let obj = { - "CalendarSettings.ShowUserList": showUserList + // Toggling the switch will trigger the CSS rules + if(calendar.dataset.showAddedAnimeOnly === "true") { + calendar.dataset.showAddedAnimeOnly = "false" + } else { + calendar.dataset.showAddedAnimeOnly = "true" } - let apiEndpoint = arn.findAPIEndpoint(element); - arn.post(apiEndpoint, obj) - .catch(err => arn.statusMessage.showError(err)); + // Save the state in the database + let showAddedAnimeOnly = calendar.dataset.showAddedAnimeOnly === "true" + let apiEndpoint = arn.findAPIEndpoint(element) + + try { + await arn.post(apiEndpoint, { + "Calendar.ShowAddedAnimeOnly": showAddedAnimeOnly + }) + } catch(err) { + arn.statusMessage.showError(err) + } } \ No newline at end of file