From 07acfb05dcb902707594f14c318e9ea774ba8145 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Wed, 22 Nov 2023 17:32:09 -0800
Subject: feat(wrapped): optional reread filter

---
 src/lib/Tools/Wrapped.svelte | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

(limited to 'src/lib/Tools/Wrapped.svelte')

diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte
index b9b3a1c8..56099af9 100644
--- a/src/lib/Tools/Wrapped.svelte
+++ b/src/lib/Tools/Wrapped.svelte
@@ -27,10 +27,12 @@
 	let watermark = false;
 	let includeMusic = false;
 	let includeSpecials = false;
+	let includeRepeats = false;
 
 	$: {
 		includeMusic = includeMusic;
 		includeSpecials = includeSpecials;
+		includeRepeats = includeRepeats;
 
 		update().then(() => {});
 	}
@@ -68,7 +70,8 @@
 				(item, index, self) =>
 					self.findIndex((itemToCompare) => itemToCompare.id === item.id) === index &&
 					item.mediaListEntry?.startedAt.year === currentYear &&
-					(includeMusic ? true : item.format !== 'MUSIC')
+					(includeMusic ? true : item.format !== 'MUSIC') &&
+					(includeRepeats ? true : item.mediaListEntry?.repeat === 0)
 			)
 			.sort((a, b) => {
 				if (a.mediaListEntry?.score === undefined) {
@@ -93,7 +96,8 @@
 			.filter(
 				(item, index, self) =>
 					self.findIndex((itemToCompare) => itemToCompare.id === item.id) === index &&
-					item.mediaListEntry?.startedAt.year === currentYear
+					item.mediaListEntry?.startedAt.year === currentYear &&
+					(includeRepeats ? true : item.mediaListEntry?.repeat === 0)
 			)
 			.sort((a, b) => {
 				if (a.mediaListEntry?.score === undefined) {
@@ -105,15 +109,16 @@
 				}
 			});
 
+		episodes = 0;
+
 		for (const media of animeList) {
 			episodes += media.mediaListEntry?.progress || 0;
 		}
 	};
 
 	/* eslint-disable @typescript-eslint/no-explicit-any */
-	const year = (statistic: { startYears: any }) => {
-		return statistic.startYears.find((y: { startYear: number }) => y.startYear === 2023);
-	};
+	const year = (statistic: { startYears: any }) =>
+		statistic.startYears.find((y: { startYear: number }) => y.startYear === 2023);
 
 	const screenshot = async (dark = false) => {
 		let element = document.querySelector('.categories-grid') as HTMLElement;
@@ -333,6 +338,7 @@
 			<input type="checkbox" bind:checked={watermark} /> Enable watermark<br />
 			<input type="checkbox" bind:checked={transparency} /> Enable background transparency<br />
 			<input type="checkbox" bind:checked={includeMusic} /> Include music<br />
+			<input type="checkbox" bind:checked={includeRepeats} /> Include rewatches & rereads<br />
 			<input type="checkbox" bind:checked={includeSpecials} /> Include specials and OVAs<br />
 			<input type="checkbox" bind:checked={abbreviateTitles} /> Fit long titles<br />
 			{#if abbreviateTitles}
-- 
cgit v1.2.3

