Separate toggle and hide logic

This commit is contained in:
Eduard Urbach 2018-07-06 01:52:05 +09:00
parent a491ac50a1
commit 20ebafe83a
3 changed files with 22 additions and 14 deletions

View File

@ -4,7 +4,7 @@ component ExploreAnime(animes []*arn.Anime, year string, season string, status s
.corner-buttons-hide-on-mobile
if user != nil
button.action(data-trigger="click", data-action="hideAddedAnime", title="Hide anime in my collection")
button.action(data-trigger="click", data-action="toggleHideAddedAnime", title="Hide anime in my collection")
RawIcon("eye-slash")
a.button(href="/halloffame", title="Hall of Fame")

View File

@ -6,7 +6,7 @@ component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore flo
.corner-buttons-hide-on-mobile
if user != nil
button.action(data-trigger="click", data-action="hideAddedAnime", title="Hide anime in my collection")
button.action(data-trigger="click", data-action="toggleHideAddedAnime", title="Hide anime in my collection")
RawIcon("eye-slash")
a.button(href="/genres", title="View genres")

View File

@ -1,5 +1,6 @@
import AnimeNotifier from "../AnimeNotifier"
import { findAll } from "scripts/Utils";
import toggleBoolString from "../Utils/toggleBoolString";
// Filter anime on explore page
export function filterAnime(arn: AnimeNotifier, input: HTMLInputElement) {
@ -25,20 +26,27 @@ export function filterAnime(arn: AnimeNotifier, input: HTMLInputElement) {
arn.diff(`${root.dataset.url}/${year}/${season}/${status}/${type}`)
}
// Hides anime that are already in your list. And "toggles" localStorage.hide if button is pressed
export function hideAddedAnime(arn?: AnimeNotifier, input?: HTMLButtonElement) {
if(input) {
// Toggle hiding added anime.
export function toggleHideAddedAnime(arn: AnimeNotifier, input: HTMLButtonElement) {
// Toggle state
if(localStorage.getItem("hide-added-anime") === "true") {
localStorage.setItem("hide-added-anime", "false")
} else {
localStorage.setItem("hide-added-anime", "true")
}
}
if(input || localStorage.getItem("hide-added-anime") === "true") {
// Hide anime
hideAddedAnime()
}
// Hides anime that are already in your list.
export function hideAddedAnime() {
for(let anime of findAll("anime-grid-cell")) {
if(anime.dataset.added === "true") {
anime.classList.toggle("anime-grid-cell-hide")
if(localStorage.getItem("hide-added-anime") === "true") {
anime.classList.add("anime-grid-cell-hide")
} else {
anime.classList.remove("anime-grid-cell-hide")
}
}
}