84 lines
4.0 KiB
Svelte
84 lines
4.0 KiB
Svelte
<script lang="ts">
|
|
|
|
import {AniListSearch} from "../../wailsjs/go/main/App";
|
|
import type {AniSearchList} from "../anilist/types/AniListTypes";
|
|
import {push} from "svelte-spa-router";
|
|
|
|
let aniSearch = ""
|
|
let aniListSearch: AniSearchList
|
|
let aniListSearchActive = false
|
|
|
|
function runAniListSearch(): void {
|
|
AniListSearch(aniSearch).then(result => {
|
|
aniListSearch = result
|
|
aniListSearchActive = true
|
|
})
|
|
}
|
|
|
|
function searchDropdown(): void {
|
|
let dropdown = document.querySelector("#aniListSearchDropdown")
|
|
dropdown.classList.toggle("hidden")
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<div id="searchDropdown" class="relative w-64 md:w-48">
|
|
<div class="flex">
|
|
<label for="anime-search" class="mb-2 text-sm font-medium sr-only text-white">Find
|
|
Anime</label>
|
|
<div class="relative w-full">
|
|
<input type="search" id="anime-search" bind:value={aniSearch}
|
|
class="rounded-s-lg block p-2.5 w-full z-20 text-sm rounded-e-lg bg-gray-700 border-s-gray-700 border-gray-600 placeholder-gray-400 text-white focus:border-blue-500"
|
|
placeholder="Search for Anime"
|
|
on:keypress={(e) => {
|
|
if (e.key === "Enter") {
|
|
searchDropdown()
|
|
if(aniSearch.length > 0) runAniListSearch()
|
|
}
|
|
}}
|
|
required/>
|
|
<button id="aniListSearchButton"
|
|
class="absolute top-0 end-0 h-full p-2.5 text-sm font-medium rounded-e-lg border focus:ring-4 focus:outline-none bg-blue-600 hover:bg-blue-700 focus:ring-blue-800"
|
|
on:click={() => {
|
|
searchDropdown()
|
|
if(aniSearch.length > 0) runAniListSearch()
|
|
}}>
|
|
<svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
|
|
viewBox="0 0 20 20">
|
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/>
|
|
</svg>
|
|
<span class="sr-only">Search</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="aniListSearchDropdown" class="z-10 absolute left-0 hidden bg-white rounded-lg shadow w-60 2xl:w-80 dark:bg-gray-700">
|
|
{#if aniListSearchActive}
|
|
<ul class="h-56 w-full py-2 overflow-y-auto text-gray-700 dark:text-gray-200"
|
|
aria-labelledby="aniListSearchButton">
|
|
{#each aniListSearch.data.Page.media as media}
|
|
<li class="w-full">
|
|
<div class="flex w-full items-start p-1 hover:bg-gray-600 hover:text-white rounded-lg">
|
|
<button on:click={() => {
|
|
searchDropdown()
|
|
push(`#/anime/${media.id}`)
|
|
}}
|
|
>
|
|
<img class="rounded-bl-lg rounded-tl-lg max-w-24 max-h-24" src={media.coverImage.large}
|
|
alt="{media.title.english === '' || media.title.english === null ? media.title.romaji : media.title.english} Cover">
|
|
</button>
|
|
<button class="rounded-bl-lg rounded-tl-lg w-full h-24" on:click={() => {
|
|
searchDropdown()
|
|
push(`#/anime/${media.id}`)
|
|
}} >{media.title.english === '' || media.title.english === null ? media.title.romaji : media.title.english }</button>
|
|
</div>
|
|
</li>
|
|
{/each}
|
|
</ul>
|
|
{:else if aniSearch.length === 0}
|
|
<div class="m-4">Please enter a search term...</div>
|
|
{/if}
|
|
</div>
|
|
</div> |