Separate toggle and hide logic
This commit is contained in:
parent
a491ac50a1
commit
20ebafe83a
@ -4,7 +4,7 @@ component ExploreAnime(animes []*arn.Anime, year string, season string, status s
|
|||||||
|
|
||||||
.corner-buttons-hide-on-mobile
|
.corner-buttons-hide-on-mobile
|
||||||
if user != nil
|
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")
|
RawIcon("eye-slash")
|
||||||
|
|
||||||
a.button(href="/halloffame", title="Hall of Fame")
|
a.button(href="/halloffame", title="Hall of Fame")
|
||||||
|
@ -6,7 +6,7 @@ component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore flo
|
|||||||
|
|
||||||
.corner-buttons-hide-on-mobile
|
.corner-buttons-hide-on-mobile
|
||||||
if user != nil
|
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")
|
RawIcon("eye-slash")
|
||||||
|
|
||||||
a.button(href="/genres", title="View genres")
|
a.button(href="/genres", title="View genres")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import AnimeNotifier from "../AnimeNotifier"
|
import AnimeNotifier from "../AnimeNotifier"
|
||||||
import { findAll } from "scripts/Utils";
|
import { findAll } from "scripts/Utils";
|
||||||
|
import toggleBoolString from "../Utils/toggleBoolString";
|
||||||
|
|
||||||
// Filter anime on explore page
|
// Filter anime on explore page
|
||||||
export function filterAnime(arn: AnimeNotifier, input: HTMLInputElement) {
|
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}`)
|
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
|
// Toggle hiding added anime.
|
||||||
export function hideAddedAnime(arn?: AnimeNotifier, input?: HTMLButtonElement) {
|
export function toggleHideAddedAnime(arn: AnimeNotifier, input: HTMLButtonElement) {
|
||||||
if(input) {
|
// Toggle state
|
||||||
if(localStorage.getItem("hide-added-anime") === "true") {
|
if(localStorage.getItem("hide-added-anime") === "true") {
|
||||||
localStorage.setItem("hide-added-anime", "false")
|
localStorage.setItem("hide-added-anime", "false")
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem("hide-added-anime", "true")
|
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")) {
|
for(let anime of findAll("anime-grid-cell")) {
|
||||||
if(anime.dataset.added === "true") {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user