mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
fix(palette): slice 10 and default to show only home
This commit is contained in:
@@ -5,7 +5,7 @@ import { Dialog, DialogPortal, DialogHeader, DialogTitle, DialogDescription } fr
|
|||||||
import { CommandGroup } from "./command-items"
|
import { CommandGroup } from "./command-items"
|
||||||
import { CommandAction, CommandItemType, createCommandGroups } from "./command-data"
|
import { CommandAction, CommandItemType, createCommandGroups } from "./command-data"
|
||||||
import { useAccount } from "@/lib/providers/jazz-provider"
|
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 { GraphNode } from "@/components/routes/public/PublicHomeRoute"
|
||||||
import { useCommandActions } from "./hooks/use-command-actions"
|
import { useCommandActions } from "./hooks/use-command-actions"
|
||||||
import { atom, useAtom } from "jotai"
|
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 graph_data_promise = import("@/components/routes/public/graph-data.json").then(a => a.default)
|
||||||
|
|
||||||
const filterItems = (items: CommandItemType[], searchRegex: RegExp) =>
|
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)
|
export const commandPaletteOpenAtom = atom(false)
|
||||||
|
|
||||||
@@ -115,24 +115,23 @@ export function CommandPalette() {
|
|||||||
const searchRegex = searchSafeRegExp(inputValue)
|
const searchRegex = searchSafeRegExp(inputValue)
|
||||||
|
|
||||||
if (activePage === "home") {
|
if (activePage === "home") {
|
||||||
const filteredGroups = Object.entries(commandGroups)
|
if (!inputValue) {
|
||||||
.map(([key, groups]) => {
|
// Only show items from the home object when there's no search input
|
||||||
return groups.map(group => ({
|
return commandGroups.home
|
||||||
heading: group.heading,
|
}
|
||||||
items: filterItems(group.items, searchRegex)
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
.flat()
|
|
||||||
|
|
||||||
const additionalGroups = [
|
// When there's a search input, search across all categories
|
||||||
{ heading: personalLinks.heading, items: filterItems(personalLinks.items, searchRegex) },
|
const allGroups = [...Object.values(commandGroups).flat(), personalLinks, personalPages, topics]
|
||||||
{ heading: personalPages.heading, items: filterItems(personalPages.items, searchRegex) },
|
|
||||||
{ heading: topics.heading, items: filterItems(topics.items, searchRegex) }
|
|
||||||
]
|
|
||||||
|
|
||||||
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) {
|
switch (activePage) {
|
||||||
case "searchLinks":
|
case "searchLinks":
|
||||||
return [...commandGroups.searchLinks, { items: filterItems(personalLinks.items, searchRegex) }]
|
return [...commandGroups.searchLinks, { items: filterItems(personalLinks.items, searchRegex) }]
|
||||||
|
|||||||
Reference in New Issue
Block a user