From 1c134d0b128d8f030f1b4c211a3f8a7ab709e6ee Mon Sep 17 00:00:00 2001 From: Xylight Date: Sun, 21 Jul 2024 17:27:16 -0700 Subject: [PATCH] feat: add accounts to command palette --- .../ui/navbar/commands/CommandItem.svelte | 7 ++++- .../ui/navbar/commands/Commands.svelte | 15 +++++----- .../components/ui/navbar/commands/actions.ts | 30 +++++++++++++++++-- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/lib/components/ui/navbar/commands/CommandItem.svelte b/src/lib/components/ui/navbar/commands/CommandItem.svelte index 8ea873e9..072a32c0 100644 --- a/src/lib/components/ui/navbar/commands/CommandItem.svelte +++ b/src/lib/components/ui/navbar/commands/CommandItem.svelte @@ -28,7 +28,12 @@ {/if} - {action.name} + + {action.name} + {#if action.detail} + {action.detail} + {/if} + {#if action.shortcut}
⌘ {action.shortcut} diff --git a/src/lib/components/ui/navbar/commands/Commands.svelte b/src/lib/components/ui/navbar/commands/Commands.svelte index fb0d8a7d..5004f033 100644 --- a/src/lib/components/ui/navbar/commands/Commands.svelte +++ b/src/lib/components/ui/navbar/commands/Commands.svelte @@ -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 @@ { - if (action.href) { - togglePalette() - return - } + if (action.href) { + togglePalette() + return + } e.stopPropagation() handleSelect(action) }} diff --git a/src/lib/components/ui/navbar/commands/actions.ts b/src/lib/components/ui/navbar/commands/actions.ts index d690661f..10592afd 100644 --- a/src/lib/components/ui/navbar/commands/actions.ts +++ b/src/lib/components/ui/navbar/commands/actions.ts @@ -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, })) ?? [], }, ]