Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1090f112f3 |
@@ -1,163 +1,177 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Avatar } from "flowbite-svelte";
|
import { Avatar } from "flowbite-svelte";
|
||||||
import type { AniListUser } from "../anilist/types/AniListTypes";
|
import type { AniListUser } from "../anilist/types/AniListTypes";
|
||||||
import {
|
import {
|
||||||
aniListLoggedIn,
|
aniListLoggedIn,
|
||||||
aniListUser,
|
aniListUser,
|
||||||
malUser,
|
malUser,
|
||||||
simklUser,
|
simklUser,
|
||||||
malLoggedIn,
|
malLoggedIn,
|
||||||
simklLoggedIn,
|
simklLoggedIn,
|
||||||
loginToAniList,
|
loginToAniList,
|
||||||
loginToMAL,
|
loginToMAL,
|
||||||
loginToSimkl,
|
loginToSimkl,
|
||||||
logoutOfAniList,
|
logoutOfAniList,
|
||||||
logoutOfMAL,
|
logoutOfMAL,
|
||||||
logoutOfSimkl
|
logoutOfSimkl,
|
||||||
} from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
|
} from "../helperModules/GlobalVariablesAndHelperFunctions.svelte";
|
||||||
import * as runtime from "../../wailsjs/runtime";
|
import * as runtime from "../../wailsjs/runtime";
|
||||||
import type {MyAnimeListUser} from "../mal/types/MALTypes";
|
import type { MyAnimeListUser } from "../mal/types/MALTypes";
|
||||||
import type {SimklUser} from "../simkl/types/simklTypes";
|
import type { SimklUser } from "../simkl/types/simklTypes";
|
||||||
import { ShowVersion } from "../../wailsjs/go/main/App";
|
import { ShowVersion } from "../../wailsjs/go/main/App";
|
||||||
|
|
||||||
let currentAniListUser: AniListUser;
|
let currentAniListUser: AniListUser;
|
||||||
let currentMALUser: MyAnimeListUser;
|
let currentMALUser: MyAnimeListUser;
|
||||||
let currentSimklUser: SimklUser;
|
let currentSimklUser: SimklUser;
|
||||||
let isAniListLoggedIn: boolean;
|
let isAniListLoggedIn: boolean;
|
||||||
let isSimklLoggedIn: boolean;
|
let isSimklLoggedIn: boolean;
|
||||||
let isMALLoggedIn: boolean;
|
let isMALLoggedIn: boolean;
|
||||||
|
|
||||||
aniListUser.subscribe((value) => (currentAniListUser = value));
|
aniListUser.subscribe((value) => (currentAniListUser = value));
|
||||||
malUser.subscribe((value) => (currentMALUser = value))
|
malUser.subscribe((value) => (currentMALUser = value));
|
||||||
simklUser.subscribe(value => currentSimklUser = value)
|
simklUser.subscribe((value) => (currentSimklUser = value));
|
||||||
aniListLoggedIn.subscribe((value) => (isAniListLoggedIn = value));
|
aniListLoggedIn.subscribe((value) => (isAniListLoggedIn = value));
|
||||||
simklLoggedIn.subscribe((value) => (isSimklLoggedIn = value));
|
simklLoggedIn.subscribe((value) => (isSimklLoggedIn = value));
|
||||||
malLoggedIn.subscribe((value) => (isMALLoggedIn = value));
|
malLoggedIn.subscribe((value) => (isMALLoggedIn = value));
|
||||||
|
|
||||||
function dropdownUser(): void {
|
function dropdownUser(): void {
|
||||||
let dropdown = document.querySelector("#userDropdown");
|
let dropdown = document.querySelector("#userDropdown");
|
||||||
dropdown.classList.toggle("hidden");
|
dropdown.classList.toggle("hidden");
|
||||||
|
|
||||||
if (!dropdown.classList.contains("hidden")) {
|
if (!dropdown.classList.contains("hidden")) {
|
||||||
document.addEventListener("click", clickOutside)
|
document.addEventListener("click", clickOutside);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clickOutside(event: Event): void {
|
function clickOutside(event: Event): void {
|
||||||
let dropdown = document.querySelector("#userDropdown")
|
let dropdown = document.querySelector("#userDropdown");
|
||||||
let toggleBtn = document.querySelector("#userDropdownButton")
|
let toggleBtn = document.querySelector("#userDropdownButton");
|
||||||
|
|
||||||
if (!dropdown.contains(event.target as Node) && !toggleBtn.contains(event.target as Node)) {
|
if (
|
||||||
dropdown.classList.add("hidden")
|
!dropdown.contains(event.target as Node) &&
|
||||||
document.removeEventListener("click", clickOutside)
|
!toggleBtn.contains(event.target as Node)
|
||||||
}
|
) {
|
||||||
|
dropdown.classList.add("hidden");
|
||||||
|
document.removeEventListener("click", clickOutside);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<button id="userDropdownButton" on:click={dropdownUser}>
|
<button id="userDropdownButton" on:click={dropdownUser}>
|
||||||
{#if isAniListLoggedIn}
|
{#if isAniListLoggedIn}
|
||||||
<Avatar
|
<Avatar
|
||||||
src={currentAniListUser.data.Viewer.avatar.medium}
|
src={currentAniListUser.data.Viewer.avatar.medium}
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
dot={{ color: "green" }}
|
dot={isAniListLoggedIn && isMALLoggedIn && isSimklLoggedIn
|
||||||
/>
|
? { color: "green" }
|
||||||
{:else}
|
: { color: "yellow" }}
|
||||||
<Avatar class="cursor-pointer" dot={{ color: "red" }} />
|
/>
|
||||||
{/if}
|
{:else}
|
||||||
</button>
|
<Avatar class="cursor-pointer" dot={{ color: "red" }} />
|
||||||
<div
|
{/if}
|
||||||
id="userDropdown"
|
</button>
|
||||||
class="absolute hidden right-0 2xl:left-1/2 2xl:-translate-x-1/2 z-10 divide-y rounded-lg shadow w-44 bg-gray-700 divide-gray-600"
|
<div
|
||||||
>
|
id="userDropdown"
|
||||||
<div class="px-4 py-3 text-sm text-white">
|
class="absolute hidden right-0 2xl:left-1/2 2xl:-translate-x-1/2 z-10 divide-y rounded-lg shadow w-44 bg-gray-700 divide-gray-600"
|
||||||
{#if isAniListLoggedIn}
|
>
|
||||||
<div>{currentAniListUser.data.Viewer.name}</div>
|
<div class="px-4 py-3 text-sm text-white">
|
||||||
{:else}
|
{#if isAniListLoggedIn}
|
||||||
<div>You are not logged into AniList</div>
|
<div>{currentAniListUser.data.Viewer.name}</div>
|
||||||
{/if}
|
{:else}
|
||||||
</div>
|
<div>You are not logged into AniList</div>
|
||||||
<ul
|
{/if}
|
||||||
class="py-2 text-sm text-gray-200"
|
|
||||||
aria-labelledby="dropdownUserAvatarButton"
|
|
||||||
>
|
|
||||||
{#if isAniListLoggedIn}
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
on:click={logoutOfAniList}
|
|
||||||
class="block px-4 py-2 w-full hover:bg-gray-600 truncate bg-green-800 hover:text-white"
|
|
||||||
>
|
|
||||||
<span class="maple-font text-lg text-green-200 mr-4">A</span>Logout {currentAniListUser.data.Viewer.name}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{:else}
|
|
||||||
<li>
|
|
||||||
<button on:click={() => {
|
|
||||||
dropdownUser()
|
|
||||||
loginToAniList()
|
|
||||||
}}
|
|
||||||
class="block px-4 py-2 w-full hover:bg-gray-600 truncate hover:text-white">
|
|
||||||
<span class="maple-font text-lg mr-4">A</span>Login to AniList
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{/if}
|
|
||||||
{#if isMALLoggedIn}
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
on:click={logoutOfMAL}
|
|
||||||
class="block px-4 py-2 w-full hover:bg-gray-600 truncate bg-blue-800 hover:text-white"
|
|
||||||
>
|
|
||||||
<span class="maple-font text-lg text-blue-200 mr-4">M</span>Logout {currentMALUser.name}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{:else}
|
|
||||||
<li>
|
|
||||||
<button on:click={() => {
|
|
||||||
dropdownUser()
|
|
||||||
loginToMAL()
|
|
||||||
}}
|
|
||||||
class="block px-4 py-2 w-full hover:bg-gray-600 truncate hover:text-white">
|
|
||||||
<span class="maple-font text-lg mr-4">M</span>Login to MyAnimeList
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{/if}
|
|
||||||
{#if isSimklLoggedIn}
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
on:click={logoutOfSimkl}
|
|
||||||
class="block px-4 py-2 w-full hover:bg-gray-600 truncate bg-indigo-800 hover:text-white"
|
|
||||||
>
|
|
||||||
<span class="maple-font text-lg text-indigo-200 mr-4">S</span>Logout {currentSimklUser.user.name}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{:else}
|
|
||||||
<li>
|
|
||||||
<button on:click={() => {
|
|
||||||
dropdownUser()
|
|
||||||
loginToSimkl()
|
|
||||||
}}
|
|
||||||
class="block px-4 py-2 w-full hover:bg-gray-600 truncate hover:text-white">
|
|
||||||
<span class="maple-font text-lg mr-4">S</span>Login to Simkl
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{/if}
|
|
||||||
</ul>
|
|
||||||
<div class="py-2">
|
|
||||||
<button
|
|
||||||
on:click={() => {
|
|
||||||
dropdownUser()
|
|
||||||
ShowVersion()
|
|
||||||
}}
|
|
||||||
class="block px-4 py-2 w-full text-sm hover:bg-gray-600 text-gray-200 over:text-white"
|
|
||||||
>
|
|
||||||
Version
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
on:click={() => runtime.Quit()}
|
|
||||||
class="block px-4 py-2 w-full text-sm hover:bg-gray-600 text-gray-200 over:text-white"
|
|
||||||
>
|
|
||||||
Exit Application
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<ul
|
||||||
|
class="py-2 text-sm text-gray-200"
|
||||||
|
aria-labelledby="dropdownUserAvatarButton"
|
||||||
|
>
|
||||||
|
{#if isAniListLoggedIn}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
on:click={logoutOfAniList}
|
||||||
|
class="block px-4 py-2 w-full hover:bg-gray-600 truncate bg-green-800 hover:text-white"
|
||||||
|
>
|
||||||
|
<span class="maple-font text-lg text-green-200 mr-4">A</span>Logout {currentAniListUser
|
||||||
|
.data.Viewer.name}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{:else}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
dropdownUser();
|
||||||
|
loginToAniList();
|
||||||
|
}}
|
||||||
|
class="block px-4 py-2 w-full hover:bg-gray-600 truncate hover:text-white"
|
||||||
|
>
|
||||||
|
<span class="maple-font text-lg mr-4">A</span>Login to AniList
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/if}
|
||||||
|
{#if isMALLoggedIn}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
on:click={logoutOfMAL}
|
||||||
|
class="block px-4 py-2 w-full hover:bg-gray-600 truncate bg-blue-800 hover:text-white"
|
||||||
|
>
|
||||||
|
<span class="maple-font text-lg text-blue-200 mr-4">M</span>Logout {currentMALUser.name}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{:else}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
dropdownUser();
|
||||||
|
loginToMAL();
|
||||||
|
}}
|
||||||
|
class="block px-4 py-2 w-full hover:bg-gray-600 truncate hover:text-white"
|
||||||
|
>
|
||||||
|
<span class="maple-font text-lg mr-4">M</span>Login to MyAnimeList
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/if}
|
||||||
|
{#if isSimklLoggedIn}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
on:click={logoutOfSimkl}
|
||||||
|
class="block px-4 py-2 w-full hover:bg-gray-600 truncate bg-indigo-800 hover:text-white"
|
||||||
|
>
|
||||||
|
<span class="maple-font text-lg text-indigo-200 mr-4">S</span>Logout {currentSimklUser
|
||||||
|
.user.name}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{:else}
|
||||||
|
<li>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
dropdownUser();
|
||||||
|
loginToSimkl();
|
||||||
|
}}
|
||||||
|
class="block px-4 py-2 w-full hover:bg-gray-600 truncate hover:text-white"
|
||||||
|
>
|
||||||
|
<span class="maple-font text-lg mr-4">S</span>Login to Simkl
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/if}
|
||||||
|
</ul>
|
||||||
|
<div class="py-2">
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
dropdownUser();
|
||||||
|
ShowVersion();
|
||||||
|
}}
|
||||||
|
class="block px-4 py-2 w-full text-sm hover:bg-gray-600 text-gray-200 over:text-white"
|
||||||
|
>
|
||||||
|
Version
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
on:click={() => runtime.Quit()}
|
||||||
|
class="block px-4 py-2 w-full text-sm hover:bg-gray-600 text-gray-200 over:text-white"
|
||||||
|
>
|
||||||
|
Exit Application
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user