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

+7 -5
View File
@@ -37,17 +37,19 @@
"prompt": "Command palette", "prompt": "Command palette",
"recents": "Recents", "recents": "Recents",
"content": "Content", "content": "Content",
"search": "Search for {{default}}", "search": "Search for **{{default}}**",
"main": "Main", "main": "Main",
"setView": "Set view", "setView": "Set view",
"setViewTo": "Set view to {{default}}", "setViewTo": "Set view to **{{default}}**",
"setColor": "Set color scheme", "setColor": "Set color scheme",
"setColorTo": "Set color scheme to {{default}}", "setColorTo": "Set color scheme to **{{default}}**",
"feeds": "Feeds", "feeds": "Feeds",
"downloading": "Downloading actions", "downloading": "Downloading actions",
"setTheme": "Set theme", "setTheme": "Set theme",
"setThemeTo": "Set theme to {{default}}", "setThemeTo": "Set theme to **{{default}}**",
"contextual": "On this page" "contextual": "On this page",
"communities": "Communities with **{{default}}**",
"goto": "Go to **{{default}}**"
}, },
"notifications": "Notifications" "notifications": "Notifications"
}, },
@@ -98,6 +98,8 @@ const regexes = {
implicitUser: /^mailto:([a-z0-9_.-]+)@(([\da-z.-]+)\.([a-z]{2,63}))/i, implicitUser: /^mailto:([a-z0-9_.-]+)@(([\da-z.-]+)\.([a-z]{2,63}))/i,
} }
export { regexes as CONTENT_REGEXES }
/** /**
* Convert links to photon links * Convert links to photon links
*/ */
@@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import Markdown from '$lib/app/markdown/Markdown.svelte'
import Avatar from '$lib/ui/generic/Avatar.svelte' import Avatar from '$lib/ui/generic/Avatar.svelte'
import { Button } from 'mono-svelte' import { Button } from 'mono-svelte'
import type { Snippet } from 'svelte' import type { Snippet } from 'svelte'
@@ -25,7 +26,7 @@
alignment="left" alignment="left"
color="none" color="none"
size="custom" size="custom"
class="block w-full" class="px-3! py-2! w-full"
data-sveltekit-preload-code="viewport" data-sveltekit-preload-code="viewport"
data-sveltekit-preload-data="tap" data-sveltekit-preload-data="tap"
{...rest} {...rest}
@@ -42,7 +43,7 @@
{/if} {/if}
{@render children?.()} {@render children?.()}
<div class="inline-flex flex-col"> <div class="inline-flex flex-col">
<span>{action.name}</span> <Markdown inline source={action.name} />
{#if action.detail} {#if action.detail}
<span class="font-normal text-xs">{action.detail}</span> <span class="font-normal text-xs">{action.detail}</span>
{/if} {/if}
+34 -43
View File
@@ -11,8 +11,13 @@
import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte' import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte'
import { TextInput } from 'mono-svelte' import { TextInput } from 'mono-svelte'
import { createEventDispatcher, onMount } from 'svelte' import { createEventDispatcher, onMount } from 'svelte'
import { Home, Icon, MagnifyingGlass } from 'svelte-hero-icons/dist' import { Home, Icon } from 'svelte-hero-icons/dist'
import { type Action, type Group, getGroups } from './actions.svelte' import {
type Action,
type Group,
dynamicActions,
getGroups,
} from './actions.svelte'
import CommandItem from './CommandItem.svelte' import CommandItem from './CommandItem.svelte'
interface Props { interface Props {
@@ -49,10 +54,6 @@
} }
function searchGroup(term: string) { function searchGroup(term: string) {
if (term == '/kill @') {
goto('/you_died')
}
if (term.length < 1) { if (term.length < 1) {
if (breadcrumbs.length <= 0) { if (breadcrumbs.length <= 0) {
filteredGroups = groups.map((group) => ({ filteredGroups = groups.map((group) => ({
@@ -61,31 +62,34 @@
})) }))
} }
} else { } else {
filteredGroups = groups filteredGroups = [
.map((group) => { ...groups
const scoredActions = flattenActions(group.actions) .map((group) => {
.map((action) => ({ const scoredActions = flattenActions(group.actions)
...action, .map((action) => ({
score: Math.max( ...action,
fuzzySearch(action.name, term), score: Math.max(
fuzzySearch(group.name, term), fuzzySearch(action.name, term),
action.detail ? fuzzySearch(action.detail, term) : -1, fuzzySearch(group.name, term),
), action.detail ? fuzzySearch(action.detail, term) : -1,
})) ),
.filter((action) => action.score > 0) }))
.sort((a, b) => b.score - a.score) .filter((action) => action.score > 0)
.sort((a, b) => b.score - a.score)
return { return {
...group, ...group,
actions: scoredActions, actions: scoredActions,
score: Math.max( score: Math.max(
fuzzySearch(group.name, term), fuzzySearch(group.name, term),
...scoredActions.map((a) => a.score), ...scoredActions.map((a) => a.score),
), ),
} }
}) })
.filter((group) => group.actions.length > 0) .filter((group) => group.actions.length > 0)
.sort((a, b) => b.score - a.score) .sort((a, b) => b.score - a.score),
dynamicActions(term),
]
} }
} }
@@ -283,18 +287,5 @@
</CommonList> </CommonList>
</div> </div>
{/each} {/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>
</div> </div>
+25 -2
View File
@@ -26,6 +26,7 @@ import {
Home, Home,
Identification, Identification,
Inbox, Inbox,
MagnifyingGlass,
MapPin, MapPin,
Moon, Moon,
Newspaper, Newspaper,
@@ -68,7 +69,7 @@ export function getGroups(
profiles: ProfileInfo[], profiles: ProfileInfo[],
td: ThemeData, td: ThemeData,
contextual?: Action[], contextual?: Action[],
) { ): Group[] {
return [ return [
{ {
name: t.get('nav.commands.recents'), name: t.get('nav.commands.recents'),
@@ -400,7 +401,7 @@ export function getGroups(
name: t.get('profile.subscribed'), name: t.get('profile.subscribed'),
actions: actions:
profile.user?.follows.map((f) => ({ profile.user?.follows.map((f) => ({
icon: f.community.icon, icon: f.community.icon ?? Newspaper,
name: f.community.title, name: f.community.title,
href: `/c/${fullCommunityName( href: `/c/${fullCommunityName(
f.community.name, 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,
}
}