misc: add more links
This commit is contained in:
1 parent
59bb6dde89
commit
f38011e0c6
3 files changed
+97
-59
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Button } from 'mono-svelte'
|
||||||
|
import { Icon, QuestionMarkCircle, type IconSource } from 'svelte-hero-icons'
|
||||||
|
import Avatar from '../../Avatar.svelte'
|
||||||
|
|
||||||
|
export let action: {
|
||||||
|
name: string
|
||||||
|
desc?: string
|
||||||
|
handle?: () => any
|
||||||
|
href?: string
|
||||||
|
shortcut?: string
|
||||||
|
icon: string | IconSource
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
href={action.href}
|
||||||
|
on:click={action.handle}
|
||||||
|
alignment="left"
|
||||||
|
color="tertiary"
|
||||||
|
size="lg"
|
||||||
|
class="focus:bg-slate-200 focus:dark:bg-zinc-800"
|
||||||
|
>
|
||||||
|
{#if typeof action.icon === 'string'}
|
||||||
|
<Avatar url={action.icon} width={20} />
|
||||||
|
{:else}
|
||||||
|
<Icon src={action.icon ?? QuestionMarkCircle} size="20" />
|
||||||
|
{/if}
|
||||||
|
{action.name}
|
||||||
|
</Button>
|
||||||
@@ -9,25 +9,23 @@
|
|||||||
} from 'mono-svelte'
|
} from 'mono-svelte'
|
||||||
import { createEventDispatcher, onMount } from 'svelte'
|
import { createEventDispatcher, onMount } from 'svelte'
|
||||||
import {
|
import {
|
||||||
|
Bookmark,
|
||||||
Icon,
|
Icon,
|
||||||
|
Inbox,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
QuestionMarkCircle,
|
QuestionMarkCircle,
|
||||||
|
UserCircle,
|
||||||
type IconSource,
|
type IconSource,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import Avatar from '../../Avatar.svelte'
|
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 = ''
|
$: if (open) search = ''
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
window.addEventListener('keydown', (e) => {
|
|
||||||
if (e.key == '/') {
|
|
||||||
e.preventDefault()
|
|
||||||
open = !open
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
interface Group {
|
interface Group {
|
||||||
name: string
|
name: string
|
||||||
actions: Action[]
|
actions: Action[]
|
||||||
@@ -53,9 +51,30 @@
|
|||||||
href: r.url,
|
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 search = ''
|
||||||
|
let container: HTMLElement
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
|
|
||||||
@@ -63,14 +82,12 @@
|
|||||||
group.actions.map((action) => ({ ...action, group: group.name })),
|
group.actions.map((action) => ({ ...action, group: group.name })),
|
||||||
)
|
)
|
||||||
|
|
||||||
$: filteredActions = flattenedActions.filter(
|
$: filteredActions = flattenedActions.filter((action) =>
|
||||||
(action) =>
|
action.name.toLowerCase().includes(search.toLowerCase()),
|
||||||
action.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
action.group.toLowerCase().includes(search.toLowerCase()),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
function togglePalette() {
|
function togglePalette() {
|
||||||
open = !open
|
open = false
|
||||||
if (open) {
|
if (open) {
|
||||||
search = ''
|
search = ''
|
||||||
selectedIndex = 0
|
selectedIndex = 0
|
||||||
@@ -78,9 +95,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleKeydown(event: KeyboardEvent) {
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
if (event.ctrlKey && event.key === 'k') {
|
if ((event.ctrlKey && event.key === 'k') || event.key == '/') {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
togglePalette()
|
open = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!open) return
|
if (!open) return
|
||||||
@@ -98,8 +115,8 @@
|
|||||||
case 'Enter':
|
case 'Enter':
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (filteredActions[selectedIndex]) {
|
if (filteredActions[selectedIndex]) {
|
||||||
|
handleSelect(filteredActions[selectedIndex])
|
||||||
dispatch('select', filteredActions[selectedIndex])
|
dispatch('select', filteredActions[selectedIndex])
|
||||||
togglePalette()
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'Escape':
|
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)
|
dispatch('select', action)
|
||||||
togglePalette()
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:window on:keydown={handleKeydown} />
|
||||||
|
|
||||||
<Modal title="Command Prompt" bind:open>
|
<Modal title="Command Prompt" bind:open>
|
||||||
<TextInput bind:value={search} autofocus />
|
<TextInput bind:value={search} autofocus />
|
||||||
{#if search == ''}
|
<div class="space-y-1" bind:this={container}>
|
||||||
{#each groups as group}
|
{#if search == ''}
|
||||||
<div class="space-y-1">
|
{#each groups as group}
|
||||||
<span class="text-slate-700 dark:text-zinc-300 font-medium text-sm">
|
<span class="text-slate-700 dark:text-zinc-300 font-medium text-sm">
|
||||||
{group.name}
|
{group.name}
|
||||||
</span>
|
</span>
|
||||||
<ul class="flex flex-col">
|
<ul class="flex flex-col gap-1">
|
||||||
{#each group.actions as action}
|
{#each group.actions as action, index}
|
||||||
<Button
|
<CommandItem {action} />
|
||||||
href={action.href}
|
|
||||||
on:click={action.handle}
|
|
||||||
alignment="left"
|
|
||||||
color="tertiary"
|
|
||||||
size="lg"
|
|
||||||
>
|
|
||||||
{#if typeof action.icon === 'string'}
|
|
||||||
<Avatar url={action.icon} width={24} />
|
|
||||||
{:else}
|
|
||||||
<Icon src={action.icon ?? QuestionMarkCircle} size="24" mini />
|
|
||||||
{/if}
|
|
||||||
{action.name}
|
|
||||||
</Button>
|
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
{/each}
|
||||||
{/each}
|
{:else}
|
||||||
{:else}
|
<ul class="flex flex-col gap-1">
|
||||||
{#each filteredActions as action}
|
{#each filteredActions as action, index}
|
||||||
<Button
|
<CommandItem {action} />
|
||||||
href={action.href}
|
{/each}
|
||||||
on:click={action.handle}
|
</ul>
|
||||||
alignment="left"
|
{/if}
|
||||||
color="tertiary"
|
</div>
|
||||||
size="lg"
|
|
||||||
>
|
|
||||||
{#if typeof action.icon === 'string'}
|
|
||||||
<Avatar url={action.icon} width={24} />
|
|
||||||
{:else}
|
|
||||||
<Icon src={action.icon ?? QuestionMarkCircle} size="24" mini />
|
|
||||||
{/if}
|
|
||||||
{action.name}
|
|
||||||
</Button>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -109,3 +109,8 @@ pre {
|
|||||||
.banner {
|
.banner {
|
||||||
mask-image: linear-gradient(to left, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
|
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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user