diff --git a/src/lib/components/home-items.svelte b/src/lib/components/home-items.svelte
index dd3a355..3c080c3 100644
--- a/src/lib/components/home-items.svelte
+++ b/src/lib/components/home-items.svelte
@@ -2,11 +2,15 @@
import { Star, CalendarDays, Clapperboard, MoveUpRight } from 'lucide-svelte';
import ItemRequest from './item-request.svelte';
import { roundOff } from '$lib/helpers';
+ import { writable } from 'svelte/store';
+ import { goto } from '$app/navigation';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export let data: any;
export let name: string;
export let type: string;
+
+ const hoveredItem = writable(null);
@@ -28,6 +32,19 @@
{#each data.results as item}
($hoveredItem = item.id)}
+ on:mouseleave={() => ($hoveredItem = null)}
+ on:focus={() => ($hoveredItem = item.id)}
+ on:blur={() => ($hoveredItem = null)}
+ on:keydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') {
+ e.preventDefault();
+ $hoveredItem = item.id;
+ }
+ }}
+ on:click={() => goto(`/${type}/${item.id}`)}
>
-
-
-
+ {#if $hoveredItem === item.id}
+
+ {/if}
+
{/each}
diff --git a/src/lib/components/item-request.svelte b/src/lib/components/item-request.svelte
index 7ff40c7..946ee4e 100644
--- a/src/lib/components/item-request.svelte
+++ b/src/lib/components/item-request.svelte
@@ -4,11 +4,34 @@
import { toast } from 'svelte-sonner';
import { getExternalID } from '$lib/tmdb';
import { ItemsService } from '$lib/client';
+ import { onMount } from 'svelte';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export let data: any;
export let type: string;
+ let isInLibrary = false;
+ let isChecking = true;
+
+ async function checkItemExists(id: number) {
+ try {
+ const externalIds = await getExternalID(fetch, type, id);
+ const response = await ItemsService.getItems({
+ query: {
+ search: externalIds.imdb_id
+ }
+ });
+
+ if (response.data && response.data.items.length > 0) {
+ isInLibrary = true;
+ }
+ } catch {
+ //pass
+ } finally {
+ isChecking = false;
+ }
+ }
+
async function requestItem(id: number) {
const externalIds = await getExternalID(fetch, type, id);
const response = await ItemsService.addItems({
@@ -19,36 +42,47 @@
if (!response.error) {
toast.success('Media requested successfully');
+ isInLibrary = true;
} else {
toast.error('An error occurred while requesting the media');
}
}
+
+ onMount(() => {
+ checkItemExists(data.id);
+ });
-
-
-
-
-
-
- Requesting {data.title || data.name || data.original_name}
-
-
- Cancel
- {
- await requestItem(data.id);
- }}>ContinueChecking...
+{:else if isInLibrary}
+
+{:else}
+
+
+
-
-
-
+
+
+
+ Requesting {data.title || data.name || data.original_name}
+
+
+ Cancel
+ {
+ await requestItem(data.id);
+ }}>Continue
+
+
+
+{/if}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 861cafa..e662205 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -7,6 +7,7 @@
import { Button } from '$lib/components/ui/button';
import { roundOff } from '$lib/helpers';
import HomeItems from '$lib/components/home-items.svelte';
+ import ItemRequest from '$lib/components/item-request.svelte';
export let data: PageData;
@@ -62,15 +63,7 @@
{nowPlaying.overview}