anitrack/frontend/src/App.svelte

158 lines
6.0 KiB
Svelte
Raw Normal View History

2024-07-09 10:16:53 -04:00
<script lang="ts">
2024-07-26 16:50:42 -04:00
import {anilistModal, GetAniListSingleItemAndOpenModal, title} from "./GetAniListSingleItemAndOpenModal.svelte";
import {
CheckIfAniListLoggedIn,
CheckIfSimklLoggedIn,
GetAniListLoggedInUser,
GetAniListUserWatchingList,
2024-07-31 19:33:04 -04:00
GetSimklLoggedInUser,
SimklGetUserWatchlist,
} from "../wailsjs/go/main/App";
import {type AniListUser, MediaListSort} from "./anilist/types/AniListTypes";
import type {AniListCurrentUserWatchList} from "./anilist/types/AniListCurrentUserWatchListType"
import Header from "./Header.svelte";
2024-07-31 19:33:04 -04:00
import {Button, Rating} from "flowbite-svelte";
import {default as Modal} from "./modal/Modal.svelte"
import ChangeDataDialogue from "./ChangeDataDialogue.svelte";
import {onMount} from "svelte";
import type {SimklUser, SimklWatchList} from "./simkl/types/simklTypes";
import {writable} from "svelte/store";
2024-07-27 21:17:30 -04:00
let aniListLoggedIn = false
let aniListPrimary = true
let simklUser: SimklUser
let simklLoggedIn = false
let aniListUser: AniListUser
let aniListWatchlist: AniListCurrentUserWatchList
export let simklWatchList = writable({} as SimklWatchList)
let page = 1
let perPage = 20
const size = "xl"
onMount(async () => {
await CheckIfAniListLoggedIn().then(result => {
if (result) {
GetAniListLoggedInUser().then(result => {
aniListUser = result
if (aniListPrimary) {
GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((result) => {
aniListWatchlist = result
aniListLoggedIn = true
})
} else {
aniListLoggedIn = result
}
})
}
})
await CheckIfSimklLoggedIn().then(result => {
if (result) {
GetSimklLoggedInUser().then(result => {
simklUser = result
SimklGetUserWatchlist().then(result => {
simklWatchList.set(result)
simklLoggedIn = result
})
})
}
})
})
function loginToSimkl(): void {
GetSimklLoggedInUser().then(result => {
simklUser = result
simklLoggedIn = true
})
}
function loginToAniList(): void {
GetAniListLoggedInUser().then(result => {
aniListUser = result
aniListLoggedIn = true
if (aniListPrimary) {
GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then(result => aniListWatchlist = result)
}
})
}
2024-07-31 19:33:04 -04:00
// function anilistGetUserWatchlist(): void {
// GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((result) => {
// aniListWatchlist = result
// aniListLoggedIn = true
// })
// }
//
// let count = 1;
//
// const decrement = () => {
// if (count > 0) {
// count--
// }
// }
//
// const increment = () => {
// count++
// }
2024-07-27 21:17:30 -04:00
2024-07-09 10:16:53 -04:00
</script>
2024-07-26 16:50:42 -04:00
<Header/>
2024-07-09 10:16:53 -04:00
<main>
{#if aniListLoggedIn}
<div>You are logged into AniList, {aniListWatchlist.data.Page.mediaList[0].user.name}!</div>
{:else}
<button class="btn" on:click={loginToAniList}>Login to AniList</button>
{/if}
{#if simklLoggedIn}
<div>You are logged into Simkl, {simklUser.user.name}</div>
{:else}
<Button class="btn" on:click={loginToSimkl}>Login to Simkl</Button>
{/if}
{#if aniListLoggedIn}
2024-07-31 19:33:04 -04:00
<div class="mx-auto max-w-2xl p-4 sm:p-6 lg:max-w-7xl lg:px-8">
<h1 class="text-left text-xl font-bold mb-4">Your Watching List</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 aniListWatchlist.data.Page.mediaList as media}
2024-07-26 16:50:42 -04:00
<div class="aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-lg xl:aspect-h-8 xl:aspect-w-7">
2024-07-31 19:33:04 -04:00
<div class="flex flex-col items-center group">
<button on:click={() => GetAniListSingleItemAndOpenModal(media.media.id, true)}>
2024-07-27 21:17:30 -04:00
<img class="rounded-lg" src={media.media.coverImage.large} alt={
2024-07-26 16:50:42 -04:00
media.media.title.english === "" ?
media.media.title.romaji :
media.media.title.english
2024-07-27 21:17:30 -04:00
}/>
2024-07-31 19:33:04 -04:00
</button>
<Rating id="anime-rating" total={5} size={35} rating={media.score/2.0} />
<button class="mt-4 text-md font-semibold text-white-700"
on:click={() => GetAniListSingleItemAndOpenModal(media.media.id, true)}>
{
2024-07-27 21:17:30 -04:00
media.media.title.english === "" ?
2024-07-31 19:33:04 -04:00
media.media.title.romaji :
media.media.title.english
}
</button>
<p class="mt-1 text-lg font-medium text-white-900">{media.progress}
/ {media.media.nextAiringEpisode.episode !== 0 ?
media.media.nextAiringEpisode.episode - 1 : media.media.episodes}</p>
{#if media.media.episodes > 0}
<p class="mt-1 text-lg font-medium text-white-900">Total
Episodes: {media.media.episodes}</p>
{/if}
</div>
2024-07-26 16:50:42 -04:00
</div>
{/each}
</div>
</div>
{/if}
2024-07-27 21:17:30 -04:00
<Modal title={$title} bind:open={$anilistModal} {size} autoclose={false}>
2024-07-26 16:50:42 -04:00
<ChangeDataDialogue/>
</Modal>
2024-07-09 10:16:53 -04:00
</main>