From f38011e0c654d45aa6b3874e2014d4d8b5eba6e4 Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 19 Jul 2024 15:42:44 -0700 Subject: [PATCH] misc: add more links --- .../ui/navbar/commands/CommandItem.svelte | 30 +++++ .../ui/navbar/commands/Commands.svelte | 121 +++++++++--------- src/style/app.css | 5 + 3 files changed, 97 insertions(+), 59 deletions(-) create mode 100644 src/lib/components/ui/navbar/commands/CommandItem.svelte diff --git a/src/lib/components/ui/navbar/commands/CommandItem.svelte b/src/lib/components/ui/navbar/commands/CommandItem.svelte new file mode 100644 index 00000000..9eaca2d9 --- /dev/null +++ b/src/lib/components/ui/navbar/commands/CommandItem.svelte @@ -0,0 +1,30 @@ + + + diff --git a/src/lib/components/ui/navbar/commands/Commands.svelte b/src/lib/components/ui/navbar/commands/Commands.svelte index 6af9ca90..beb79e21 100644 --- a/src/lib/components/ui/navbar/commands/Commands.svelte +++ b/src/lib/components/ui/navbar/commands/Commands.svelte @@ -9,25 +9,23 @@ } from 'mono-svelte' import { createEventDispatcher, onMount } from 'svelte' import { + Bookmark, Icon, + Inbox, PencilSquare, QuestionMarkCircle, + UserCircle, type IconSource, } from 'svelte-hero-icons' import Avatar from '../../Avatar.svelte' + import { t } from '$lib/translations' + import CommandItem from './CommandItem.svelte' + import { browser } from '$app/environment' + import { goto } from '$app/navigation' - let open = true + export let open = false $: if (open) search = '' - onMount(() => { - window.addEventListener('keydown', (e) => { - if (e.key == '/') { - e.preventDefault() - open = !open - } - }) - }) - interface Group { name: string actions: Action[] @@ -53,9 +51,30 @@ href: r.url, })), }, + { + name: $t('profile.profile'), + actions: [ + { + href: '/profile/user', + name: $t('profile.profile'), + icon: UserCircle, + }, + { + href: '/inbox', + name: $t('profile.inbox'), + icon: Inbox, + }, + { + href: '/saved', + name: $t('profile.saved'), + icon: Bookmark, + }, + ], + }, ] let search = '' + let container: HTMLElement const dispatch = createEventDispatcher() let selectedIndex = 0 @@ -63,14 +82,12 @@ group.actions.map((action) => ({ ...action, group: group.name })), ) - $: filteredActions = flattenedActions.filter( - (action) => - action.name.toLowerCase().includes(search.toLowerCase()) || - action.group.toLowerCase().includes(search.toLowerCase()), + $: filteredActions = flattenedActions.filter((action) => + action.name.toLowerCase().includes(search.toLowerCase()), ) function togglePalette() { - open = !open + open = false if (open) { search = '' selectedIndex = 0 @@ -78,9 +95,9 @@ } function handleKeydown(event: KeyboardEvent) { - if (event.ctrlKey && event.key === 'k') { + if ((event.ctrlKey && event.key === 'k') || event.key == '/') { event.preventDefault() - togglePalette() + open = true } if (!open) return @@ -98,8 +115,8 @@ case 'Enter': event.preventDefault() if (filteredActions[selectedIndex]) { + handleSelect(filteredActions[selectedIndex]) dispatch('select', filteredActions[selectedIndex]) - togglePalette() } break case 'Escape': @@ -109,56 +126,42 @@ } } - function handleSelect(action: Action & { group: string }) { + function focusItem(index: number) { + if (!browser) return + + const listItems = container?.querySelectorAll('li') + listItems[index % listItems.length].focus() + } + + async function handleSelect(action: Action & { group: string }) { + if (action.href) await goto(action.href) + if (action.handle) action.handle() dispatch('select', action) - togglePalette() } + + - {#if search == ''} - {#each groups as group} -
+
+ {#if search == ''} + {#each groups as group} {group.name} -
    - {#each group.actions as action} - +
      + {#each group.actions as action, index} + {/each}
    -
- {/each} - {:else} - {#each filteredActions as action} - - {/each} - {/if} + {/each} + {:else} +
    + {#each filteredActions as action, index} + + {/each} +
+ {/if} +
diff --git a/src/style/app.css b/src/style/app.css index 432a24ea..b34672e3 100644 --- a/src/style/app.css +++ b/src/style/app.css @@ -109,3 +109,8 @@ pre { .banner { mask-image: linear-gradient(to left, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); } + +select:focus-visible, a:focus-visible, button:focus-visible { + outline: none; + @apply ring-2 ring-primary-900 dark:ring-primary-100 +} \ No newline at end of file