anitrack/frontend/src/App.svelte

124 lines
3.9 KiB
Svelte
Raw Normal View History

2024-07-09 10:16:53 -04:00
<script lang="ts">
import {
aniListLoggedIn,
aniListPrimary,
2024-08-11 21:13:22 -04:00
aniListUser,
aniListWatchlist,
2024-08-18 17:23:09 -04:00
animePerPage,
malLoggedIn,
malPrimary,
malUser,
malWatchList,
2024-08-11 21:13:22 -04:00
simklLoggedIn,
simklUser,
simklWatchList,
2024-08-13 19:36:39 -04:00
watchListPage,
2024-08-18 17:23:09 -04:00
simklPrimary,
aniListAnime,
GetAniListSingleItem,
} from "./helperComponents/GlobalVariablesAndHelperFunctions.svelte";
import {
CheckIfAniListLoggedIn,
2024-08-13 18:54:27 -04:00
CheckIfMyAnimeListLoggedIn,
2024-08-18 17:23:09 -04:00
CheckIfSimklLoggedIn,
GetAniListLoggedInUser,
GetAniListUserWatchingList,
2024-08-18 17:23:09 -04:00
GetMyAnimeList,
GetMyAnimeListLoggedInUser,
2024-07-31 19:33:04 -04:00
GetSimklLoggedInUser,
SimklGetUserWatchlist,
} from "../wailsjs/go/main/App";
2024-08-11 20:42:57 -04:00
import {MediaListSort} from "./anilist/types/AniListTypes";
import {onMount} from "svelte";
import Router from "svelte-spa-router"
import Home from "./routes/Home.svelte";
import {wrap} from "svelte-spa-router/wrap";
import Spinner from "./helperComponents/Spinner.svelte";
import Header from "./helperComponents/Header.svelte";
let isAniListPrimary: boolean
let isMalPrimary: boolean
2024-08-18 17:23:09 -04:00
let isSimklPrimary: boolean
aniListPrimary.subscribe((value) => isAniListPrimary = value)
malPrimary.subscribe((value) => isMalPrimary = value)
2024-08-18 17:23:09 -04:00
simklPrimary.subscribe(value => isSimklPrimary = value)
2024-08-13 19:36:39 -04:00
let page: number
let perPage: number
watchListPage.subscribe(value => page = value)
animePerPage.subscribe(value => perPage = value)
onMount(async () => {
2024-08-15 21:27:31 -04:00
await CheckIfAniListLoggedIn().then(loggedIn => {
if (loggedIn) {
GetAniListLoggedInUser().then(user => {
aniListUser.set(user)
if (isAniListPrimary) {
2024-08-15 21:27:31 -04:00
GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((watchList) => {
aniListWatchlist.set(watchList)
aniListLoggedIn.set(loggedIn)
})
} else {
2024-08-15 21:27:31 -04:00
aniListLoggedIn.set(loggedIn)
}
})
}
})
2024-08-15 21:27:31 -04:00
await CheckIfMyAnimeListLoggedIn().then(loggedIn => {
if (loggedIn) {
GetMyAnimeListLoggedInUser().then(user => {
malUser.set(user)
2024-08-18 17:23:09 -04:00
if (isMalPrimary) {
GetMyAnimeList(1000).then(watchList => {
malWatchList.set(watchList)
malLoggedIn.set(loggedIn)
})
} else {
2024-08-15 21:27:31 -04:00
malLoggedIn.set(loggedIn)
}
2024-08-13 18:54:27 -04:00
})
}
})
2024-08-15 21:27:31 -04:00
await CheckIfSimklLoggedIn().then(loggedIn => {
if (loggedIn) {
GetSimklLoggedInUser().then(user => {
2024-08-18 17:23:09 -04:00
if (Object.keys(user).length === 0) {
simklLoggedIn.set(false)
} else {
simklUser.set(user)
if(isSimklPrimary) {
SimklGetUserWatchlist().then(result => {
simklWatchList.set(result)
simklLoggedIn.set(loggedIn)
})
} else {
simklLoggedIn.set(loggedIn)
}
}
})
}
})
})
2024-07-09 10:16:53 -04:00
</script>
<Header />
<Router routes={{
'/': Home,
'/anime/:id': wrap({
2024-09-04 12:26:26 -04:00
asyncComponent: () => import('./routes/Anime.svelte'),
conditions: [
async (detail) => {
await GetAniListSingleItem(Number(detail.params.id), true)
return Object.keys($aniListAnime).length!==0
},
],
loadingComponent: Spinner
}),
// '*': "Not Found"
}} />