feat: add global shortcuts

This commit is contained in:
Xylight committed 2024-07-19 18:14:16 -07:00
1 parent f63db02e98
commit 98a597c0d3
2 files changed
+22 -2

No files matched your search

@@ -1,5 +1,5 @@
<script lang="ts">
import { Button } from 'mono-svelte'
import { Button, Material } from 'mono-svelte'
import { Icon, QuestionMarkCircle, type IconSource } from 'svelte-hero-icons'
import Avatar from '../../Avatar.svelte'
@@ -28,4 +28,9 @@
{/if}
<slot />
{action.name}
{#if action.shortcut}
<div class="ml-auto flex items-center gap-0.5 text-xs font-medium">
⌘ {action.shortcut}
</div>
{/if}
</Button>
@@ -66,7 +66,7 @@
{
name: $t('nav.commands.main'),
actions: [
{ href: '/', name: $t('nav.home'), icon: Home },
{ href: '/', name: $t('nav.home'), icon: Home, shortcut: 'h' },
{ href: '/communities', name: $t('nav.communities'), icon: GlobeAlt },
],
},
@@ -82,6 +82,7 @@
href: '/inbox',
name: $t('profile.inbox'),
icon: Inbox,
shortcut: 'i',
},
{
href: '/saved',
@@ -216,6 +217,20 @@
togglePalette()
}
if (event.ctrlKey) {
const actions = groups
.flatMap((g) => g.actions)
.filter((a) => a.shortcut != undefined)
actions.forEach((a) => {
if (event.key === a.shortcut) {
event.preventDefault()
if (a.href) goto(a.href)
if (a.handle) a.handle()
}
})
}
if (!open) return
switch (event.key) {