allow two children to get single anime and launch modal

This commit is contained in:
John O'Keefe 2024-07-25 20:02:15 -04:00
parent 93f54d8425
commit 69ce979367
5 changed files with 191 additions and 44 deletions

View File

@ -1,4 +1,5 @@
<script lang="ts">
import {GetAniListSingleItemAndOpenModal, anime, title, anilistModal} from "./GetAniListSingleItemAndOpenModal.svelte";
import {
AniListSearch,
GetAniListUserWatchingList
@ -6,9 +7,8 @@
import {type AniSearchList, MediaListSort} from "./anilist/types/AniListTypes";
import type {AniListCurrentUserWatchList} from "./anilist/types/AniListCurrentUserWatchListType"
import Header from "./Header.svelte";
import {Button, Modal} from "flowbite-svelte";
import type {AniListGetSingleAnime} from "./anilist/types/AniListCurrentUserWatchListType.js";
import {GetAniListItem} from "../wailsjs/go/main/App";
import {Modal} from "flowbite-svelte";
import ChangeDataDialogue from "./ChangeDataDialogue.svelte";
let aniSearch = ""
@ -18,9 +18,8 @@
let aniListWatchlist: AniListCurrentUserWatchList
let page = 1
let perPage = 20
let anilistModal = false;
let anime: AniListGetSingleAnime
let title: string
const size = "xl"
function runAniListSearch(): void {
AniListSearch(aniSearch).then(result => {
@ -36,15 +35,7 @@
})
}
export function GetAniListSingleItemAndOpenModal(aniId: number): void {
GetAniListItem(aniId).then(result => {
anime = result
title = anime.data.MediaList.media.title.english === "" ?
anime.data.MediaList.media.title.romaji :
anime.data.MediaList.media.title.english
anilistModal = true
})
}
</script>
<Header />
@ -110,7 +101,7 @@
</div>
</div>
{/if}
<Modal title={title} bind:open={anilistModal} autoclose>
<ChangeDataDialogue anime={anime} />
<Modal title={$title} bind:open={$anilistModal} {size} autoclose>
<ChangeDataDialogue />
</Modal>
</main>

View File

@ -1,26 +1,34 @@
<script lang="ts">
import type {AniListGetSingleAnime} from "./anilist/types/AniListCurrentUserWatchListType";
import { anime } from "./GetAniListSingleItemAndOpenModal.svelte";
import {Button} from "flowbite-svelte";
export let anime: AniListGetSingleAnime
const title = anime.data.MediaList.media.title.english !== "" ?
anime.data.MediaList.media.title.english :
anime.data.MediaList.media.title.romaji
</script>
<div>
<div>
<div class="grid grid-rows-2 grid-cols-10 grid-flow-col gap-4">
<div class="row-span-2 col-span-2">
<img src={anime.data.MediaList.media.coverImage.large} alt="{title} Cover Image">
</div>
<div class="col-span-8">
<form class="flex flex-row">
<div>
<label for="countries" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Select your
country</label>
<select id="countries"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<form class="max-w-sm mx-auto">
<label for="countries" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Select your
country</label>
<select id="countries"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option>United States</option>
<option>Canada</option>
<option>France</option>
<option>Germany</option>
</select>
</form>
<option>United States</option>
<option>Canada</option>
<option>France</option>
<option>Germany</option>
</select>
</div>
</form>
</div>
</div>
<footer class="bg-white rounded-lg shadow m-4 dark:bg-gray-800">
<div class="w-full mx-auto max-w-screen-xl p-4 md:flex md:items-center md:justify-end">

View File

@ -0,0 +1,19 @@
<script lang="ts" context="module">
import {GetAniListItem} from "../wailsjs/go/main/App";
import type {AniListGetSingleAnime} from "./anilist/types/AniListCurrentUserWatchListType.js";
import {writable} from 'svelte/store'
export let anime: AniListGetSingleAnime
export let title = writable("")
export let anilistModal = writable(false);
export function GetAniListSingleItemAndOpenModal(aniId: number): void {
GetAniListItem(aniId).then(result => {
anime = result
title.set(anime.data.MediaList.media.title.english === "" ?
anime.data.MediaList.media.title.romaji :
anime.data.MediaList.media.title.english)
anilistModal.set(true)
})
}
</script>

View File

@ -1,19 +1,7 @@
<script lang="ts">
import logo from "./assets/images/AniTrackLogo.svg"
import type {AniSearchList} from "./anilist/types/AniListTypes.js";
import {AniListSearch} from "../wailsjs/go/main/App.js";
import Search from "./Search.svelte"
let aniSearch = ""
let aniListSearch: AniSearchList
let aniListSearchActive = false
function runAniListSearch(): void {
AniListSearch(aniSearch).then(result => {
aniListSearch = result
aniListSearchActive = true
})
}
</script>
<header class="mb-2">

141
frontend/src/Search.svelte Normal file
View File

@ -0,0 +1,141 @@
<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>