fix(palette): slice 10 and default to show only home

This commit is contained in:
Aslam H
2024-09-09 11:00:34 +07:00
parent 94aac134ea
commit 9e7f4e80bd

View File

@@ -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) }]