impr: restructure src/lib

This commit is contained in:
Xylight committed 2025-09-24 17:12:19 -07:00
1 parent d85b889409
commit 75f907743e
376 files changed
+1000 -1033

No files matched your search

+193
View File
@@ -0,0 +1,193 @@
<script lang="ts">
import { notifications, profile } from '$lib/app/auth.svelte.js'
import ItemList from '$lib/ui/generic/ItemList.svelte'
import Expandable from 'mono-svelte/disclosure/Expandable.svelte'
import SidebarButton from '$comp/ui/sidebar/SidebarButton.svelte'
import { t } from '$lib/app/i18n'
import { communityLink } from '$lib/util.svelte'
import { settings } from '$lib/settings.svelte.js'
import { theme } from '$lib/app/theme/theme.svelte'
import { Badge, Option, Select } from 'mono-svelte'
import {
ArrowLeftOnRectangle,
Bookmark,
ChevronUpDown,
Cog6Tooth,
ComputerDesktop,
Icon,
Identification,
Inbox,
Moon,
Sun,
Swatch,
UserCircle,
UserGroup,
} from 'svelte-hero-icons'
import type { ClassValue } from 'svelte/elements'
import EndPlaceholder from '../EndPlaceholder.svelte'
import ProfileSelection from './ProfileSelection.svelte'
import Logo from '../Logo.svelte'
import { env } from '$env/dynamic/public'
import Link from '$comp/input/Link.svelte'
interface Props {
style?: string
class?: ClassValue
}
let { style = '', class: clazz = '' }: Props = $props()
</script>
<nav
aria-label={$t('aria.sidebar.title')}
class={['flex flex-col overflow-auto gap-1', clazz]}
{style}
>
<ProfileSelection profiles={profile.meta.profiles} />
<EndPlaceholder margin="sm" size="xs">{$t('profile.profile')}</EndPlaceholder>
{#if profile.current?.jwt}
<SidebarButton
icon={UserCircle}
href="/profile"
label={$t('profile.profile')}
/>
<SidebarButton icon={Inbox} href="/inbox" label={$t('profile.inbox')}>
{#if $notifications.inbox}
<Badge
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
color="red-subtle"
>
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
</Badge>
{/if}
</SidebarButton>
<SidebarButton icon={Bookmark} href="/saved" label={$t('profile.saved')} />
{:else}
<SidebarButton
href="/login"
label={$t('account.login')}
icon={ArrowLeftOnRectangle}
/>
<SidebarButton
href="/signup"
label={$t('account.signup')}
icon={Identification}
/>
<SidebarButton
href="/accounts"
label={$t('account.accounts')}
icon={UserGroup}
/>
{/if}
<EndPlaceholder margin="sm" size="xs">{$t('nav.menu.app')}</EndPlaceholder>
<SidebarButton
href="/settings"
label={$t('nav.menu.settings')}
icon={Cog6Tooth}
/>
<Select bind:value={theme.colorScheme} size="sm">
{#snippet target(attachment)}
<SidebarButton
{@attach attachment}
label={$t('nav.menu.colorscheme.label')}
icon={theme.colorScheme == 'system'
? ComputerDesktop
: theme.colorScheme == 'light'
? Sun
: Moon}
class="w-full relative"
>
<Option value="system" class="hidden" icon={ComputerDesktop}>
{$t('nav.menu.colorscheme.system')}
</Option>
<Option value="light" class="hidden" icon={Sun}>
{$t('nav.menu.colorscheme.light')}
</Option>
<Option value="dark" class="hidden" icon={Moon}>
{$t('nav.menu.colorscheme.dark')}
</Option>
<Icon micro size="16" src={ChevronUpDown} class="ml-auto" />
</SidebarButton>
{/snippet}
</Select>
<SidebarButton href="/theme" label={$t('nav.menu.theme')} icon={Swatch} />
{#if profile.current?.user}
<EndPlaceholder margin="sm" size="xs">
{$t('content.communities')}
</EndPlaceholder>
<div class="space-y-3">
{#if profile.current?.user.moderates.length > 0}
<Expandable class="px-1.5" bind:open={settings.expand.moderates}>
{#snippet title()}
<span class="px-2 py-1 w-full">
<EndPlaceholder border={false}>
{$t('routes.profile.moderates')}
{#snippet action()}
<span class="dark:text-white text-black">
{profile.current.user?.moderates.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<ItemList
items={profile.current.user.moderates.map((i) => ({
id: i.community.id,
name: i.community.title,
url: communityLink(i.community),
avatar: i.community.icon,
instance: new URL(i.community.actor_id).hostname,
}))}
/>
</Expandable>
{/if}
<Expandable class="px-1.5" bind:open={settings.expand.communities}>
{#snippet title()}
<span class="px-2 py-1 w-full">
<EndPlaceholder border={false}>
{$t('profile.subscribed')}
{#snippet action()}
<span class="dark:text-white text-black">
{profile.current.user?.follows.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<ItemList
items={profile.current.user.follows.map((i) => ({
id: i.community.id,
name: i.community.title,
url: communityLink(i.community),
avatar: i.community.icon,
instance: new URL(i.community.actor_id).hostname,
}))}
/>
</Expandable>
</div>
{/if}
<div class="flex-1 h-full mt-auto"></div>
<footer
class="flex gap-6 flex-col xl:flex-row text-sm text-slate-600 dark:text-zinc-300 flex-wrap"
>
<div class="flex items-center gap-2">
<Logo width={16} />
<span class="font-medium">
{__VERSION__}
</span>
</div>
{#if env.PUBLIC_XYLIGHT_MODE?.toLowerCase() == 'true'}
<Link highlight href="https://github.com/xyphyn/photon">
{$t('nav.menu.source')}
</Link>
<Link highlight href="https://buymeacoffee.com/xylight">
{$t('nav.menu.donate')}
</Link>
{/if}
</footer>
</nav>
+54
View File
@@ -0,0 +1,54 @@
<script lang="ts">
import { page } from '$app/state'
import { Button } from 'mono-svelte'
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
import { Icon, type IconSource } from 'svelte-hero-icons'
interface Props extends ButtonProps {
href?: string | undefined
icon?: IconSource | undefined
class?: string
label?: string
customIcon?: import('svelte').Snippet<[{ selected: boolean }]>
children?: import('svelte').Snippet
}
let {
href = undefined,
icon = undefined,
class: clazz = '',
customIcon,
children,
label,
...rest
}: Props = $props()
let selected = $derived(page.url.pathname == href)
</script>
<Button
color="tertiary"
alignment="left"
rounding="xl"
{...rest}
{href}
weight="none"
class={[
'hover:text-slate-900 hover:dark:text-zinc-50',
selected
? 'text-primary-900 dark:text-primary-100'
: 'text-slate-600 dark:text-zinc-400',
clazz,
]}
shadow="none"
>
{#snippet prefix()}
{#if customIcon}
{@render customIcon({ selected })}
{:else if icon}
<Icon src={icon} solid size="18" />
{/if}
{/snippet}
{label}
{@render children?.()}
</Button>