fix: redesign and fix command palette

This commit is contained in:
James Xylight committed 2025-02-08 15:30:47 -08:00
1 parent cef63faf93
commit 75bf706d33
4 files changed
+48 -50

No files matched your search

@@ -21,6 +21,16 @@
let { open = $bindable(false), groups = $bindable([]) }: Props = $props() let { open = $bindable(false), groups = $bindable([]) }: Props = $props()
$effect(() => {
groups = getGroups(
$resumables,
profile.data,
profileData.profiles,
$themeData,
page.data.contextual?.actions,
)
})
let search = $state('') let search = $state('')
let container: HTMLElement | undefined = $state() let container: HTMLElement | undefined = $state()
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@@ -226,18 +236,11 @@
$effect(() => { $effect(() => {
if (open) search = '' if (open) search = ''
}) })
$effect(() => {
groups = getGroups(
$resumables,
profile.data,
profileData.profiles,
$themeData,
page.data.contextual?.actions,
)
})
let flattenedActions = $derived( let flattenedActions = $derived(
filteredGroups.flatMap((group) => group.actions), filteredGroups.flatMap((group) => group.actions),
) )
$effect(() => { $effect(() => {
debouncedSearch(search) debouncedSearch(search)
}) })
@@ -245,8 +248,14 @@
<svelte:window onkeydown={handleKeydown} /> <svelte:window onkeydown={handleKeydown} />
<TextInput bind:value={search} autofocus class="sticky font-mono" /> <TextInput
<div class="h-96 overflow-auto border-slate-200 dark:border-zinc-800"> bind:value={search}
autofocus
class="sticky rounded-none border-t-0 border-x-0 focus-within:dark:border-zinc-800"
size="lg"
placeholder={$t('nav.commands.prompt')}
/>
<div class="h-[32rem] overflow-auto border-slate-200 dark:border-zinc-800 p-5">
{#if breadcrumbs.length > 0} {#if breadcrumbs.length > 0}
<div class="flex items-center gap-2 my-1"> <div class="flex items-center gap-2 my-1">
<button <button
@@ -24,31 +24,15 @@
<svelte:window onkeydown={handleKeydown} /> <svelte:window onkeydown={handleKeydown} />
{#if open} {#if open}
<Modal bind:open> <Modal bind:open title={null} class="!p-0 !gap-0">
{#snippet customTitle()}
<span class="flex items-center gap-1">
<svg
width="24"
height="24"
fill="currentColor"
viewBox="15 15 70 70"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M45 20.8868C48.094 19.1004 51.906 19.1004 55 20.8868L72.7128 31.1132C75.8068 32.8996 77.7128 36.2008 77.7128 39.7735V60.2265C77.7128 63.7992 75.8068 67.1004 72.7128 68.8867L55 79.1133C51.906 80.8996 48.094 80.8996 45 79.1133L27.2872 68.8867C24.1932 67.1004 22.2872 63.7992 22.2872 60.2265V39.7735C22.2872 36.2008 24.1932 32.8996 27.2872 31.1132L45 20.8868Z"
/>
</svg>
{$t('nav.commands.prompt')}
</span>
{/snippet}
{#await import('./Commands.svelte')} {#await import('./Commands.svelte')}
<div class="h-96 flex flex-col gap-2 items-center justify-center"> <div class="h-[32rem] flex flex-col gap-2 items-center justify-center">
<Spinner width={32} /> <Spinner width={32} />
<span class="font-medium text-lg"> <span class="font-medium text-lg">
{$t('nav.commands.downloading')} {$t('nav.commands.downloading')}
</span> </span>
</div> </div>
{:then {default: Commands }} {:then { default: Commands }}
<Commands bind:open /> <Commands bind:open />
{/await} {/await}
</Modal> </Modal>
@@ -92,7 +92,7 @@ export function getGroups(
name: t.get('nav.communities'), name: t.get('nav.communities'),
icon: GlobeAlt, icon: GlobeAlt,
}, },
...(amModOfAny(profile.data.user) ...(amModOfAny(profile.user)
? [ ? [
{ {
href: '/moderation', href: '/moderation',
@@ -101,7 +101,7 @@ export function getGroups(
}, },
] ]
: []), : []),
...(profile.data.user && isAdmin(profile.data.user) ...(profile.user && isAdmin(profile.user)
? [ ? [
{ {
href: '/admin', href: '/admin',
@@ -236,23 +236,23 @@ export function getGroups(
], ],
}, },
{ {
name: t.get('profile.data.profile'), name: t.get('profile.profile'),
actions: profile.data.jwt actions: profile.jwt
? [ ? [
{ {
href: '/profile/user', href: '/profile/user',
name: t.get('profile.data.profile'), name: t.get('profile.profile'),
icon: UserCircle, icon: UserCircle,
}, },
{ {
href: '/inbox', href: '/inbox',
name: t.get('profile.data.inbox'), name: t.get('profile.inbox'),
icon: Inbox, icon: Inbox,
shortcut: 'i', shortcut: 'i',
}, },
{ {
href: '/saved', href: '/saved',
name: t.get('profile.data.saved'), name: t.get('profile.saved'),
icon: Bookmark, icon: Bookmark,
}, },
{ {
@@ -311,11 +311,11 @@ export function getGroups(
icon: p.avatar ?? UserCircle, icon: p.avatar ?? UserCircle,
detail: p.instance, detail: p.instance,
handle: async () => { handle: async () => {
if (profile.data.id != p.id) { if (profile.id != p.id) {
await setUserID(p.id) await setUserID(p.id)
} }
await goto(get(page).url, { await goto(page.url, {
invalidateAll: true, invalidateAll: true,
}) })
}, },
@@ -407,9 +407,9 @@ export function getGroups(
], ],
}, },
{ {
name: t.get('profile.data.subscribed'), name: t.get('profile.subscribed'),
actions: actions:
profile.data?.user?.follows.map((f) => ({ profile.user?.follows.map((f) => ({
icon: f.community.icon, icon: f.community.icon,
name: f.community.title, name: f.community.title,
href: `/c/${fullCommunityName( href: `/c/${fullCommunityName(
+14 -9
View File
@@ -6,12 +6,14 @@
import { fade, scale } from 'svelte/transition' import { fade, scale } from 'svelte/transition'
import { focusTrap } from 'svelte-focus-trap' import { focusTrap } from 'svelte-focus-trap'
import Portal from '../popover/Portal.svelte' import Portal from '../popover/Portal.svelte'
import type { ClassValue } from 'svelte/elements'
interface Props { interface Props {
action?: string | undefined action?: string | undefined
open?: boolean open?: boolean
title?: string | undefined title?: string | undefined | null
dismissable?: boolean dismissable?: boolean
class?: ClassValue
customTitle?: import('svelte').Snippet customTitle?: import('svelte').Snippet
children?: import('svelte').Snippet children?: import('svelte').Snippet
actions?: import('svelte').Snippet<[any]> actions?: import('svelte').Snippet<[any]>
@@ -29,6 +31,7 @@
actions, actions,
ondismissed, ondismissed,
onaction, onaction,
class: clazz = '',
}: Props = $props() }: Props = $props()
let el: any = $state() let el: any = $state()
@@ -65,7 +68,7 @@ bg-white/50 dark:bg-black/50 box-border p-4"
dark:border-zinc-900 dark:border-t-zinc-800 dark:border-b-zinc-900 dark:border-zinc-900 dark:border-t-zinc-800 dark:border-b-zinc-900
rounded-2xl max-w-lg box-border mx-auto overscroll-contain shadow-lg overflow-auto rounded-2xl max-w-lg box-border mx-auto overscroll-contain shadow-lg overflow-auto
p-5 flex flex-col gap-2 dark:bg-zinc-925 p-5 flex flex-col gap-2 dark:bg-zinc-925
bg-white relative" bg-white relative {clazz}"
> >
{#if dismissable} {#if dismissable}
<Button <Button
@@ -82,13 +85,15 @@ bg-white/50 dark:bg-black/50 box-border p-4"
{/snippet} {/snippet}
</Button> </Button>
{/if} {/if}
<h1 class="font-semibold text-xl max-w-full"> {#if title !== null}
{#if customTitle} <h1 class="font-semibold text-xl max-w-full">
{@render customTitle?.()} {#if customTitle}
{:else if title} {@render customTitle?.()}
{title} {:else if title}
{/if} {title}
</h1> {/if}
</h1>
{/if}
{@render children?.()} {@render children?.()}
{#if action} {#if action}
<div class="mt-2 flex w-full"> <div class="mt-2 flex w-full">