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" />
|
<Icon src={action.icon ?? QuestionMarkCircle} size="20" />
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
<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}
|
{#if action.shortcut}
|
||||||
<div class="flex items-center gap-0.5 text-xs font-medium">
|
<div class="flex items-center gap-0.5 text-xs font-medium">
|
||||||
⌘ {action.shortcut}
|
⌘ {action.shortcut}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
import CommandItem from './CommandItem.svelte'
|
import CommandItem from './CommandItem.svelte'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { afterNavigate, goto } from '$app/navigation'
|
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'
|
import { getGroups, type Action, type Group } from './actions'
|
||||||
|
|
||||||
export let open = false
|
export let open = false
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
export let groups: Group[] = []
|
export let groups: Group[] = []
|
||||||
|
|
||||||
$: groups = getGroups($resumables, $profile)
|
$: groups = getGroups($resumables, $profile, $profileData.profiles)
|
||||||
|
|
||||||
let search = ''
|
let search = ''
|
||||||
let container: HTMLElement
|
let container: HTMLElement
|
||||||
@@ -80,7 +80,8 @@
|
|||||||
...action,
|
...action,
|
||||||
score: Math.max(
|
score: Math.max(
|
||||||
fuzzySearch(action.name, term),
|
fuzzySearch(action.name, term),
|
||||||
fuzzySearch(group.name, term)
|
fuzzySearch(group.name, term),
|
||||||
|
action.detail ? fuzzySearch(action.detail, term) : -1
|
||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
.filter((action) => action.score > 0)
|
.filter((action) => action.score > 0)
|
||||||
@@ -259,10 +260,10 @@
|
|||||||
<CommandItem
|
<CommandItem
|
||||||
{action}
|
{action}
|
||||||
on:click={(e) => {
|
on:click={(e) => {
|
||||||
if (action.href) {
|
if (action.href) {
|
||||||
togglePalette()
|
togglePalette()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
handleSelect(action)
|
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 {
|
import {
|
||||||
amModOfAny,
|
amModOfAny,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
@@ -41,6 +43,7 @@ import {
|
|||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
ChatBubbleLeftRight,
|
ChatBubbleLeftRight,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export interface Group {
|
export interface Group {
|
||||||
name: string
|
name: string
|
||||||
@@ -55,9 +58,14 @@ export interface Action {
|
|||||||
shortcut?: string
|
shortcut?: string
|
||||||
icon: string | IconSource
|
icon: string | IconSource
|
||||||
subActions?: Action[]
|
subActions?: Action[]
|
||||||
|
detail?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGroups(resumables: ResumableItem[], profile: Profile) {
|
export function getGroups(
|
||||||
|
resumables: ResumableItem[],
|
||||||
|
profile: Profile,
|
||||||
|
profiles: Profile[]
|
||||||
|
) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: t.get('nav.commands.recents'),
|
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'),
|
name: t.get('nav.menu.app'),
|
||||||
actions: [
|
actions: [
|
||||||
@@ -375,6 +400,7 @@ export function getGroups(resumables: ResumableItem[], profile: Profile) {
|
|||||||
f.community.name,
|
f.community.name,
|
||||||
f.community.actor_id
|
f.community.actor_id
|
||||||
)}`,
|
)}`,
|
||||||
|
detail: new URL(f.community.actor_id).hostname,
|
||||||
})) ?? [],
|
})) ?? [],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in new issue
Block a user