- loader action used new Component() plus $destroy, both removed in Svelte 5 (component_api_invalid_new crashed every refresh click before the reload ran); rewritten on mount/unmount with a real action destroy for the leaked subscription - homecoming refresh moves off the legacy $: block, which never tracked the runes-backed router.location, onto the sanctioned onRouteLoaded callback with identical guard semantics; unused router import dropped so the check stays warning-free
80 lines
2.9 KiB
Svelte
80 lines
2.9 KiB
Svelte
<script lang="ts">
|
|
import {
|
|
aniListLoggedIn,
|
|
malLoggedIn,
|
|
simklLoggedIn,
|
|
watchlistNeedsRefresh,
|
|
aniListPrimary,
|
|
malPrimary,
|
|
simklPrimary,
|
|
malWatchList,
|
|
simklWatchList,
|
|
serviceLoggingIn,
|
|
} from "./helperModules/GlobalVariablesAndHelperFunctions.svelte";
|
|
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";
|
|
import { CheckIfAniListLoggedInAndLoadWatchList } from "./helperModules/CheckIfAniListLoggedInAndLoadWatchList.svelte";
|
|
import { CheckIfMALLoggedInAndSetUser } from "./helperModules/CheckIfMyAnimeListLoggedIn.svelte";
|
|
import { CheckIfSimklLoggedInAndSetUser } from "./helperModules/CheckIsSimklLoggedIn.svelte";
|
|
import {App} from "../bindings/AniTrack";
|
|
import ErrorModal from "./helperComponents/ErrorModal.svelte";
|
|
|
|
onMount(async () => {
|
|
let isAniListLoggedIn!: boolean;
|
|
let isMALLoggedIn!: boolean;
|
|
let isSimklLoggedIn!: boolean;
|
|
aniListLoggedIn.subscribe((value) => (isAniListLoggedIn = value));
|
|
malLoggedIn.subscribe((value) => (isMALLoggedIn = value));
|
|
simklLoggedIn.subscribe((value) => (isSimklLoggedIn = value));
|
|
|
|
serviceLoggingIn.set(["anilist", "mal", "simkl"]);
|
|
|
|
!isAniListLoggedIn && (await CheckIfAniListLoggedInAndLoadWatchList());
|
|
!isMALLoggedIn && (await CheckIfMALLoggedInAndSetUser());
|
|
!isSimklLoggedIn && (await CheckIfSimklLoggedInAndSetUser());
|
|
});
|
|
|
|
import { get } from "svelte/store";
|
|
|
|
// Reloads all watchlists when returning home with the refresh flag set
|
|
// (e.g. after saving changes on a detail page). Driven by the router's
|
|
// onRouteLoaded callback: the old `$: ... router.location ...` reactive
|
|
// statement did not reliably re-fire on navigation under Svelte 5,
|
|
// so homecoming refreshes silently never ran.
|
|
async function refreshHomeWatchlists(location: string): Promise<void> {
|
|
if (location !== "/" || !get(watchlistNeedsRefresh)) return;
|
|
if (get(aniListLoggedIn) && get(aniListPrimary)) {
|
|
await CheckIfAniListLoggedInAndLoadWatchList();
|
|
}
|
|
if (get(malLoggedIn) && get(malPrimary)) {
|
|
await App.GetMyAnimeList(1000).then((w) => malWatchList.set(w));
|
|
}
|
|
if (get(simklLoggedIn) && get(simklPrimary)) {
|
|
await App.SimklGetUserWatchlist().then((w) => simklWatchList.set(w));
|
|
}
|
|
|
|
watchlistNeedsRefresh.set(false);
|
|
}
|
|
</script>
|
|
|
|
<Header />
|
|
<ErrorModal />
|
|
<Router
|
|
onRouteLoaded={(detail) => {
|
|
void refreshHomeWatchlists(detail.location);
|
|
}}
|
|
routes={{
|
|
"/": Home,
|
|
"/anime/:id": wrap({
|
|
asyncComponent: () => import("./routes/AnimeRoutePage.svelte"),
|
|
conditions: [async () => await App.CheckIfAniListLoggedIn()],
|
|
loadingComponent: Spinner,
|
|
}),
|
|
// '*': "Not Found"
|
|
}}
|
|
/>
|