anitrack/frontend/src/Search.svelte

141 lines
7.4 KiB
Svelte

<script lang="ts">
import {AniListSearch} from "../wailsjs/go/main/App";
import type {AniSearchList} from "./anilist/types/AniListTypes";
import {GetAniListSingleItemAndOpenModal} from "./GetAniListSingleItemAndOpenModal.svelte";
let aniSearch = ""
let aniListSearch: AniSearchList
let aniListSearchActive = false
function runAniListSearch(): void {
AniListSearch(aniSearch).then(result => {
aniListSearch = result
aniListSearchActive = true
})
}
</script>
<div>
<div class="input-box" id="aniSearch">
<input autocomplete="off" bind:value={aniSearch} class="input text-black" id="aniSearchInput" type="text"/>
<button class="text-gray-800 dark:text-white hover:bg-gray-50 focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-4 lg:px-5 py-2 lg:py-2.5 mr-2 dark:hover:bg-gray-700 focus:outline-none dark:focus:ring-gray-800" on:click={runAniListSearch}>Search AniList</button>
</div>
{#if aniListSearchActive}
<div class="mx-auto max-w-2xl px-4 py-16 sm:px-6 sm:py-24 lg:max-w-7xl lg:px-8">
<h1>Your Search Results</h1>
<div class="grid grid-cols-1 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 xl:gap-x-8">
{#each aniListSearch.data.Page.media as media}
<button on:click={() => GetAniListSingleItemAndOpenModal(media.id)} class="group">
<div class="justify-center rounded-lg bg-gray-200">
<img src={media.coverImage.large} alt="anime cover"/>
</div>
<h3 class="mt-4 text-sm text-white-700">{
media.title.english === "" ?
media.title.romaji :
media.title.english
}</h3>
</button>
{/each}
</div>
</div>
{/if}
<form class="max-w-md mx-auto">
<div class="flex">
<label for="anime-search" class="mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white">Find Anime</label>
<div class="relative w-full">
<input type="search" id="anime-search" class="rounded-s-lg block p-2.5 w-full z-20 text-sm text-gray-900 bg-gray-50 rounded-e-lg border-s-gray-50 border-s-2 border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-s-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:border-blue-500" placeholder="Search for Anime" required />
<button type="submit" id="aniListSearchButton" data-dropdown-toggle="aniListSearch" data-dropdown-placement="bottom"
class="absolute top-0 end-0 h-full p-2.5 text-sm font-medium text-white bg-blue-700 rounded-e-lg border border-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">
<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>
</form>
<div id="aniListSearch" class="z-10 hidden bg-white rounded-lg shadow w-60 dark:bg-gray-700">
<ul class="h-48 py-2 overflow-y-auto text-gray-700 dark:text-gray-200" aria-labelledby="aniListSearchButton">
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-1.jpg"
alt="Jese image">
Jese Leos
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-2.jpg"
alt="Jese image">
Robert Gough
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-3.jpg"
alt="Jese image">
Bonnie Green
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-4.jpg"
alt="Jese image">
Leslie Livingston
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-5.jpg"
alt="Jese image">
Michael Gough
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-2.jpg"
alt="Jese image">
Joseph Mcfall
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-3.jpg"
alt="Jese image">
Roberta Casas
</a>
</li>
<li>
<a href="#"
class="flex items-center px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">
<img class="w-6 h-6 me-2 rounded-full" src="/docs/images/people/profile-picture-1.jpg"
alt="Jese image">
Neil Sims
</a>
</li>
</ul>
<a href="#"
class="flex items-center p-3 text-sm font-medium text-blue-600 border-t border-gray-200 rounded-b-lg bg-gray-50 dark:border-gray-600 hover:bg-gray-100 dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-blue-500 hover:underline">
<svg class="w-4 h-4 me-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor"
viewBox="0 0 20 18">
<path d="M6.5 9a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM8 10H5a5.006 5.006 0 0 0-5 5v2a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-2a5.006 5.006 0 0 0-5-5Zm11-3h-2V5a1 1 0 0 0-2 0v2h-2a1 1 0 1 0 0 2h2v2a1 1 0 0 0 2 0V9h2a1 1 0 1 0 0-2Z"/>
</svg>
Add new user
</a>
</div>
</div>