Skip to content

Commit

Permalink
feat(web): improve NavBar design
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Aug 15, 2021
1 parent 30e5f18 commit 4a4b16b
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ apps/librelingo_tools/dist
*.tsbuildinfo
report.*.*.json
/coverage/
apps/docs/build/
File renamed without changes.
26 changes: 26 additions & 0 deletions apps/lluis/NavBar/NavBarButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="typescript">
import LinkOrButton from "../primitives/LinkOrButton.svelte"
import { createEventDispatcher } from "svelte"

const dispatch = createEventDispatcher()
export let href: string | null = null
</script>

<div>
<LinkOrButton href={href} on:click="{() => dispatch('click')}">
<slot />
</LinkOrButton>
</div>

<style type="text/scss">
div :global(*) {
display: block;
padding: 6px;
color: var(--navbar-text-color);
border-radius: var(--button-radius-small);

&:hover, &:focus {
background-color: var(--navbar-highlight-color);
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<style type="text/scss">
.buttonset {
height: 100%;
display: flex;
gap: var(--spacing-medium);
}
Expand Down
11 changes: 11 additions & 0 deletions apps/lluis/NavBar/NavBarItem.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
<slot />
</div>

<style type="text/scss">
div {
display: block;
padding: 6px;
color: var(--navbar-text-color);
}
</style>
28 changes: 28 additions & 0 deletions apps/lluis/primitives/LinkOrButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="typescript">
import { createEventDispatcher } from "svelte"

const dispatch = createEventDispatcher()
export let href: string | null = null
</script>

{#if href !== null}
<a href={href} {...$$restProps}>
<slot />
</a>
{/if}

{#if href === null}
<button on:click={() => dispatch("click")} {...$$restProps}>
<slot />
</button>
{/if}

<style type="text/scss">
button {
display: block;
background: transparent;
border: 0;
font-size: inherit;
cursor: pointer;
}
</style>
44 changes: 20 additions & 24 deletions apps/web/src/components/NavBar.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script lang="typescript">
import settings from "../settings"
import authStore from "../auth"
import SponsorButton from "./SponsorButton.svelte"
import GitHubButton from "./GitHubButton.svelte"
import NavBar from "lluis/NavBar.svelte"
import NavBar from "lluis/NavBar/NavBar.svelte"
import Icon from "lluis/Icon.svelte"
import Button from "lluis/Button.svelte"
import NavBarButton from "lluis/NavBar/NavBarButton.svelte"
import Logo from "lluis/Logo.svelte"
import ButtonLink from "lluis/ButtonLink.svelte"
import ButtonSet from "lluis/ButtonSet.svelte"
import NavBarItem from "lluis/NavBar/NavBarItem.svelte"
import NavBarButtonSet from "lluis/NavBar/NavBarButtonSet.svelte"
export let hasAuth = false

type WindowWithLogout = Window & {
Expand All @@ -23,33 +21,31 @@
</div>

<div slot="right">
<ButtonSet>
<SponsorButton />
<GitHubButton />
<NavBarButtonSet>
{#if hasAuth && settings.features.authEnabled}
{#if $authStore.user}
<Button size="small" outlined inverted info>
<NavBarItem>
<Icon size="small" icon="user" />
<span>{$authStore.user.name}</span>
</Button>
<Button
on:click="{() => _Logout()}"
size="small"
outlined
inverted
info
>
</NavBarItem>
<NavBarButton on:click="{() => _Logout()}">
Log out
</Button>
</NavBarButton>
{:else}
<ButtonLink href="/sign-up" size="small" outlined inverted info>
<NavBarButton href="/sign-up">
Sign up
</ButtonLink>
<ButtonLink href="/login" size="small" outlined inverted info>
</NavBarButton>
<NavBarButton href="/login">
Log in
</ButtonLink>
</NavBarButton>
{/if}
{/if}
</ButtonSet>
</NavBarButtonSet>
</div>
</NavBar>

<style>
div {
height: 100%;
}
</style>
6 changes: 3 additions & 3 deletions apps/web/src/db/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ if (isBrowser() === true) {
window._DB = db

// Detect fake user session
if (Cookies.get("loginDb") === getUserDbName("---fakeUser")) {
if (Cookies.get("loginDb") === getUserDbName("JohnDoe")) {
authStore.update((value) => ({
...value,
user: { name: "---fakeUser" },
user: { name: "JohnDoe" },
online: true,
}))
}
Expand Down Expand Up @@ -84,7 +84,7 @@ if (isBrowser() === true) {

// Fake login for testing purposes
window._fakeLogin = () => {
Cookies.set("loginDb", getUserDbName("---fakeUser"), {
Cookies.set("loginDb", getUserDbName("JohnDoe"), {
expires: settings.database.auth.expireDays,
})
window.location.href = "/course/spanish-from-english/"
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/mystyles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@
--spacing-small: 8px;
--spacing-medium: 12px;
--spacing-large: calc(var(--spacing-small) + var(--spacing-medium));
--button-radius-small: calc(var(--spacing-small) / 2);
--blue: #325f74;
--white: #bfb5af;
--white: #faf4f0;

--navbar-background: var(--blue);
--navbar-text-color: var(--white);
--navbar-highlight-color: rgba(255, 255, 255, .1);
--navbar-height: 52px;
--navbar-padding-vertical: var(--spacing-small);
--navbar-padding-horizontal: var(--spacing-medium);
Expand Down

0 comments on commit 4a4b16b

Please sign in to comment.