diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index d9015ba..2503c21 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -1,42 +1,27 @@ -
- import('./routes/AnimeRoutePage.svelte'), - conditions: [async () => await CheckIfAniListLoggedIn()], - loadingComponent: Spinner - }), - // '*': "Not Found" -}} /> +{#if $userStore.anilist.isLoggedIn} +
+ import('./routes/AnimeRoutePage.svelte'), + loadingComponent: Spinner + }), + // '*': "Not Found" + }} /> +{/if} diff --git a/frontend/src/helperDefaults/AniListGetSingleAnime.ts b/frontend/src/defaults/AniListGetSingleAnime.ts similarity index 77% rename from frontend/src/helperDefaults/AniListGetSingleAnime.ts rename to frontend/src/defaults/AniListGetSingleAnime.ts index 5fd955d..967719b 100644 --- a/frontend/src/helperDefaults/AniListGetSingleAnime.ts +++ b/frontend/src/defaults/AniListGetSingleAnime.ts @@ -1,6 +1,6 @@ -import type {AniListGetSingleAnime} from "../anilist/types/AniListCurrentUserWatchListType"; +import type {AniListGetSingleAnime} from "../types/AniListCurrentUserWatchListType"; -export const AniListGetSingleAnimeDefaultData: AniListGetSingleAnime = { +export const AniListGetSingleAnimeDefaultData: AniListGetSingleAnime = { data: { MediaList: { id: 0, @@ -26,7 +26,18 @@ export const AniListGetSingleAnimeDefaultData: AniListGetSingleAnime = { airingAt: 0, timeUntilAiring: 0, episode: 0, - } + }, + tags: [ + { + id: 0, + name: "", + description: "", + rank: 0, + isMediaSpoiler: false, + isAdult: false + } + ], + isAdult: false }, status: "", startedAt: { diff --git a/frontend/src/defaults/AniListWatchListDefaultData.ts b/frontend/src/defaults/AniListWatchListDefaultData.ts new file mode 100644 index 0000000..d743b28 --- /dev/null +++ b/frontend/src/defaults/AniListWatchListDefaultData.ts @@ -0,0 +1,89 @@ +import type {AniListCurrentUserWatchList} from "../types/AniListCurrentUserWatchListType" + +export const AniListWatchListDefaultData: AniListCurrentUserWatchList = { + data: { + Page: { + pageInfo: { + total: 0, + perPage: 0, + currentPage: 0, + lastPage: 0, + hasNextPage: false + }, + mediaList: [ + { + id: 0, + mediaId: 0, + userId: 0, + media: { + id: 0, + idMal: 0, + title: { + romaji: "", + english: "", + native: "", + }, + description: "", + coverImage: { + large: "", + }, + season: "", + seasonYear: 0, + status: "", + episodes: 0, + nextAiringEpisode: { + airingAt: 0, + timeUntilAiring: 0, + episode: 0, + }, + tags: [ + { + id: 0, + name: "", + description: "", + rank: 0, + isMediaSpoiler: false, + isAdult: false, + }, + ], + isAdult: false, + }, + status: "", + startedAt: { + year: 0, + month: 0, + day: 0, + }, + completedAt: { + year: 0, + month: 0, + day: 0, + }, + notes: "", + progress: 0, + score: 0, + repeat: 0, + user: { + id: 0, + name: "", + avatar: { + large: "", + medium: "", + }, + statistics: { + anime: { + count: 0, + statuses: [ + { + status: "", + count: 0, + } + ] + } + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/frontend/src/defaults/UserTypes.ts b/frontend/src/defaults/UserTypes.ts new file mode 100644 index 0000000..3ea1098 --- /dev/null +++ b/frontend/src/defaults/UserTypes.ts @@ -0,0 +1,67 @@ +import type {AniListUser} from "../types/AniListTypes"; +import type {MyAnimeListUser} from "../types/MALTypes"; +import type {SimklUser} from "../types/simklTypes"; + +export const AniListUserDefaultData: AniListUser = { + "data": { + "Viewer": { + id: 0, + name: "", + avatar: { + large: "", + medium: "", + }, + bannerImage: "", + siteUrl: "" + } + } +} + +export const MALUserDefaultData: MyAnimeListUser = { + id: 0, + name: "", + picture: "", + gender: "", + birthday: "", + location: "", + joinedAt: "", + AnimeStatistics: { + numItemsWatching: 0, + numItemsCompleted: 0, + numItemsOnHold: 0, + numItemsDropped: 0, + numItemsPlanToWatch: 0, + numItems: 0, + numDaysWatched: 0, + numDaysWatching: 0, + numDaysCompleted: 0, + numDaysOnHold: 0, + numDaysDropped: 0, + numDays: 0, + numEpisodes: 0, + numTimesRewatched: 0, + meanScore: 0 + }, + timeZone: "", + isSupporter: false +} + +export const SimklUserDefaultData: SimklUser = { + user: { + name: "", + joined_at: "", + gender: "", + avatar: "", + bio: "", + loc: "", + age: "", + }, + account: { + id: 0, + timezone: "", + type: "", + }, + connections: { + facebook: false + } +} \ No newline at end of file diff --git a/frontend/src/helperComponents/Anime.svelte b/frontend/src/helperComponents/Anime.svelte index 44523fb..1679779 100644 --- a/frontend/src/helperComponents/Anime.svelte +++ b/frontend/src/helperComponents/Anime.svelte @@ -1,14 +1,12 @@
@@ -517,20 +516,9 @@ {max} id="episodes" class="border border-x-0 p-2.5 h-11 text-center text-sm block w-full placeholder-gray-400 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none - {currentAniListAnime.data.MediaList.progress < 0 || - (currentAniListAnime.data.MediaList.media.episodes > - 0 && - currentAniListAnime.data.MediaList.progress > - currentAniListAnime.data.MediaList.media - .episodes) || - (currentAniListAnime.data.MediaList.media - .nextAiringEpisode.episode > 0 && - currentAniListAnime.data.MediaList.progress > - currentAniListAnime.data.MediaList.media - .nextAiringEpisode.episode - - 1) + {validProgress ? 'border-red-500 border-[2px] text-rose-300 focus:ring-red-500 focus:border-red-500' - : 'bg-gray-700 hover:bg-gray-600 border-gray-600 text-white focus:ring-blue-500 focus:border-blue-500'} w-24" + : 'bg-gray-700 hover:bg-gray-600 border-gray-600 text-white focus:ring-blue-500 focus:border-blue-500'}" bind:value={ currentAniListAnime.data.MediaList.progress } @@ -667,7 +655,7 @@ class="border {currentAniListAnime.data.MediaList .repeat < 0 ? 'border-red-500 border-[2px] text-rose-300 focus:ring-red-500 focus:border-red-500' - : 'border-gray-500 text-white focus:ring-blue-500 focus:border-blue-500'} text-sm rounded-lg block w-24 p-2.5 bg-gray-600 placeholder-gray-400 text-white" + : 'border-gray-500 focus:ring-blue-500 focus:border-blue-500'} text-sm rounded-lg block w-24 p-2.5 bg-gray-600 placeholder-gray-400 text-white" bind:value={currentAniListAnime.data.MediaList.repeat} required /> @@ -701,9 +689,9 @@ {:else}
  • {/if} - {#if isMALLoggedIn} + {#if $userStore.mal.isLoggedIn}
  • {:else}
  • {/if} - {#if isSimklLoggedIn} + {#if $userStore.simkl.isLoggedIn}
  • {:else}
  • {/if} - {#if !isMALLoggedIn} - {/if}
  • - {#if !isSimklLoggedIn} - diff --git a/frontend/src/helperComponents/Pagination.svelte b/frontend/src/helperComponents/Pagination.svelte index 72b0946..ee14322 100644 --- a/frontend/src/helperComponents/Pagination.svelte +++ b/frontend/src/helperComponents/Pagination.svelte @@ -6,9 +6,9 @@ watchListPage, } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte"; - import type {AniListCurrentUserWatchList} from "../anilist/types/AniListCurrentUserWatchListType" + import type {AniListCurrentUserWatchList} from "../types/AniListCurrentUserWatchListType" import {GetAniListUserWatchingList} from "../../wailsjs/go/main/App"; - import {MediaListSort} from "../anilist/types/AniListTypes"; + import {MediaListSort} from "../types/AniListTypes"; let aniListWatchListLoaded: AniListCurrentUserWatchList let page: number diff --git a/frontend/src/helperComponents/Search.svelte b/frontend/src/helperComponents/Search.svelte index 5a7c4f6..6f1fe09 100644 --- a/frontend/src/helperComponents/Search.svelte +++ b/frontend/src/helperComponents/Search.svelte @@ -1,7 +1,7 @@
    - {#if isAniListLoggedIn} -
    -

    Your AniList WatchList

    +
    +

    Your AniList WatchList

    -
    - {#each aniListWatchListLoaded.data.Page.mediaList as media} -
    -
    - - - -

    {media.progress} - / {media.media.nextAiringEpisode.episode !== 0 ? - media.media.nextAiringEpisode.episode - 1 : media.media.episodes}

    - {#if media.media.episodes > 0} -

    Total - Episodes: {media.media.episodes}

    - {/if} -
    + + + +

    {media.progress} + / {media.media.nextAiringEpisode.episode !== 0 ? + media.media.nextAiringEpisode.episode - 1 : media.media.episodes}

    + {#if media.media.episodes > 0} +

    Total + Episodes: {media.media.episodes}

    + {/if}
    - {/each} -
    +
    + {/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" } }