optimize: tweak navbar

This commit is contained in:
Xylight committed 2024-02-26 16:04:37 -08:00
1 parent 9be53724d2
commit 1d4bc14075
5 files changed
+365 -343

No files matched your search

@@ -0,0 +1,23 @@
<script lang="ts">
import { Button } from 'mono-svelte'
import { Icon, type IconSource } from 'svelte-hero-icons'
export let label: string
export let icon: IconSource | undefined = undefined
</script>
<Button
{...$$restProps}
class="px-3 py-1.5 max-md:py-0 max-md:px-0 max-md:h-9 max-md:w-9 {$$props.class ??
''}"
size="custom"
title={label}
>
{#if icon}
<Icon src={icon} mini size="16" />
{:else}
<slot name="icon" />
{/if}
<span class="max-md:hidden">{label}</span>
<slot />
</Button>
+174
View File
@@ -0,0 +1,174 @@
<script lang="ts">
import { profile, profileData } from '$lib/auth.js'
import Link from '$lib/components/input/Link.svelte'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
import {
amModOfAny,
isAdmin,
} from '$lib/components/lemmy/moderation/moderation.js'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Logo from '$lib/components/ui/Logo.svelte'
import { LINKED_INSTANCE_URL, instance } from '$lib/instance.js'
import { site } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
import { theme } from '$lib/ui/colors.js'
import {
Badge,
Button,
Menu,
MenuButton,
MenuDivider,
Select,
Spinner,
toast,
} from 'mono-svelte'
import {
Bars3,
Bookmark,
BugAnt,
CodeBracket,
CodeBracketSquare,
Cog6Tooth,
CommandLine,
ComputerDesktop,
GlobeAlt,
Heart,
Icon,
Inbox,
InformationCircle,
MagnifyingGlass,
Moon,
Newspaper,
PencilSquare,
Plus,
ServerStack,
Sun,
UserCircle,
UserGroup,
} from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
import Profile from './Profile.svelte'
import NavButton from './NavButton.svelte'
export let title: string | undefined = ''
</script>
<nav
class="flex flex-row gap-2 items-center
backdrop-blur-lg w-full mx-auto px-4 py-2 z-50 box-border h-16
{$$props.class}
"
style={$$props.style}
>
<div class="flex flex-row gap-2 items-center mr-auto">
<a
href="/"
class="flex flex-row items-center gap-2 logo group"
title="Home"
>
{#if LINKED_INSTANCE_URL}
{#if $site}
<Avatar
url={$site.site_view.site.icon}
alt={$site.site_view.site.name}
width={32}
res={64}
circle={false}
class="rounded-md"
/>
<div class="flex flex-row items-center gap-2 max-[500px]:hidden">
<span class="opacity-30 text-xl">/</span>
{$site.site_view.site.name}
</div>
{:else}
<Spinner width={32} />
{/if}
{:else}
<Logo width={40} />
<div class="flex flex-row items-center gap-2 max-[1000px]:hidden">
<span class="opacity-30 text-xl">/</span>
<span class="text-sm font-bold grid place-items-start">
{#key title || $instance}
<span
in:fly={{ y: -12 }}
out:fly={{ y: 12 }}
style="grid-row: 1; grid-column: 1; max-width: 24ch;"
class="overflow-hidden break-words overflow-ellipsis whitespace-nowrap"
>
{title || $instance}
</span>
{/key}
</span>
</div>
{/if}
</a>
</div>
<div class="flex flex-row gap-2 py-2 px-2 items-center">
{#if $profile?.user && isAdmin($profile.user)}
<NavButton
href="/admin"
label="Admin"
icon={ServerStack}
class="relative"
>
{#if ($profile?.user?.notifications.applications ?? 0) > 0}
<div
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
/>
{/if}
</NavButton>
{/if}
{#if amModOfAny($profile?.user)}
<NavButton href="/moderation" label="Moderation" class="relative">
{#if ($profile?.user?.notifications.reports ?? 0) > 0}
<div
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
/>
{/if}
<ShieldIcon slot="icon" filled width={15} />
</NavButton>
{/if}
<NavButton href="/search" label="Search" icon={MagnifyingGlass} />
<NavButton href="/communities" label="Explore" icon={GlobeAlt} />
<Menu placement="bottom-end" targetClass="h-8">
<NavButton
class="relative"
color="primary"
slot="target"
label="Create"
icon={Plus}
/>
<MenuDivider>Create</MenuDivider>
<MenuButton
link
href="/create/post"
disabled={$profile?.jwt == undefined}
>
<Icon src={PencilSquare} mini width={16} />
Post
</MenuButton>
<MenuButton
link
href="/create/community"
disabled={!$profile?.jwt ||
!$profile?.user ||
($site?.site_view.local_site.community_creation_admin_only &&
!isAdmin($profile.user))}
>
<Icon src={Newspaper} mini width={16} />
Community
</MenuButton>
{#if !$profile?.jwt}
<span class="text-sm mx-4 my-1 py-1">
<Link highlight href="/login">Log in</Link> to create content.
</span>
{/if}
</Menu>
<Profile
placement="bottom-end"
itemsClass="h-8 md:h-8 z-10"
targetClass="z-10 h-8"
containerClass="!max-h-[28rem] z-10"
/>
</div>
</nav>
+167
View File
@@ -0,0 +1,167 @@
<script>
import { profile } from '$lib/auth'
import {
Badge,
Button,
Menu,
MenuButton,
MenuDivider,
Select,
toast,
} from 'mono-svelte'
import Avatar from '../Avatar.svelte'
import {
Bars3,
Bookmark,
BugAnt,
CodeBracketSquare,
Cog6Tooth,
ComputerDesktop,
Heart,
Icon,
Inbox,
InformationCircle,
Moon,
Sun,
UserCircle,
UserGroup,
} from 'svelte-hero-icons'
import { theme } from '$lib/ui/colors'
import { userSettings } from '$lib/settings'
</script>
<Menu {...$$restProps}>
<button
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100
dark:bg-zinc-800 relative"
aria-label="Profile"
slot="target"
>
{#if $profile?.user}
<div class="w-8 h-8 aspect-square object-cover rounded-full">
<Avatar
url={$profile.user.local_user_view.person.avatar}
width={32}
alt={$profile.user.local_user_view.person.name}
/>
</div>
{#if $profile.user.notifications.inbox > 0}
<div
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
/>
{/if}
{:else}
<div class="w-full h-full grid place-items-center">
<Icon src={Bars3} mini size="18" />
</div>
{/if}
</button>
{#if $profile?.user}
<div class="flex flex-row gap-2 items-center py-2 mx-4 font-medium">
<Avatar
width={22}
url={$profile?.user?.local_user_view.person.avatar}
alt={$profile?.username}
/>
{$profile?.user?.local_user_view?.person.name}
</div>
{:else}
<MenuDivider>Profile</MenuDivider>
{/if}
{#if $profile?.user}
<MenuButton link href="/profile">
<Icon src={UserCircle} mini width={16} /> Profile
</MenuButton>
<MenuButton link href="/inbox">
<Icon src={Inbox} mini width={16} />
Inbox
{#if $profile.user.notifications.inbox > 0}
<Badge color="red-subtle" class="text-xs ml-auto font-bold !py-0.5">
{$profile.user.notifications.inbox}
</Badge>
{/if}
</MenuButton>
<MenuButton link href="/saved">
<Icon src={Bookmark} mini width={16} /> Saved
</MenuButton>
{/if}
<MenuButton link href="/accounts">
<Icon src={UserGroup} mini width={16} />
Accounts
</MenuButton>
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
<MenuDivider>Photon</MenuDivider>
<MenuButton link href="/settings">
<Icon src={Cog6Tooth} mini width={16} />
Settings
</MenuButton>
<MenuButton class="!py-0">
<Icon
src={$theme == 'system'
? ComputerDesktop
: $theme == 'light'
? Sun
: $theme == 'dark'
? Moon
: Moon}
mini
size="16"
/>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="flex flex-row flex-wrap justify-between w-full items-center"
on:click|stopPropagation
>
<span>Theme</span>
<Select bind:value={$theme} class="ml-auto my-auto w-24" size="sm">
<option value="system">System</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</Select>
</div>
</MenuButton>
{#if $userSettings.debugInfo}
<MenuButton link href="/util">
<Icon src={BugAnt} mini width={16} />
Debug
</MenuButton>
{/if}
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
<li class="flex flex-col px-4 py-1 mx-auto my-1 text-xs w-full">
<div class="flex flex-row gap-2 w-full items-center">
<!-- svelte-ignore missing-declaration -->
<div class="flex-1">
<button
class="hover:brightness-110 transition-all"
on:click={() => {
navigator?.clipboard?.writeText(__VERSION__)
toast({ content: 'Copied version to clipboard.' })
}}
>
<Badge>{__VERSION__}</Badge>
</button>
</div>
<Button
color="tertiary"
href="https://buymeacoffee.com/xylight"
title="Donate"
size="square-md"
>
<Icon src={Heart} size="16" mini />
</Button>
<Button
color="tertiary"
href="https://github.com/Xyphyn/Photon"
title="GitHub"
size="square-md"
>
<Icon src={CodeBracketSquare} size="16" mini />
</Button>
<Button color="tertiary" href="/about" title="About" size="square-md">
<Icon src={InformationCircle} size="16" mini />
</Button>
</div>
</li>
</Menu>