Fixed components to reload watchlist
This commit is contained in:
		@@ -1,108 +1,23 @@
 | 
			
		||||
<script lang="ts">
 | 
			
		||||
    import {
 | 
			
		||||
        aniListLoggedIn,
 | 
			
		||||
        aniListPrimary,
 | 
			
		||||
        aniListUser,
 | 
			
		||||
        aniListWatchlist,
 | 
			
		||||
        animePerPage,
 | 
			
		||||
        malLoggedIn,
 | 
			
		||||
        malPrimary,
 | 
			
		||||
        malUser,
 | 
			
		||||
        malWatchList,
 | 
			
		||||
        simklLoggedIn,
 | 
			
		||||
        simklUser,
 | 
			
		||||
        simklWatchList,
 | 
			
		||||
        watchListPage,
 | 
			
		||||
        simklPrimary,
 | 
			
		||||
        aniListAnime,
 | 
			
		||||
        GetAniListSingleItem,
 | 
			
		||||
    } from "./helperComponents/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
    import {
 | 
			
		||||
        CheckIfAniListLoggedIn,
 | 
			
		||||
        CheckIfMyAnimeListLoggedIn,
 | 
			
		||||
        CheckIfSimklLoggedIn,
 | 
			
		||||
        GetAniListLoggedInUser,
 | 
			
		||||
        GetAniListUserWatchingList,
 | 
			
		||||
        GetMyAnimeList,
 | 
			
		||||
        GetMyAnimeListLoggedInUser,
 | 
			
		||||
        GetSimklLoggedInUser,
 | 
			
		||||
        SimklGetUserWatchlist,
 | 
			
		||||
    } from "../wailsjs/go/main/App";
 | 
			
		||||
    import {MediaListSort} from "./anilist/types/AniListTypes";
 | 
			
		||||
    } 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";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    let isAniListPrimary: boolean
 | 
			
		||||
    let isMalPrimary: boolean
 | 
			
		||||
    let isSimklPrimary: boolean
 | 
			
		||||
 | 
			
		||||
    aniListPrimary.subscribe((value) => isAniListPrimary = value)
 | 
			
		||||
    malPrimary.subscribe((value) => isMalPrimary = value)
 | 
			
		||||
    simklPrimary.subscribe(value => isSimklPrimary = value)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    let page: number
 | 
			
		||||
    let perPage: number
 | 
			
		||||
    watchListPage.subscribe(value => page = value)
 | 
			
		||||
    animePerPage.subscribe(value => perPage = value)
 | 
			
		||||
    import {CheckIfAniListLoggedInAndLoadWatchList} from "./helperModules/CheckIfAniListLoggedInAndLoadWatchList.svelte";
 | 
			
		||||
    import { CheckIfMALLoggedInAndSetUser } from "./helperModules/CheckIfMyAnimeListLoggedIn.svelte";
 | 
			
		||||
    import {CheckIfSimklLoggedInAndSetUser} from "./helperModules/CheckIsSimklLoggedIn.svelte"
 | 
			
		||||
 | 
			
		||||
    onMount(async () => {
 | 
			
		||||
        await CheckIfAniListLoggedIn().then(loggedIn => {
 | 
			
		||||
            if (loggedIn) {
 | 
			
		||||
                GetAniListLoggedInUser().then(user => {
 | 
			
		||||
                    aniListUser.set(user)
 | 
			
		||||
                    if (isAniListPrimary) {
 | 
			
		||||
                        GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((watchList) => {
 | 
			
		||||
                            aniListWatchlist.set(watchList)
 | 
			
		||||
                            aniListLoggedIn.set(loggedIn)
 | 
			
		||||
                        })
 | 
			
		||||
                    } else {
 | 
			
		||||
                        aniListLoggedIn.set(loggedIn)
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        await CheckIfMyAnimeListLoggedIn().then(loggedIn => {
 | 
			
		||||
            if (loggedIn) {
 | 
			
		||||
                GetMyAnimeListLoggedInUser().then(user => {
 | 
			
		||||
                    malUser.set(user)
 | 
			
		||||
                    if (isMalPrimary) {
 | 
			
		||||
                        GetMyAnimeList(1000).then(watchList => {
 | 
			
		||||
                            malWatchList.set(watchList)
 | 
			
		||||
                            malLoggedIn.set(loggedIn)
 | 
			
		||||
                        })
 | 
			
		||||
                    } else {
 | 
			
		||||
                        malLoggedIn.set(loggedIn)
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
        await CheckIfSimklLoggedIn().then(loggedIn => {
 | 
			
		||||
            if (loggedIn) {
 | 
			
		||||
                GetSimklLoggedInUser().then(user => {
 | 
			
		||||
                    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)
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
        await CheckIfAniListLoggedInAndLoadWatchList()
 | 
			
		||||
        await CheckIfMALLoggedInAndSetUser()
 | 
			
		||||
        await CheckIfSimklLoggedInAndSetUser()
 | 
			
		||||
    })
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
    import {createTable, Render, Subscribe} from "svelte-headless-table";
 | 
			
		||||
    // @ts-ignore
 | 
			
		||||
    import { addSortBy } from "svelte-headless-table/plugins";
 | 
			
		||||
    import {tableItems} from "./GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
    import {tableItems} from "../helperModules/GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
 | 
			
		||||
    //when adding sort here is code { sort: addSortBy() }
 | 
			
		||||
    const table = createTable(tableItems, { sort: addSortBy() })
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
    import {Avatar} from "flowbite-svelte";
 | 
			
		||||
    import type {AniListUser} from "../anilist/types/AniListTypes";
 | 
			
		||||
    import {aniListLoggedIn, aniListUser, malLoggedIn, simklLoggedIn, logoutOfAniList, logoutOfMAL, logoutOfSimkl} from "./GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
    import {aniListLoggedIn, aniListUser, malLoggedIn, simklLoggedIn, logoutOfAniList, logoutOfMAL, logoutOfSimkl} from "../helperModules/GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
    import * as runtime from "../../wailsjs/runtime";
 | 
			
		||||
 | 
			
		||||
    let currentAniListUser: AniListUser
 | 
			
		||||
 
 | 
			
		||||
@@ -10,13 +10,14 @@
 | 
			
		||||
        malUser,
 | 
			
		||||
        simklLoggedIn,
 | 
			
		||||
        simklUser,
 | 
			
		||||
    } from "./GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
    } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
    import type {AniListUser} from "../anilist/types/AniListTypes";
 | 
			
		||||
    import type {SimklUser} from "../simkl/types/simklTypes";
 | 
			
		||||
    import type {MyAnimeListUser} from "../mal/types/MALTypes";
 | 
			
		||||
    import AvatarMenu from "./AvatarMenu.svelte";
 | 
			
		||||
    import logo from "../assets/images/AniTrackLogo.svg"
 | 
			
		||||
    import {location, pop} from "svelte-spa-router";
 | 
			
		||||
    import {CheckIfAniListLoggedInAndLoadWatchList} from "../helperModules/CheckIfAniListLoggedInAndLoadWatchList.svelte";
 | 
			
		||||
 | 
			
		||||
    let isAniListLoggedIn: boolean
 | 
			
		||||
    let isSimklLoggedIn: boolean
 | 
			
		||||
@@ -42,7 +43,10 @@
 | 
			
		||||
            {#if currentLocation === "/"}
 | 
			
		||||
                <a href="/"><img src={logo} class="h-8" alt="AniTrack Logo"/></a>
 | 
			
		||||
            {:else}
 | 
			
		||||
                <button on:click={() => pop()}><img src={logo} class="h-8" alt="AniTrack Logo"/></button>
 | 
			
		||||
                <button on:click={async () => {
 | 
			
		||||
                    await CheckIfAniListLoggedInAndLoadWatchList()
 | 
			
		||||
                    return pop()
 | 
			
		||||
                }}><img src={logo} class="h-8" alt="AniTrack Logo"/></button>
 | 
			
		||||
            {/if}
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="flex items-center min-[950px]:order-2 space-x-3 min-[950px]:space-x-0 rtl:space-x-reverse">
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@
 | 
			
		||||
        aniListWatchlist,
 | 
			
		||||
        animePerPage,
 | 
			
		||||
        watchListPage,
 | 
			
		||||
    } from "./GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
    } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
 | 
			
		||||
    import type {AniListCurrentUserWatchList} from "../anilist/types/AniListCurrentUserWatchListType"
 | 
			
		||||
    import {GetAniListUserWatchingList} from "../../wailsjs/go/main/App";
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@
 | 
			
		||||
        aniListWatchlist,
 | 
			
		||||
        GetAniListSingleItem,
 | 
			
		||||
        loading,
 | 
			
		||||
    } from "./GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
    } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
    import {push} from "svelte-spa-router";
 | 
			
		||||
    import type {AniListCurrentUserWatchList} from "../anilist/types/AniListCurrentUserWatchListType"
 | 
			
		||||
    import {Rating} from "flowbite-svelte";
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,31 @@
 | 
			
		||||
<script lang="ts" context="module">
 | 
			
		||||
    import {CheckIfAniListLoggedIn, GetAniListLoggedInUser, GetAniListUserWatchingList} from "../../wailsjs/go/main/App";
 | 
			
		||||
    import {MediaListSort} from "../anilist/types/AniListTypes";
 | 
			
		||||
    import { aniListUser, watchListPage, animePerPage, aniListPrimary, aniListLoggedIn, aniListWatchlist } from "./GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
 | 
			
		||||
    let isAniListPrimary: boolean
 | 
			
		||||
    let page: number
 | 
			
		||||
    let perPage: number
 | 
			
		||||
 | 
			
		||||
    aniListPrimary.subscribe(value => isAniListPrimary = value)
 | 
			
		||||
    watchListPage.subscribe(value => page = value)
 | 
			
		||||
    animePerPage.subscribe(value => perPage = value)
 | 
			
		||||
 | 
			
		||||
    export const CheckIfAniListLoggedInAndLoadWatchList = async () => {
 | 
			
		||||
        await CheckIfAniListLoggedIn().then(loggedIn => {
 | 
			
		||||
            if (loggedIn) {
 | 
			
		||||
                GetAniListLoggedInUser().then(user => {
 | 
			
		||||
                    aniListUser.set(user)
 | 
			
		||||
                    if (isAniListPrimary) {
 | 
			
		||||
                        GetAniListUserWatchingList(page, perPage, MediaListSort.UpdatedTimeDesc).then((watchList) => {
 | 
			
		||||
                            aniListWatchlist.set(watchList)
 | 
			
		||||
                            aniListLoggedIn.set(loggedIn)
 | 
			
		||||
                        })
 | 
			
		||||
                    } else {
 | 
			
		||||
                        aniListLoggedIn.set(loggedIn)
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
</script>
 | 
			
		||||
							
								
								
									
										25
									
								
								frontend/src/helperModules/CheckIfMyAnimeListLoggedIn.svelte
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								frontend/src/helperModules/CheckIfMyAnimeListLoggedIn.svelte
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
<script lang="ts" context="module">
 | 
			
		||||
    import {CheckIfMyAnimeListLoggedIn, GetMyAnimeList, GetMyAnimeListLoggedInUser} from "../../wailsjs/go/main/App";
 | 
			
		||||
    import {malUser, malPrimary, malWatchList, malLoggedIn} from "./GlobalVariablesAndHelperFunctions.svelte"
 | 
			
		||||
 | 
			
		||||
    let isMalPrimary: boolean
 | 
			
		||||
    malPrimary.subscribe(value => isMalPrimary = value)
 | 
			
		||||
 | 
			
		||||
    export const CheckIfMALLoggedInAndSetUser = async () => {
 | 
			
		||||
        await CheckIfMyAnimeListLoggedIn().then(loggedIn => {
 | 
			
		||||
            if (loggedIn) {
 | 
			
		||||
                GetMyAnimeListLoggedInUser().then(user => {
 | 
			
		||||
                    malUser.set(user)
 | 
			
		||||
                    if (isMalPrimary) {
 | 
			
		||||
                        GetMyAnimeList(1000).then(watchList => {
 | 
			
		||||
                            malWatchList.set(watchList)
 | 
			
		||||
                            malLoggedIn.set(loggedIn)
 | 
			
		||||
                        })
 | 
			
		||||
                    } else {
 | 
			
		||||
                        malLoggedIn.set(loggedIn)
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
</script>
 | 
			
		||||
							
								
								
									
										29
									
								
								frontend/src/helperModules/CheckIsSimklLoggedIn.svelte
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								frontend/src/helperModules/CheckIsSimklLoggedIn.svelte
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
<script lang="ts" context="module">
 | 
			
		||||
    import {CheckIfSimklLoggedIn, GetSimklLoggedInUser, SimklGetUserWatchlist} from "../../wailsjs/go/main/App";
 | 
			
		||||
    import { simklLoggedIn, simklUser, simklPrimary, simklWatchList } from "./GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
 | 
			
		||||
    let isSimklPrimary: boolean
 | 
			
		||||
    simklPrimary.subscribe(value => isSimklPrimary = value)
 | 
			
		||||
 | 
			
		||||
    export const CheckIfSimklLoggedInAndSetUser = async () => {
 | 
			
		||||
        await CheckIfSimklLoggedIn().then(loggedIn => {
 | 
			
		||||
            if (loggedIn) {
 | 
			
		||||
                GetSimklLoggedInUser().then(user => {
 | 
			
		||||
                    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)
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        })
 | 
			
		||||
    }
 | 
			
		||||
</script>
 | 
			
		||||
@@ -6,7 +6,7 @@
 | 
			
		||||
        malLoggedIn,
 | 
			
		||||
        simklAnime,
 | 
			
		||||
        simklLoggedIn,
 | 
			
		||||
    } from "../helperComponents/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
    } from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
    import {pop} from "svelte-spa-router";
 | 
			
		||||
    import {Button} from "flowbite-svelte";
 | 
			
		||||
    import type {AniListGetSingleAnime} from "../anilist/types/AniListCurrentUserWatchListType";
 | 
			
		||||
@@ -26,7 +26,8 @@
 | 
			
		||||
        SimklSyncRating,
 | 
			
		||||
        SimklSyncStatus
 | 
			
		||||
    } from "../../wailsjs/go/main/App";
 | 
			
		||||
    import {AddAnimeServiceToTable} from "../helperComponents/AddAnimeServiceToTable.svelte";
 | 
			
		||||
    import {AddAnimeServiceToTable} from "../helperModules/AddAnimeServiceToTable.svelte";
 | 
			
		||||
    import {CheckIfAniListLoggedInAndLoadWatchList} from "../helperModules/CheckIfAniListLoggedInAndLoadWatchList.svelte";
 | 
			
		||||
 | 
			
		||||
    let isAniListLoggedIn: boolean
 | 
			
		||||
    let isMalLoggedIn: boolean
 | 
			
		||||
@@ -434,7 +435,10 @@
 | 
			
		||||
                    class="text-gray-900 bg-white border border-gray-300 focus:outline-none hover:bg-gray-100 focus:ring-4
 | 
			
		||||
                    focus:ring-gray-100 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:text-white
 | 
			
		||||
                    dark:border-gray-600 dark:hover:bg-gray-700 dark:hover:border-gray-600 dark:focus:ring-gray-700"
 | 
			
		||||
                    on:click={() => pop()}>
 | 
			
		||||
                    on:click={async () => {
 | 
			
		||||
                        await CheckIfAniListLoggedInAndLoadWatchList()
 | 
			
		||||
                        return pop()
 | 
			
		||||
                    }}>
 | 
			
		||||
                Back
 | 
			
		||||
            </Button>
 | 
			
		||||
        </div>
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ import {
 | 
			
		||||
    aniListLoggedIn,
 | 
			
		||||
    aniListPrimary,
 | 
			
		||||
    loading,
 | 
			
		||||
} from "../helperComponents/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
} from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
 | 
			
		||||
import loader from '../helperFunctions/loader'
 | 
			
		||||
 | 
			
		||||
let isAniListPrimary: boolean
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user