Browse Source

Improve command palette search

pull/66/head
Sacha Weatherstone 3 years ago
parent
commit
e7a5dabdc9
  1. 21
      src/components/CommandPalette/Index.tsx

21
src/components/CommandPalette/Index.tsx

@ -54,6 +54,7 @@ export interface Command {
icon: (props: React.ComponentProps<"svg">) => JSX.Element; icon: (props: React.ComponentProps<"svg">) => JSX.Element;
action?: () => void; action?: () => void;
subItems?: SubItem[]; subItems?: SubItem[];
tags?: string[];
} }
export interface SubItem { export interface SubItem {
@ -117,7 +118,8 @@ export const CommandPalette = (): JSX.Element => {
icon: Cog8ToothIcon, icon: Cog8ToothIcon,
action() { action() {
setActivePage("config"); setActivePage("config");
} },
tags: ["settings"]
}, },
{ {
name: "Channels", name: "Channels",
@ -397,9 +399,24 @@ export const CommandPalette = (): JSX.Element => {
return { return {
...group, ...group,
commands: group.commands.filter((command) => { commands: group.commands.filter((command) => {
return `${group.name} ${command.name}` const nameIncludes = `${group.name} ${command.name}`
.toLowerCase() .toLowerCase()
.includes(query.toLowerCase()); .includes(query.toLowerCase());
const tagsInclude = (
command.tags
?.map((t) => t.includes(query.toLowerCase()))
.filter(Boolean) ?? []
).length;
const subItemsInclude = (
command.subItems
?.map((s) =>
s.name.toLowerCase().includes(query.toLowerCase())
)
.filter(Boolean) ?? []
).length;
return nameIncludes || tagsInclude || subItemsInclude;
}) })
}; };
}) })

Loading…
Cancel
Save