impr: add community/normal search to command palette

This commit is contained in:
Xylight committed 2025-10-18 12:46:22 -07:00
1 parent 05140f4fc7
commit 7e990381a7
5 files changed
+71 -52

No files matched your search

@@ -1,4 +1,5 @@
<script lang="ts">
import Markdown from '$lib/app/markdown/Markdown.svelte'
import Avatar from '$lib/ui/generic/Avatar.svelte'
import { Button } from 'mono-svelte'
import type { Snippet } from 'svelte'
@@ -25,7 +26,7 @@
alignment="left"
color="none"
size="custom"
class="block w-full"
class="px-3! py-2! w-full"
data-sveltekit-preload-code="viewport"
data-sveltekit-preload-data="tap"
{...rest}
@@ -42,7 +43,7 @@
{/if}
{@render children?.()}
<div class="inline-flex flex-col">
<span>{action.name}</span>
<Markdown inline source={action.name} />
{#if action.detail}
<span class="font-normal text-xs">{action.detail}</span>
{/if}
+34 -43
View File
@@ -11,8 +11,13 @@
import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte'
import { TextInput } from 'mono-svelte'
import { createEventDispatcher, onMount } from 'svelte'
import { Home, Icon, MagnifyingGlass } from 'svelte-hero-icons/dist'
import { type Action, type Group, getGroups } from './actions.svelte'
import { Home, Icon } from 'svelte-hero-icons/dist'
import {
type Action,
type Group,
dynamicActions,
getGroups,
} from './actions.svelte'
import CommandItem from './CommandItem.svelte'
interface Props {
@@ -49,10 +54,6 @@
}
function searchGroup(term: string) {
if (term == '/kill @') {
goto('/you_died')
}
if (term.length < 1) {
if (breadcrumbs.length <= 0) {
filteredGroups = groups.map((group) => ({
@@ -61,31 +62,34 @@
}))
}
} else {
filteredGroups = groups
.map((group) => {
const scoredActions = flattenActions(group.actions)
.map((action) => ({
...action,
score: Math.max(
fuzzySearch(action.name, term),
fuzzySearch(group.name, term),
action.detail ? fuzzySearch(action.detail, term) : -1,
),
}))
.filter((action) => action.score > 0)
.sort((a, b) => b.score - a.score)
filteredGroups = [
...groups
.map((group) => {
const scoredActions = flattenActions(group.actions)
.map((action) => ({
...action,
score: Math.max(
fuzzySearch(action.name, term),
fuzzySearch(group.name, term),
action.detail ? fuzzySearch(action.detail, term) : -1,
),
}))
.filter((action) => action.score > 0)
.sort((a, b) => b.score - a.score)
return {
...group,
actions: scoredActions,
score: Math.max(
fuzzySearch(group.name, term),
...scoredActions.map((a) => a.score),
),
}
})
.filter((group) => group.actions.length > 0)
.sort((a, b) => b.score - a.score)
return {
...group,
actions: scoredActions,
score: Math.max(
fuzzySearch(group.name, term),
...scoredActions.map((a) => a.score),
),
}
})
.filter((group) => group.actions.length > 0)
.sort((a, b) => b.score - a.score),
dynamicActions(term),
]
}
}
@@ -283,18 +287,5 @@
</CommonList>
</div>
{/each}
{#if search != ''}
<CommandItem
action={{
name: search,
href: `/search?q=${encodeURIComponent(search)}`,
icon: MagnifyingGlass,
}}
>
<span class="font-normal text-slate-600 dark:text-zinc-400">
{$t('nav.commands.search', { default: '' })}
</span>
</CommandItem>
{/if}
</div>
</div>
+25 -2
View File
@@ -26,6 +26,7 @@ import {
Home,
Identification,
Inbox,
MagnifyingGlass,
MapPin,
Moon,
Newspaper,
@@ -68,7 +69,7 @@ export function getGroups(
profiles: ProfileInfo[],
td: ThemeData,
contextual?: Action[],
) {
): Group[] {
return [
{
name: t.get('nav.commands.recents'),
@@ -400,7 +401,7 @@ export function getGroups(
name: t.get('profile.subscribed'),
actions:
profile.user?.follows.map((f) => ({
icon: f.community.icon,
icon: f.community.icon ?? Newspaper,
name: f.community.title,
href: `/c/${fullCommunityName(
f.community.name,
@@ -411,3 +412,25 @@ export function getGroups(
},
]
}
// this should really be rewritten, but a temporary change
// to make sure we don't recalculate ALL of that per keypress
export function dynamicActions(query: string): Group {
const actions = [
{
name: t.get('nav.commands.search', { default: query }),
icon: MagnifyingGlass,
href: `/search?q=${query}`,
},
{
name: t.get('nav.commands.communities', { default: query }),
icon: Newspaper,
href: `/explore/communities?q=${query}`,
},
]
return {
name: t.get('routes.search.other'),
actions: actions,
}
}