feat: add accounts to command palette
This commit is contained in:
1 parent
b8f08dcaaa
commit
1c134d0b12
3 files changed
+42
-10
No files matched your search
@@ -28,7 +28,12 @@
|
||||
<Icon src={action.icon ?? QuestionMarkCircle} size="20" />
|
||||
{/if}
|
||||
<slot />
|
||||
<span class="mr-auto">{action.name}</span>
|
||||
<span class="mr-auto inline-flex flex-col">
|
||||
<span>{action.name}</span>
|
||||
{#if action.detail}
|
||||
<span class="font-normal text-xs">{action.detail}</span>
|
||||
{/if}
|
||||
</span>
|
||||
{#if action.shortcut}
|
||||
<div class="flex items-center gap-0.5 text-xs font-medium">
|
||||
⌘ {action.shortcut}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import CommandItem from './CommandItem.svelte'
|
||||
import { browser } from '$app/environment'
|
||||
import { afterNavigate, goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth'
|
||||
import { profile, profileData } from '$lib/auth'
|
||||
import { getGroups, type Action, type Group } from './actions'
|
||||
|
||||
export let open = false
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
export let groups: Group[] = []
|
||||
|
||||
$: groups = getGroups($resumables, $profile)
|
||||
$: groups = getGroups($resumables, $profile, $profileData.profiles)
|
||||
|
||||
let search = ''
|
||||
let container: HTMLElement
|
||||
@@ -80,7 +80,8 @@
|
||||
...action,
|
||||
score: Math.max(
|
||||
fuzzySearch(action.name, term),
|
||||
fuzzySearch(group.name, term)
|
||||
fuzzySearch(group.name, term),
|
||||
action.detail ? fuzzySearch(action.detail, term) : -1
|
||||
),
|
||||
}))
|
||||
.filter((action) => action.score > 0)
|
||||
@@ -259,10 +260,10 @@
|
||||
<CommandItem
|
||||
{action}
|
||||
on:click={(e) => {
|
||||
if (action.href) {
|
||||
togglePalette()
|
||||
return
|
||||
}
|
||||
if (action.href) {
|
||||
togglePalette()
|
||||
return
|
||||
}
|
||||
e.stopPropagation()
|
||||
handleSelect(action)
|
||||
}}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { Profile } from '$lib/auth'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import { setUserID, type Profile } from '$lib/auth'
|
||||
import {
|
||||
amModOfAny,
|
||||
isAdmin,
|
||||
@@ -41,6 +43,7 @@ import {
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
ChatBubbleLeftRight,
|
||||
} from 'svelte-hero-icons'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export interface Group {
|
||||
name: string
|
||||
@@ -55,9 +58,14 @@ export interface Action {
|
||||
shortcut?: string
|
||||
icon: string | IconSource
|
||||
subActions?: Action[]
|
||||
detail?: string
|
||||
}
|
||||
|
||||
export function getGroups(resumables: ResumableItem[], profile: Profile) {
|
||||
export function getGroups(
|
||||
resumables: ResumableItem[],
|
||||
profile: Profile,
|
||||
profiles: Profile[]
|
||||
) {
|
||||
return [
|
||||
{
|
||||
name: t.get('nav.commands.recents'),
|
||||
@@ -263,6 +271,23 @@ export function getGroups(resumables: ResumableItem[], profile: Profile) {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('account.accounts'),
|
||||
actions: profiles.map((p) => ({
|
||||
name: p.username ?? t.get('account.guest'),
|
||||
icon: p.avatar ?? UserCircle,
|
||||
detail: p.instance,
|
||||
handle: async () => {
|
||||
if (profile.id != p.id) {
|
||||
await setUserID(p.id)
|
||||
}
|
||||
|
||||
await goto(get(page).url, {
|
||||
invalidateAll: true,
|
||||
})
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.menu.app'),
|
||||
actions: [
|
||||
@@ -375,6 +400,7 @@ export function getGroups(resumables: ResumableItem[], profile: Profile) {
|
||||
f.community.name,
|
||||
f.community.actor_id
|
||||
)}`,
|
||||
detail: new URL(f.community.actor_id).hostname,
|
||||
})) ?? [],
|
||||
},
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user