From f67aa1565a16ec878d9408cb9bc45c830fa60f2a Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 29 Dec 2023 22:23:01 -0800
Subject: fix(wrapped): sort anime watched by progress

---
 src/lib/Tools/Wrapped.svelte | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

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

diff --git a/src/lib/Tools/Wrapped.svelte b/src/lib/Tools/Wrapped.svelte
index 196ecffe..3d5dd29f 100644
--- a/src/lib/Tools/Wrapped.svelte
+++ b/src/lib/Tools/Wrapped.svelte
@@ -300,9 +300,13 @@
 			.sort((a, b) => {
 				switch (mediaSort) {
 					case SortOptions.MINUTES_WATCHED:
-						if (a.duration === undefined) return 1;
-						else if (b.duration === undefined) return -1;
-						else return b.duration - a.duration;
+						if (a.duration === undefined || a.mediaListEntry?.progress === undefined) return 1;
+						else if (b.duration === undefined || b.mediaListEntry?.progress === undefined)
+							return -1;
+						else
+							return (
+								b.duration * b.mediaListEntry.progress - a.duration * a.mediaListEntry.progress
+							);
 					case SortOptions.SCORE:
 					default:
 						if (a.mediaListEntry?.score === undefined) return 1;
-- 
cgit v1.2.3

