From 9e7f4e80bd8cbf43a97bcdec77ece0c2f649bbd5 Mon Sep 17 00:00:00 2001 From: Aslam H Date: Mon, 9 Sep 2024 11:00:34 +0700 Subject: [PATCH] fix(palette): slice 10 and default to show only home --- .../command-palette/command-palette.tsx | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/web/components/custom/command-palette/command-palette.tsx b/web/components/custom/command-palette/command-palette.tsx index ac4033ff..4e2fd40c 100644 --- a/web/components/custom/command-palette/command-palette.tsx +++ b/web/components/custom/command-palette/command-palette.tsx @@ -5,7 +5,7 @@ import { Dialog, DialogPortal, DialogHeader, DialogTitle, DialogDescription } fr import { CommandGroup } from "./command-items" import { CommandAction, CommandItemType, createCommandGroups } from "./command-data" import { useAccount } from "@/lib/providers/jazz-provider" -import { searchSafeRegExp, toTitleCase } from "@/lib/utils" +import { searchSafeRegExp } from "@/lib/utils" import { GraphNode } from "@/components/routes/public/PublicHomeRoute" import { useCommandActions } from "./hooks/use-command-actions" import { atom, useAtom } from "jotai" @@ -13,7 +13,7 @@ import { atom, useAtom } from "jotai" const graph_data_promise = import("@/components/routes/public/graph-data.json").then(a => a.default) const filterItems = (items: CommandItemType[], searchRegex: RegExp) => - items.filter(item => searchRegex.test(item.value)).slice(0, 6) + items.filter(item => searchRegex.test(item.value)).slice(0, 10) export const commandPaletteOpenAtom = atom(false) @@ -115,24 +115,23 @@ export function CommandPalette() { const searchRegex = searchSafeRegExp(inputValue) if (activePage === "home") { - const filteredGroups = Object.entries(commandGroups) - .map(([key, groups]) => { - return groups.map(group => ({ - heading: group.heading, - items: filterItems(group.items, searchRegex) - })) - }) - .flat() + if (!inputValue) { + // Only show items from the home object when there's no search input + return commandGroups.home + } - const additionalGroups = [ - { heading: personalLinks.heading, items: filterItems(personalLinks.items, searchRegex) }, - { heading: personalPages.heading, items: filterItems(personalPages.items, searchRegex) }, - { heading: topics.heading, items: filterItems(topics.items, searchRegex) } - ] + // When there's a search input, search across all categories + const allGroups = [...Object.values(commandGroups).flat(), personalLinks, personalPages, topics] - return [...filteredGroups, ...additionalGroups].filter(group => group.items.length > 0) + return allGroups + .map(group => ({ + heading: group.heading, + items: filterItems(group.items, searchRegex) + })) + .filter(group => group.items.length > 0) } + // Handle other active pages (searchLinks, searchPages, etc.) switch (activePage) { case "searchLinks": return [...commandGroups.searchLinks, { items: filterItems(personalLinks.items, searchRegex) }]