From f0767e860609ac5d3a33b26357cb21ec4f16922c Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 7 Jan 2024 00:13:40 -0800
Subject: refactor(hovercover): simple state

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

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

diff --git a/src/lib/Tools/SequelSpy.svelte b/src/lib/Tools/SequelSpy.svelte
index ea6f74d8..acaf9cdf 100644
--- a/src/lib/Tools/SequelSpy.svelte
+++ b/src/lib/Tools/SequelSpy.svelte
@@ -9,7 +9,12 @@
 	import { page } from '$app/stores';
 	import { browser } from '$app/environment';
 	import { season as getSeason } from '$lib/Media/Anime/season';
-	import { onMouseEnter, onMouseLeave, onMouseMove } from '$lib/Media/Cover/hoverCover';
+	import {
+		onMouseEnter,
+		onMouseLeave,
+		onMouseMove,
+		type HoverCoverResponse
+	} from '$lib/Media/Cover/hoverCover';
 	import HoverCover from '$lib/Media/Cover/HoverCover.svelte';
 
 	export let user: AniListAuthorisation;
@@ -18,9 +23,7 @@
 	const urlParameters = browser ? new URLSearchParams(window.location.search) : null;
 	let year = parseOrDefault(urlParameters, 'year', new Date().getFullYear());
 	let season = parseOrDefault(urlParameters, 'season', getSeason());
-	let hovering = false;
-	let hoveredMedia: Media | null = null;
-	let imageStyle = '';
+	let hoverCoverState: HoverCoverResponse = {};
 
 	$: {
 		if (year.toString().length === 4) currentPrequels = prequels(user, year, season);
@@ -60,19 +63,21 @@
 					on:mouseenter={() => {
 						const response = onMouseEnter(prequel);
 
-						hovering = response.hovering;
-						hoveredMedia = response.media;
+						hoverCoverState.hovering = response.hovering;
+						hoverCoverState.item = response.item;
+						hoverCoverState.media = response.media;
 					}}
 					on:mouseleave={() => {
 						const response = onMouseLeave();
 
-						hovering = response.hovering;
-						hoveredMedia = response.media;
+						hoverCoverState.hovering = response.hovering;
+						hoverCoverState.item = response.item;
+						hoverCoverState.media = response.media;
 					}}
 					on:mousemove={(e) => {
-						const response = onMouseMove(e);
+						const response = onMouseMove(e, 300);
 
-						imageStyle = response.style;
+						hoverCoverState.style = response.style;
 					}}
 				>
 					<a href={`https://anilist.co/anime/${prequel.id}`} target="_blank">
@@ -92,4 +97,4 @@
 	of episodes of all direct prequels.
 </div>
 
-<HoverCover {hovering} {hoveredMedia} {imageStyle} />
+<HoverCover options={hoverCoverState} width={300} />
-- 
cgit v1.2.3

