-
Your AniList WatchList
+
+
Your AniList WatchList
-
- {#each aniListWatchListLoaded.data.Page.mediaList as media}
-
-
-
+ {/each}
- {/if}
+
diff --git a/frontend/src/helperFunctions/userStore.ts b/frontend/src/helperFunctions/userStore.ts
new file mode 100644
index 0000000..41d6121
--- /dev/null
+++ b/frontend/src/helperFunctions/userStore.ts
@@ -0,0 +1,121 @@
+// stores/user.ts
+import {get, writable} from 'svelte/store';
+import type {SimklUser, SimklWatchList} from "../types/simklTypes";
+import type {AniListUser} from "../types/AniListTypes";
+import type {MALWatchlist, MyAnimeListUser} from "../types/MALTypes";
+import {
+ GetAniListLoggedInUser,
+ GetMyAnimeList,
+ GetMyAnimeListLoggedInUser,
+ GetSimklLoggedInUser,
+ LogoutAniList,
+ LogoutMyAnimeList,
+ LogoutSimkl,
+ SimklGetUserWatchlist
+} from "../../wailsjs/go/main/App";
+import {LoadAniListWatchList} from "../helperModules/LoadAniListWatchList.svelte";
+import {aniListWatchlist, malWatchList, simklWatchList} from "../helperModules/GlobalVariablesAndHelperFunctions.svelte"
+import type {AniListCurrentUserWatchList} from "../types/AniListCurrentUserWatchListType";
+import {AniListUserDefaultData, MALUserDefaultData, SimklUserDefaultData} from "../defaults/UserTypes";
+
+let aniWatchlist: AniListCurrentUserWatchList
+aniListWatchlist.subscribe(value => aniWatchlist = value)
+
+interface UserState {
+ simkl: { user: SimklUser; isLoggedIn: boolean; isPrimary: boolean };
+ anilist: { user: AniListUser; isLoggedIn: boolean; isPrimary: boolean };
+ mal: { user: MyAnimeListUser; isLoggedIn: boolean; isPrimary: boolean };
+}
+
+const createUserStore = () => {
+ const {subscribe, update} = writable
({
+ anilist: {user: AniListUserDefaultData, isLoggedIn: false, isPrimary: true},
+ mal: {user: MALUserDefaultData, isLoggedIn: false, isPrimary: false},
+ simkl: {user: SimklUserDefaultData, isLoggedIn: false, isPrimary: false}
+ });
+
+ return {
+ subscribe,
+ setAniListUser: (user: AniListUser, isPrimary = true) =>
+ update(s => ({
+ ...s,
+ anilist: {user, isLoggedIn: true, isPrimary}
+ })),
+ setMalUser: (user: MyAnimeListUser, isPrimary = false) =>
+ update(s => ({
+ ...s,
+ mal: {user, isLoggedIn: true, isPrimary}
+ })),
+ setSimklUser: (user: SimklUser, isPrimary = false) =>
+ update(s => ({
+ ...s,
+ simkl: {user, isLoggedIn: true, isPrimary}
+ })),
+ setPrimary: (provider: 'simkl' | 'anilist' | 'mal') =>
+ update(s => ({
+ ...s,
+ simkl: {...s.simkl, isPrimary: provider === 'simkl'},
+ anilist: {...s.anilist, isPrimary: provider === 'anilist'},
+ mal: {...s.mal, isPrimary: provider === 'mal'}
+ })),
+ checkProvider: async (provider: 'simkl' | 'anilist' | 'mal') => {
+ const state = get(userStore);
+ if (state[provider].isLoggedIn) return;
+
+ if (provider === 'anilist') {
+ const user: AniListUser = await GetAniListLoggedInUser();
+ console.log(user)
+ userStore.setAniListUser(user, state.anilist.isPrimary);
+ console.log(state.anilist.isPrimary)
+ if (state.anilist.isPrimary) await LoadAniListWatchList();
+ } else if (provider === 'mal') {
+ const user: MyAnimeListUser = await GetMyAnimeListLoggedInUser();
+ userStore.setMalUser(user, state.mal.isPrimary);
+ if (state.mal.isPrimary) {
+ const watchList = await GetMyAnimeList(1000);
+ malWatchList.set(watchList);
+ }
+ } else if (provider === 'simkl') {
+ const user: SimklUser = await GetSimklLoggedInUser();
+ userStore.setSimklUser(user, state.simkl.isPrimary);
+ if (state.simkl.isPrimary) {
+ const watchList = await SimklGetUserWatchlist();
+ simklWatchList.set(watchList)
+ }
+ }
+ },
+ logout: async (provider: 'simkl' | 'anilist' | 'mal') => {
+ update(s => {
+ s[provider].user = {} as SimklUser | AniListUser | MyAnimeListUser
+ s[provider].isLoggedIn = false;
+ if (s[provider].isPrimary) {
+ s[provider].isPrimary = false;
+ const others = ['simkl', 'anilist', 'mal'] as const;
+ const newPrimary = others.find(p => p !== provider && s[p].isLoggedIn);
+ if (newPrimary) s[newPrimary].isPrimary = true;
+ }
+ return s;
+ });
+
+ // Clear provider-specific watchlist
+ if (provider === 'anilist') {
+ if (Object.keys(aniWatchlist).length !== 0) {
+ aniListWatchlist.set({} as AniListCurrentUserWatchList)
+ }
+ await LogoutAniList();
+ } else if (provider === 'mal') {
+ if (Object.keys(aniWatchlist).length !== 0) {
+ malWatchList.set({} as MALWatchlist);
+ }
+ await LogoutMyAnimeList();
+ } else if (provider === 'simkl') {
+ if (Object.keys(aniWatchlist).length !== 0) {
+ simklWatchList.set({} as SimklWatchList);
+ }
+ await LogoutSimkl();
+ }
+ }
+ }
+};
+
+export const userStore = createUserStore();
\ No newline at end of file
diff --git a/frontend/src/helperModules/AddAnimeServiceToTable.svelte b/frontend/src/helperModules/AddAnimeServiceToTable.svelte
index 3e4e433..0a0756e 100644
--- a/frontend/src/helperModules/AddAnimeServiceToTable.svelte
+++ b/frontend/src/helperModules/AddAnimeServiceToTable.svelte
@@ -1,5 +1,5 @@
\ No newline at end of file
diff --git a/frontend/src/helperModules/CheckIfMyAnimeListLoggedIn.svelte b/frontend/src/helperModules/CheckIfMyAnimeListLoggedIn.svelte
deleted file mode 100644
index 8054578..0000000
--- a/frontend/src/helperModules/CheckIfMyAnimeListLoggedIn.svelte
+++ /dev/null
@@ -1,25 +0,0 @@
-
\ No newline at end of file
diff --git a/frontend/src/helperModules/CheckIsSimklLoggedIn.svelte b/frontend/src/helperModules/CheckIsSimklLoggedIn.svelte
deleted file mode 100644
index 706db11..0000000
--- a/frontend/src/helperModules/CheckIsSimklLoggedIn.svelte
+++ /dev/null
@@ -1,29 +0,0 @@
-
\ No newline at end of file
diff --git a/frontend/src/helperModules/GlobalVariablesAndHelperFunctions.svelte b/frontend/src/helperModules/GlobalVariablesAndHelperFunctions.svelte
index aedfe42..722efeb 100644
--- a/frontend/src/helperModules/GlobalVariablesAndHelperFunctions.svelte
+++ b/frontend/src/helperModules/GlobalVariablesAndHelperFunctions.svelte
@@ -1,41 +1,25 @@
\ No newline at end of file
diff --git a/frontend/src/helperModules/LoadAniListWatchList.svelte b/frontend/src/helperModules/LoadAniListWatchList.svelte
new file mode 100644
index 0000000..c05e73e
--- /dev/null
+++ b/frontend/src/helperModules/LoadAniListWatchList.svelte
@@ -0,0 +1,17 @@
+
\ No newline at end of file
diff --git a/frontend/src/routes/AnimeRoutePage.svelte b/frontend/src/routes/AnimeRoutePage.svelte
index 243ff9d..8650c76 100644
--- a/frontend/src/routes/AnimeRoutePage.svelte
+++ b/frontend/src/routes/AnimeRoutePage.svelte
@@ -1,7 +1,7 @@
-{#if isAniListLoggedIn && isAniListPrimary}
+{#if $userStore.anilist.isLoggedIn && $userStore.anilist.isPrimary}
diff --git a/frontend/src/anilist/types/AniListCurrentUserWatchListType.ts b/frontend/src/types/AniListCurrentUserWatchListType.ts
similarity index 100%
rename from frontend/src/anilist/types/AniListCurrentUserWatchListType.ts
rename to frontend/src/types/AniListCurrentUserWatchListType.ts
diff --git a/frontend/src/anilist/types/AniListTypes.ts b/frontend/src/types/AniListTypes.ts
similarity index 100%
rename from frontend/src/anilist/types/AniListTypes.ts
rename to frontend/src/types/AniListTypes.ts
diff --git a/frontend/src/mal/types/MALTypes.ts b/frontend/src/types/MALTypes.ts
similarity index 100%
rename from frontend/src/mal/types/MALTypes.ts
rename to frontend/src/types/MALTypes.ts
diff --git a/frontend/src/helperTypes/StatusTypes.ts b/frontend/src/types/StatusTypes.ts
similarity index 100%
rename from frontend/src/helperTypes/StatusTypes.ts
rename to frontend/src/types/StatusTypes.ts
diff --git a/frontend/src/helperTypes/TableTypes.ts b/frontend/src/types/TableTypes.ts
similarity index 100%
rename from frontend/src/helperTypes/TableTypes.ts
rename to frontend/src/types/TableTypes.ts
diff --git a/frontend/src/simkl/types/simklTypes.ts b/frontend/src/types/simklTypes.ts
similarity index 100%
rename from frontend/src/simkl/types/simklTypes.ts
rename to frontend/src/types/simklTypes.ts
diff --git a/wails.json b/wails.json
index d170dcf..ed7b7d1 100644
--- a/wails.json
+++ b/wails.json
@@ -12,6 +12,6 @@
},
"info": {
"productName": "AniTrack",
- "productVersion": "0.5.0"
+ "productVersion": "0.6.0"
}
}