partey_workadventure/desktop/local-app/src/lib/Sidebar.svelte

70 lines
2.3 KiB
Svelte
Raw Normal View History

2022-02-20 20:30:53 +01:00
<script lang="ts">
import { onMount } from "svelte";
2022-02-22 10:05:21 +01:00
import Link from "~/lib/Link.svelte";
import { servers, selectedServer, selectServer, loadServers, Server } from "../store";
import CogIcon from "~/assets/nes.icons/cog.svg";
2022-02-20 20:30:53 +01:00
let isDevelopment = false;
2022-02-20 21:51:55 +01:00
function getServerColor(i: number) {
2022-02-22 10:05:21 +01:00
const serverColors = [
"bg-red-400",
"bg-yellow-500",
"bg-green-500",
"bg-blue-500",
"bg-indigo-500",
"bg-purple-500",
];
2022-02-20 21:51:55 +01:00
return serverColors[i % serverColors.length];
}
2022-02-22 10:05:21 +01:00
selectedServer.subscribe((e) => {
console.log("selected server changed", e);
});
2022-02-20 20:30:53 +01:00
onMount(async () => {
await loadServers();
isDevelopment = await window?.WorkAdventureDesktopApi?.isDevelopment();
});
</script>
<aside class="flex flex-col bg-gray-700 items-center">
2022-02-20 21:51:55 +01:00
<div class="flex flex-col mt-4 space-y-4 overflow-y-auto pb-4">
{#each $servers as server, i}
2022-02-22 10:05:21 +01:00
<div class="flex flex-col items-center justify-center ">
2022-02-20 20:30:53 +01:00
<div
2022-02-22 10:05:21 +01:00
class={`w-16 h-16 p-1 rounded-md flex cursor-pointer text-light-50 border-4 border-transparent text-gray-200 hover:text-gray-500`}
class:border-gray-400={$selectedServer === server._id}
2022-02-20 20:30:53 +01:00
on:click={() => selectServer(server)}
>
2022-02-22 10:05:21 +01:00
<div class={`flex w-full h-full text-center items-center justify-center rounded-md ${getServerColor(i)}`}>
{server.name.slice(0,2).toLocaleUpperCase()}
</div>
2022-02-20 20:30:53 +01:00
</div>
</div>
{/each}
</div>
2022-02-22 10:05:21 +01:00
<Link
to="/server/add"
class="flex justify-center items-center text-4xl no-underline text-gray-200 cursor-pointer hover:text-gray-500"
>+</Link
>
<Link
to="/settings"
class="flex mt-auto justify-center items-center text-4xl no-underline cursor-pointer"
>
<CogIcon width="30" height="30" class="fill-gray-200 hover:fill-gray-500" />
</Link>
2022-02-20 20:30:53 +01:00
{#if isDevelopment}
2022-02-22 10:05:21 +01:00
<button class="text-8px text-red-500 mt-8 mb-4" on:click={() => location.reload()}>Refresh</button>
2022-02-20 20:30:53 +01:00
{/if}
</aside>
<style>
aside {
2022-02-22 10:05:21 +01:00
width: 80px;
2022-02-20 20:30:53 +01:00
}
</style>