When the app starts it verifies all three services sequentially, which could leave the other two login controls looking idle or trigger login actions before their real state is known. Track which service is currently being checked and reflect it in the header: - Add a serviceLoggingIn store (plus setServiceLoggingIn and isServiceLoggingIn helpers) to GlobalVariablesAndHelperFunctions. - Have the loginTo* functions and the startup CheckIf* functions toggle their service in the store (seed all three at startup, clear each as it resolves). - In Header, the login buttons show a spinner with 'Checking AniList' / 'Checking MAL' / 'Checking Simkl' and are disabled while that service is being checked, reverting to the normal 'AniList Login' style label once its state is known. - In the avatar menu, the 'Login to X' row shows a spinner with the matching 'Checking X' text while that service is logging in.
86 lines
2.3 KiB
Svelte
86 lines
2.3 KiB
Svelte
<script lang="ts" context="module">
|
|
import {
|
|
CheckIfAniListLoggedIn,
|
|
GetAniListLoggedInUser,
|
|
GetAniListUserWatchingList,
|
|
} from "../../wailsjs/go/main/App";
|
|
import {
|
|
aniListUser,
|
|
watchListPage,
|
|
animePerPage,
|
|
aniListPrimary,
|
|
aniListLoggedIn,
|
|
aniListWatchlist,
|
|
aniListSort,
|
|
clearApiError,
|
|
setApiError,
|
|
serviceLoggingIn,
|
|
} from "./GlobalVariablesAndHelperFunctions.svelte";
|
|
|
|
let isAniListPrimary: boolean;
|
|
let page: number;
|
|
let perPage: number;
|
|
let sort: string;
|
|
|
|
aniListPrimary.subscribe((value) => (isAniListPrimary = value));
|
|
watchListPage.subscribe((value) => (page = value));
|
|
animePerPage.subscribe((value) => (perPage = value));
|
|
aniListSort.subscribe((value) => (sort = value));
|
|
|
|
export const LoadAniListUser = async () => {
|
|
try {
|
|
await GetAniListLoggedInUser().then((user) => {
|
|
aniListUser.set(user);
|
|
});
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
setApiError(
|
|
"anilist",
|
|
`Failed to load user: ${errorMsg}`,
|
|
undefined,
|
|
true,
|
|
);
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
export const LoadAniListWatchList = async () => {
|
|
try {
|
|
const watchList = await GetAniListUserWatchingList(page, perPage, sort);
|
|
aniListWatchlist.set(watchList);
|
|
clearApiError();
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
setApiError(
|
|
"anilist",
|
|
`Failed to load watch list: ${errorMsg}`,
|
|
undefined,
|
|
true,
|
|
);
|
|
throw err;
|
|
}
|
|
};
|
|
export const CheckIfAniListLoggedInAndLoadWatchList = async () => {
|
|
serviceLoggingIn.update((s) => [...s, "anilist"]);
|
|
try {
|
|
const loggedIn = await CheckIfAniListLoggedIn();
|
|
if (loggedIn) {
|
|
await LoadAniListUser();
|
|
if (isAniListPrimary) await LoadAniListWatchList();
|
|
}
|
|
aniListLoggedIn.set(loggedIn);
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
setApiError(
|
|
"anilist",
|
|
`Authentication failed: ${errorMsg}`,
|
|
undefined,
|
|
true,
|
|
);
|
|
aniListLoggedIn.set(false);
|
|
} finally {
|
|
serviceLoggingIn.update((s) => s.filter((item) => item !== "anilist"));
|
|
}
|
|
};
|
|
</script>
|