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

68 lines
2.2 KiB
Svelte
Raw Normal View History

2022-02-20 20:30:53 +01:00
<script lang="ts">
import { onMount } from "svelte";
2022-02-22 16:57:56 +01:00
import { Link } from "svelte-navigator";
2022-02-22 10:05:21 +01:00
2022-02-22 16:57:56 +01:00
import { servers, selectedServer, loadServers } from "~/store";
2022-02-22 10:05:21 +01:00
import CogIcon from "~/assets/nes.icons/cog.svg";
2022-02-22 12:02:56 +01:00
import { api } from "~/lib/ipc";
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 17:56:57 +01:00
$: serverWithSelection = $servers.map((s) => ({ ...s, isSelected: $selectedServer === s._id }))
2022-02-20 20:30:53 +01:00
onMount(async () => {
await loadServers();
2022-02-22 12:02:56 +01:00
isDevelopment = await api.isDevelopment();
2022-02-20 20:30:53 +01:00
});
</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">
2022-02-22 17:56:57 +01:00
{#each serverWithSelection as server, i}
2022-02-22 16:57:56 +01:00
<Link to="/server/{server._id}" 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`}
2022-02-22 17:56:57 +01:00
class:bg-gray-400={server.isSelected}
2022-02-20 20:30:53 +01:00
>
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>
2022-02-22 16:57:56 +01:00
</Link>
2022-02-20 20:30:53 +01:00
{/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"
2022-02-22 10:41:55 +01:00
class="flex mt-auto mb-4 justify-center items-center text-4xl no-underline cursor-pointer"
2022-02-22 10:05:21 +01:00
>
<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:41:55 +01:00
<button class="text-8px text-red-500 my-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>