From c81866e53bac6ea8ccee359b343a18dd87861540 Mon Sep 17 00:00:00 2001 From: ld3zian <42660576+ld3z@users.noreply.github.com> Date: Mon, 27 Jan 2025 18:52:29 -0700 Subject: [PATCH] add genre filter --- src/components/ComicCard.astro | 24 ++- src/components/GenreFilter.astro | 157 ++++++++++++++++++++ src/pages/[lang]/[contentType]/[type].astro | 2 + 3 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/components/GenreFilter.astro diff --git a/src/components/ComicCard.astro b/src/components/ComicCard.astro index 52f4f12..37687b2 100644 --- a/src/components/ComicCard.astro +++ b/src/components/ComicCard.astro @@ -17,7 +17,10 @@ const coverUrl = comic.md_comics.md_covers[0] const isNSFW = comic.md_comics.content_rating === 'erotica'; --- -
+
{!isAvif ? ( @@ -220,4 +223,23 @@ const isNSFW = comic.md_comics.content_rating === 'erotica'; setInterval(() => updateTimer(timer), 1000); }); }); + + function filterComics() { + const excludedGenres = new Set(JSON.parse(localStorage.getItem('excluded-genres') || '[]')); + + document.querySelectorAll('[data-genres]').forEach(card => { + const cardGenres = JSON.parse((card as HTMLElement).dataset.genres || '[]'); + const shouldHide = cardGenres.some((genreId: number) => excludedGenres.has(genreId)); + + card.classList.toggle('hidden', shouldHide); + }); + } + + // Listen for genre updates + window.addEventListener('genresUpdated', () => { + filterComics(); + }); + + // Initial filter + filterComics(); \ No newline at end of file diff --git a/src/components/GenreFilter.astro b/src/components/GenreFilter.astro new file mode 100644 index 0000000..030a502 --- /dev/null +++ b/src/components/GenreFilter.astro @@ -0,0 +1,157 @@ +--- +import { fetchGenres } from '../lib/api'; + +const genres = await fetchGenres(); +--- + +
+ + + +
+ + \ No newline at end of file diff --git a/src/pages/[lang]/[contentType]/[type].astro b/src/pages/[lang]/[contentType]/[type].astro index 8b2b16c..8e4fa12 100644 --- a/src/pages/[lang]/[contentType]/[type].astro +++ b/src/pages/[lang]/[contentType]/[type].astro @@ -5,6 +5,7 @@ import LoadingCard from '../../../components/LoadingCard.astro'; import RSSLink from '../../../components/RSSLink.astro'; import TypeFilter from '../../../components/TypeFilter.astro'; import LanguageSelector from '../../../components/LanguageSelector.astro'; +import GenreFilter from '../../../components/GenreFilter.astro'; import { fetchComics, fetchGenres, isValidLanguage, isValidContentType, isValidComicType, getLanguageName } from '../../../lib/api'; import type { Comic, Genre } from '../../../lib/types'; @@ -39,6 +40,7 @@ const title = `ComicK - ${getLanguageName(lang!)} ${contentType?.toUpperCase()}
+