PluralKit/src/lib/Navigation.svelte

62 lines
2.5 KiB
Svelte
Raw Normal View History

2021-12-09 11:53:54 +00:00
<script lang="ts">
2021-12-12 07:01:10 +00:00
import {Navbar, NavbarBrand, Nav, NavItem, NavLink, Collapse, NavbarToggler, Dropdown, DropdownItem, DropdownMenu, DropdownToggle, Button} from 'sveltestrap';
2021-12-11 11:01:36 +00:00
import { loggedIn } from '../stores';
2021-12-12 07:01:10 +00:00
import { Link, navigate } from 'svelte-navigator';
import { get } from 'svelte/store';
2021-12-11 11:01:36 +00:00
export let style: string;
2021-12-09 11:53:54 +00:00
let isOpen = false;
const toggle = () => (isOpen = !isOpen);
2021-12-11 11:01:36 +00:00
let loggedIn_value: boolean;
loggedIn.subscribe(value => {
loggedIn_value = value;
});
2021-12-12 07:01:10 +00:00
function logout() {
localStorage.removeItem("pk-token");
localStorage.removeItem("pk-user");
loggedIn.update(() => false);
navigate("/");
}
2021-12-11 11:01:36 +00:00
</script>
2021-12-11 17:39:42 +00:00
<div style="background-color: #292929" class="mb-4">
<Navbar color="light" light expand="lg">
2021-12-11 11:01:36 +00:00
<NavbarBrand>pk-webs</NavbarBrand>
<NavbarToggler on:click={toggle}></NavbarToggler>
<Collapse {isOpen} navbar expand="lg">
<Nav class="ms-auto" navbar>
<Dropdown nav inNavbar>
<DropdownToggle color="transparent">Styles</DropdownToggle>
<DropdownMenu end>
<DropdownItem on:click={() => style = "light"}>Light</DropdownItem>
<DropdownItem on:click={() => style = "dark"}>Dark</DropdownItem>
</DropdownMenu>
</Dropdown>
{#if loggedIn_value || localStorage.getItem("pk-token")}
<Dropdown nav inNavbar>
<DropdownToggle color="transparent">Dash</DropdownToggle>
<DropdownMenu end>
2021-12-11 17:39:56 +00:00
<Link style="text-decoration: none;" to="/dash" state={{tab: "system"}}><DropdownItem>System</DropdownItem></Link>
<Link style="text-decoration: none;" to="/dash" state={{tab: "members"}}><DropdownItem>Members</DropdownItem></Link>
2021-12-12 07:01:10 +00:00
<DropdownItem divider />
<DropdownItem on:click={logout}>Log out</DropdownItem>
2021-12-11 11:01:36 +00:00
</DropdownMenu>
</Dropdown>
{/if}
<NavItem>
<NavLink href="/settings">Settings</NavLink>
</NavItem>
<NavItem>
<NavLink href="/templates">Templates</NavLink>
</NavItem>
<NavItem>
<NavLink href="/public">Public</NavLink>
</NavItem>
</Nav>
</Collapse>
</Navbar>
</div>