⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat: implement global search functionality
Andrej Acevskif840ec79269d
diff --git a/apps/api/src/index.ts b/apps/api/src/index.tsindex 2a88636b3..633197308 100644--- a/apps/api/src/index.ts+++ b/apps/api/src/index.ts@@ -12,6 +12,7 @@ import { auth } from "./middlewares/auth";import notification from "./notification";import project from "./project";import { getPublicProject } from "./project/controllers/get-public-project";+import search from "./search";import task from "./task";import timeEntry from "./time-entry";import user from "./user";@@ -98,6 +99,7 @@ const activityRoute = app.route("/activity", activity);const timeEntryRoute = app.route("/time-entry", timeEntry);const labelRoute = app.route("/label", label);const notificationRoute = app.route("/notification", notification);+const searchRoute = app.route("/search", search);try {console.log("Migrating database...");@@ -129,6 +131,7 @@ export type AppType =| typeof timeEntryRoute| typeof labelRoute| typeof notificationRoute+ | typeof searchRoute| typeof publicProjectRoute| typeof githubIntegrationRoute| typeof configRoute;diff --git a/apps/api/src/search/controllers/global-search.ts b/apps/api/src/search/controllers/global-search.tsnew file mode 100644index 000000000..3108280e3--- /dev/null+++ b/apps/api/src/search/controllers/global-search.ts@@ -0,0 +1,340 @@+import { and, desc, eq, ilike, or, sql } from "drizzle-orm";+import db from "../../database";+import {+ activityTable,+ projectTable,+ taskTable,+ userTable,+ workspaceTable,+ workspaceUserTable,+} from "../../database/schema";++type SearchParams = {+ query: string;+ userEmail: string;+ type?:+ | "all"+ | "tasks"+ | "projects"+ | "workspaces"+ | "comments"+ | "activities";+ workspaceId?: string;+ projectId?: string;+ limit?: number;+};++type SearchResult = {+ id: string;+ type: "task" | "project" | "workspace" | "comment" | "activity";+ title: string;+ description?: string;+ content?: string;+ projectId?: string;+ projectName?: string;+ workspaceId?: string;+ workspaceName?: string;+ userEmail?: string;+ userName?: string;+ createdAt: Date;+ relevanceScore: number;+ taskNumber?: number;+ projectSlug?: string;+ priority?: string;+ status?: string;+};++async function globalSearch(params: SearchParams): Promise<{+ results: SearchResult[];+ totalCount: number;+ searchQuery: string;+}> {+ const {+ query,+ userEmail,+ type = "all",+ workspaceId,+ projectId,+ limit = 20,+ } = params;++ const userWorkspaces = await db+ .select({ workspaceId: workspaceUserTable.workspaceId })+ .from(workspaceUserTable)+ .where(eq(workspaceUserTable.userEmail, userEmail));++ const accessibleWorkspaceIds = userWorkspaces+ .map((w) => w.workspaceId)+ .filter(Boolean);++ if (accessibleWorkspaceIds.length === 0) {+ return { results: [], totalCount: 0, searchQuery: query };+ }++ const results: SearchResult[] = [];+ const searchPattern = `%${query.toLowerCase()}%`;++ const workspaceFilter = workspaceId+ ? eq(projectTable.workspaceId, workspaceId)+ : sql`${projectTable.workspaceId} IN ${accessibleWorkspaceIds}`;++ if (type === "all" || type === "tasks") {+ const taskRelevanceScore = sql<number>`+ CASE+ WHEN LOWER(${taskTable.title}) LIKE ${searchPattern} THEN 3+ WHEN LOWER(${taskTable.description}) LIKE ${searchPattern} THEN 2+ ELSE 1+ END+ `;++ const taskQuery = db+ .select({+ id: taskTable.id,+ title: taskTable.title,+ description: taskTable.description,+ projectId: taskTable.projectId,+ projectName: projectTable.name,+ projectSlug: projectTable.slug,+ workspaceId: projectTable.workspaceId,+ workspaceName: workspaceTable.name,+ userEmail: taskTable.userEmail,+ userName: userTable.name,+ createdAt: taskTable.createdAt,+ taskNumber: taskTable.number,+ priority: taskTable.priority,+ status: taskTable.status,+ relevanceScore: taskRelevanceScore.as("relevanceScore"),+ })+ .from(taskTable)+ .leftJoin(projectTable, eq(taskTable.projectId, projectTable.id))+ .leftJoin(workspaceTable, eq(projectTable.workspaceId, workspaceTable.id))+ .leftJoin(userTable, eq(taskTable.userEmail, userTable.email))+ .where(+ and(+ workspaceFilter,+ projectId ? eq(taskTable.projectId, projectId) : undefined,+ or(+ ilike(taskTable.title, searchPattern),+ ilike(taskTable.description, searchPattern),+ ),+ ),+ )+ .orderBy(desc(taskRelevanceScore), desc(taskTable.createdAt))+ .limit(limit);++ const tasks = await taskQuery;++ for (const task of tasks) {+ results.push({+ id: task.id,+ type: "task",+ title: task.title,+ description: task.description || undefined,+ projectId: task.projectId,+ projectName: task.projectName || undefined,+ projectSlug: task.projectSlug || undefined,+ workspaceId: task.workspaceId || undefined,+ workspaceName: task.workspaceName || undefined,+ userEmail: task.userEmail || undefined,+ userName: task.userName || undefined,+ createdAt: task.createdAt,+ relevanceScore: task.relevanceScore,+ taskNumber: task.taskNumber || undefined,+ priority: task.priority || undefined,+ status: task.status,+ });+ }+ }++ if (type === "all" || type === "projects") {+ const projectRelevanceScore = sql<number>`+ CASE+ WHEN LOWER(${projectTable.name}) LIKE ${searchPattern} THEN 3+ WHEN LOWER(${projectTable.description}) LIKE ${searchPattern} THEN 2+ ELSE 1+ END+ `;++ const projectQuery = db+ .select({+ id: projectTable.id,+ name: projectTable.name,+ description: projectTable.description,+ slug: projectTable.slug,+ workspaceId: projectTable.workspaceId,+ workspaceName: workspaceTable.name,+ createdAt: projectTable.createdAt,+ relevanceScore: projectRelevanceScore.as("relevanceScore"),+ })+ .from(projectTable)+ .leftJoin(workspaceTable, eq(projectTable.workspaceId, workspaceTable.id))+ .where(+ and(+ workspaceFilter,+ or(+ ilike(projectTable.name, searchPattern),+ ilike(projectTable.description, searchPattern),+ ),+ ),+ )+ .orderBy(desc(projectRelevanceScore), desc(projectTable.createdAt))+ .limit(limit);++ const projects = await projectQuery;++ for (const project of projects) {+ results.push({+ id: project.id,+ type: "project",+ title: project.name,+ description: project.description || undefined,+ projectId: project.id,+ projectSlug: project.slug || undefined,+ workspaceId: project.workspaceId,+ workspaceName: project.workspaceName || undefined,+ createdAt: project.createdAt,+ relevanceScore: project.relevanceScore,+ });+ }+ }++ if (type === "all" || type === "workspaces") {+ const workspaceRelevanceScore = sql<number>`+ CASE+ WHEN LOWER(${workspaceTable.name}) LIKE ${searchPattern} THEN 3+ WHEN LOWER(${workspaceTable.description}) LIKE ${searchPattern} THEN 2+ ELSE 1+ END+ `;++ const workspaceQuery = db+ .select({+ id: workspaceTable.id,+ name: workspaceTable.name,+ description: workspaceTable.description,+ ownerEmail: workspaceTable.ownerEmail,+ createdAt: workspaceTable.createdAt,+ relevanceScore: workspaceRelevanceScore.as("relevanceScore"),+ })+ .from(workspaceTable)+ .leftJoin(+ workspaceUserTable,+ eq(workspaceTable.id, workspaceUserTable.workspaceId),+ )+ .where(+ and(+ sql`${workspaceTable.id} IN ${accessibleWorkspaceIds}`,+ or(+ ilike(workspaceTable.name, searchPattern),+ ilike(workspaceTable.description, searchPattern),+ ),+ ),+ )+ .orderBy(desc(workspaceRelevanceScore), desc(workspaceTable.createdAt))+ .limit(limit);++ const workspaces = await workspaceQuery;++ for (const workspace of workspaces) {+ results.push({+ id: workspace.id,+ type: "workspace",+ title: workspace.name,+ description: workspace.description || undefined,+ workspaceId: workspace.id,+ workspaceName: workspace.name,+ userEmail: workspace.ownerEmail,+ createdAt: workspace.createdAt,+ relevanceScore: workspace.relevanceScore,+ });+ }+ }++ if (type === "all" || type === "comments" || type === "activities") {+ const activityRelevanceScore = sql<number>`+ CASE+ WHEN LOWER(${activityTable.content}) LIKE ${searchPattern} THEN 2+ WHEN LOWER(${taskTable.title}) LIKE ${searchPattern} THEN 1+ ELSE 1+ END+ `;++ const activityQuery = db+ .select({+ id: activityTable.id,+ type: activityTable.type,+ content: activityTable.content,+ taskId: activityTable.taskId,+ taskTitle: taskTable.title,+ taskNumber: taskTable.number,+ projectId: projectTable.id,+ projectName: projectTable.name,+ projectSlug: projectTable.slug,+ workspaceId: projectTable.workspaceId,+ workspaceName: workspaceTable.name,+ userEmail: activityTable.userEmail,+ userName: userTable.name,+ createdAt: activityTable.createdAt,+ relevanceScore: activityRelevanceScore.as("relevanceScore"),+ })+ .from(activityTable)+ .leftJoin(taskTable, eq(activityTable.taskId, taskTable.id))+ .leftJoin(projectTable, eq(taskTable.projectId, projectTable.id))+ .leftJoin(workspaceTable, eq(projectTable.workspaceId, workspaceTable.id))+ .leftJoin(userTable, eq(activityTable.userEmail, userTable.email))+ .where(+ and(+ workspaceFilter,+ projectId ? eq(taskTable.projectId, projectId) : undefined,+ or(+ ilike(activityTable.content, searchPattern),+ ilike(taskTable.title, searchPattern),+ ),+ type === "comments" ? eq(activityTable.type, "comment") : undefined,+ ),+ )+ .orderBy(desc(activityRelevanceScore), desc(activityTable.createdAt))+ .limit(limit);++ const activities = await activityQuery;++ for (const activity of activities) {+ const isComment = activity.type === "comment";+ results.push({+ id: activity.id,+ type: isComment ? "comment" : "activity",+ title: isComment+ ? `Comment on ${activity.taskTitle || "task"}`+ : `${activity.type} on ${activity.taskTitle || "task"}`,+ content: activity.content || undefined,+ projectId: activity.projectId || undefined,+ projectName: activity.projectName || undefined,+ projectSlug: activity.projectSlug || undefined,+ workspaceId: activity.workspaceId || undefined,+ workspaceName: activity.workspaceName || undefined,+ userEmail: activity.userEmail || undefined,+ userName: activity.userName || undefined,+ createdAt: activity.createdAt,+ relevanceScore: activity.relevanceScore,+ taskNumber: activity.taskNumber || undefined,+ });+ }+ }++ results.sort((a, b) => {+ if (a.relevanceScore !== b.relevanceScore) {+ return b.relevanceScore - a.relevanceScore;+ }+ return b.createdAt.getTime() - a.createdAt.getTime();+ });++ const finalResults = results.slice(0, limit);++ return {+ results: finalResults,+ totalCount: results.length,+ searchQuery: query,+ };+}++export default globalSearch;diff --git a/apps/api/src/search/index.ts b/apps/api/src/search/index.tsnew file mode 100644index 000000000..bf7293ed5--- /dev/null+++ b/apps/api/src/search/index.ts@@ -0,0 +1,49 @@+import { zValidator } from "@hono/zod-validator";+import { Hono } from "hono";+import { z } from "zod";+import globalSearch from "./controllers/global-search";++const search = new Hono<{+ Variables: {+ userEmail: string;+ };+}>().get(+ "/",+ zValidator(+ "query",+ z.object({+ q: z.string().min(1),+ type: z+ .enum([+ "all",+ "tasks",+ "projects",+ "workspaces",+ "comments",+ "activities",+ ])+ .optional()+ .default("all"),+ workspaceId: z.string().optional(),+ projectId: z.string().optional(),+ limit: z.coerce.number().min(1).max(50).optional().default(20),+ }),+ ),+ async (c) => {+ const { q, type, workspaceId, projectId, limit } = c.req.valid("query");+ const userEmail = c.get("userEmail");++ const results = await globalSearch({+ query: q,+ userEmail,+ type,+ workspaceId,+ projectId,+ limit,+ });++ return c.json(results);+ },+);++export default search;diff --git a/apps/web/src/components/command-palette/index.tsx b/apps/web/src/components/command-palette/index.tsxindex b9e5ec956..112fe75ca 100644--- a/apps/web/src/components/command-palette/index.tsx+++ b/apps/web/src/components/command-palette/index.tsx@@ -2,6 +2,7 @@ import useTheme from "@/components/providers/theme-provider/hooks/use-theme";import CreateProjectModal from "@/components/shared/modals/create-project-modal";import CreateTaskModal from "@/components/shared/modals/create-task-modal";import CreateWorkspaceModal from "@/components/shared/modals/create-workspace-modal";+import useGlobalSearch from "@/hooks/queries/search/use-global-search";import { cn } from "@/lib/cn";import useProjectStore from "@/store/project";import useWorkspaceStore from "@/store/workspace";@@ -11,14 +12,20 @@ import { motion } from "framer-motion";import { AnimatePresence } from "framer-motion";import {CommandIcon,+ FileText,+ FolderOpen,+ Globe,+ Hash,LayoutDashboard,ListTodo,+ MessageCircle,Monitor,Moon,Plus,Search,Settings,Sun,+ Users,} from "lucide-react";import { useEffect, useState } from "react";import CommandGroup from "./command-group";@@ -28,6 +35,8 @@ export function CommandPalette() {const [isCreateProjectOpen, setIsCreateProjectOpen] = useState(false);const [isCreateTaskOpen, setIsCreateTaskOpen] = useState(false);const [isCreateWorkspaceOpen, setIsCreateWorkspaceOpen] = useState(false);+ const [searchValue, setSearchValue] = useState("");+ const [isGlobalSearch, setIsGlobalSearch] = useState(true);const [pendingAction, setPendingAction] = useState<{type: "task" | "project" | "workspace";status?: string;@@ -37,6 +46,15 @@ export function CommandPalette() {const { theme, setTheme } = useTheme();const navigate = useNavigate();+ const searchQuery = useGlobalSearch({+ q: searchValue,+ workspaceId: isGlobalSearch ? undefined : workspace?.id,+ limit: 10,+ });++ const searchResults = searchQuery.data?.results || [];+ const hasSearchResults = searchValue.length > 2 && searchResults.length > 0;+const commandItemStyles = cn("px-3 py-2 rounded-lg cursor-pointer flex items-center gap-3","text-sm text-zinc-900 dark:text-zinc-100",@@ -81,6 +99,13 @@ export function CommandPalette() {return () => document.removeEventListener("keydown", down);}, []);+ useEffect(() => {+ if (!open) {+ setSearchValue("");+ setIsGlobalSearch(true);+ }+ }, [open]);+return (<><AnimatePresence>@@ -109,6 +134,7 @@ export function CommandPalette() {open={open}onOpenChange={setOpen}label="Global Command Menu"+ shouldFilter={false}className={cn("fixed top-[20vh] left-1/2 -translate-x-1/2 max-w-[640px] w-full p-4 rounded-xl z-50","bg-white dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-800",@@ -125,180 +151,309 @@ export function CommandPalette() {"data-[state=open]:slide-in-from-top-[48%]",)}>- <div className="flex items-center gap-4 px-3 pb-4 mb-4 border-b border-zinc-200 dark:border-zinc-800">- <Search className="w-5 h-5 text-zinc-500 dark:text-zinc-400" />- <Command.Input- placeholder="Type a command or search..."- className={cn(- "w-full outline-none bg-transparent",- "text-zinc-900 dark:text-zinc-100 placeholder:text-zinc-500 dark:placeholder:text-zinc-400",- )}- />- <kbd className="hidden sm:inline-flex items-center gap-1 px-2 py-0.5 text-xs font-mono text-zinc-600 dark:text-zinc-400 rounded border border-zinc-300 dark:border-zinc-700 bg-zinc-50 dark:bg-zinc-800">- <CommandIcon className="w-3 h-3" />K- </kbd>+ <div className="px-3 pb-4 mb-4 border-b border-zinc-200 dark:border-zinc-800">+ <div className="flex items-center gap-4 mb-3">+ <Search className="w-5 h-5 text-zinc-500 dark:text-zinc-400" />+ <Command.Input+ placeholder="Type a command or search..."+ value={searchValue}+ onValueChange={setSearchValue}+ className={cn(+ "w-full outline-none bg-transparent",+ "text-zinc-900 dark:text-zinc-100 placeholder:text-zinc-500 dark:placeholder:text-zinc-400",+ )}+ />+ <kbd className="hidden sm:inline-flex items-center gap-1 px-2 py-0.5 text-xs font-mono text-zinc-600 dark:text-zinc-400 rounded border border-zinc-300 dark:border-zinc-700 bg-zinc-50 dark:bg-zinc-800">+ <CommandIcon className="w-3 h-3" />K+ </kbd>+ </div>++ {/* Search scope toggle */}+ {searchValue.length > 2 && (+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-2">+ <button+ type="button"+ onClick={() => setIsGlobalSearch(!isGlobalSearch)}+ className={cn(+ "flex items-center gap-1.5 px-2 py-1 rounded-md text-xs transition-colors",+ isGlobalSearch+ ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300"+ : "bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-400 hover:bg-zinc-200 dark:hover:bg-zinc-700",+ )}+ >+ {isGlobalSearch ? (+ <Globe className="w-3 h-3" />+ ) : (+ <Users className="w-3 h-3" />+ )}+ {isGlobalSearch+ ? "All workspaces"+ : workspace?.name || "Current workspace"}+ </button>+ </div>+ <div className="text-xs text-zinc-500 dark:text-zinc-400">+ {searchResults.length} result+ {searchResults.length !== 1 ? "s" : ""}+ </div>+ </div>+ )}</div><Command.List className="max-h-[300px] overflow-y-auto px-3"><Command.Empty className="py-6 text-center text-sm text-zinc-500 dark:text-zinc-400">No results found.</Command.Empty>- <CommandGroup heading="Tasks">- <Command.Item- onSelect={() => {- setOpen(false);- setPendingAction({ type: "task", status: "to-do" });- }}- disabled={!project}- className={commandItemStyles}- >- <Plus className="w-4 h-4" />- Create new task- {!project && (- <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">- Select a project first- </span>- )}- </Command.Item>- </CommandGroup>- <CommandGroup heading="Projects" className="mt-4">- <Command.Item- onSelect={() => {- setOpen(false);- setPendingAction({ type: "project" });- }}- disabled={!workspace}- className={commandItemStyles}- >- <Plus className="w-4 h-4" />- Create new project- {!workspace && (- <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">- Select a workspace first- </span>- )}- </Command.Item>- </CommandGroup>+ {/* Search Results */}+ {hasSearchResults && (+ <CommandGroup heading="Search Results">+ {searchResults.map((result) => {+ const getIcon = () => {+ switch (result.type) {+ case "task":+ return <Hash className="w-4 h-4" />;+ case "project":+ return <FolderOpen className="w-4 h-4" />;+ case "workspace":+ return <Users className="w-4 h-4" />;+ case "comment":+ return <MessageCircle className="w-4 h-4" />;+ case "activity":+ return <FileText className="w-4 h-4" />;+ default:+ return <Search className="w-4 h-4" />;+ }+ };- <CommandGroup heading="Project" className="mt-4">- {project && (- <Command.Item- onSelect={() => {- navigate({- to: "/dashboard/workspace/$workspaceId/project/$projectId/board",- params: {- workspaceId: workspace?.id ?? "",- projectId: project.id,- },- });+ const handleSelect = () => {setOpen(false);- }}- className={commandItemStyles}- >- <LayoutDashboard className="w-4 h-4" />- Go to Board- </Command.Item>- )}+ if (+ result.type === "task" &&+ result.projectId &&+ result.workspaceId+ ) {+ navigate({+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",+ params: {+ workspaceId: result.workspaceId,+ projectId: result.projectId,+ taskId: result.id,+ },+ });+ } else if (+ result.type === "project" &&+ result.workspaceId+ ) {+ navigate({+ to: "/dashboard/workspace/$workspaceId/project/$projectId/board",+ params: {+ workspaceId: result.workspaceId,+ projectId: result.id,+ },+ });+ } else if (result.type === "workspace") {+ navigate({+ to: "/dashboard/workspace/$workspaceId",+ params: {+ workspaceId: result.id,+ },+ });+ }+ };- {project && (- <Command.Item- className={commandItemStyles}- onSelect={() => {- navigate({- to: "/dashboard/workspace/$workspaceId/project/$projectId/backlog",- params: {- workspaceId: workspace?.id ?? "",- projectId: project?.id ?? "",- },- });- setOpen(false);- }}- >- <ListTodo className="w-4 h-4" />- Go to Backlog- </Command.Item>- )}+ return (+ <Command.Item+ key={result.id}+ onSelect={handleSelect}+ className={commandItemStyles}+ >+ {getIcon()}+ <div className="flex-1 min-w-0">+ <div className="font-medium text-sm truncate">+ {result.title}+ {result.taskNumber && ` #${result.taskNumber}`}+ </div>+ {result.content && (+ <div className="text-xs text-zinc-500 dark:text-zinc-400 truncate">+ {result.content}+ </div>+ )}+ </div>+ <div className="text-xs text-zinc-500 dark:text-zinc-400 ml-2">+ {result.projectName && (+ <span className="bg-zinc-100 dark:bg-zinc-800 px-2 py-0.5 rounded">+ {result.projectName}+ </span>+ )}+ </div>+ </Command.Item>+ );+ })}+ </CommandGroup>+ )}- {project && (- <Command.Item- onSelect={() => {- setOpen(false);- navigate({- to: "/dashboard/workspace/$workspaceId/project/$projectId/settings",- params: {- workspaceId: workspace?.id ?? "",- projectId: project.id,- },- });- }}- className={commandItemStyles}- >- <Settings className="w-4 h-4" />- Project settings- </Command.Item>- )}- </CommandGroup>+ {/* Regular Commands - only show when no search or no search results */}+ {!hasSearchResults && (+ <>+ <CommandGroup heading="Tasks">+ <Command.Item+ onSelect={() => {+ setOpen(false);+ setPendingAction({ type: "task", status: "to-do" });+ }}+ disabled={!project}+ className={commandItemStyles}+ >+ <Plus className="w-4 h-4" />+ Create new task+ {!project && (+ <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">+ Select a project first+ </span>+ )}+ </Command.Item>+ </CommandGroup>- <CommandGroup heading="Workspace" className="mt-4">- <Command.Item- onSelect={() => {- setOpen(false);- setPendingAction({ type: "workspace" });- }}- className={commandItemStyles}- >- <Plus className="w-4 h-4" />- Create new workspace- </Command.Item>- </CommandGroup>+ <CommandGroup heading="Projects" className="mt-4">+ <Command.Item+ onSelect={() => {+ setOpen(false);+ setPendingAction({ type: "project" });+ }}+ disabled={!workspace}+ className={commandItemStyles}+ >+ <Plus className="w-4 h-4" />+ Create new project+ {!workspace && (+ <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">+ Select a workspace first+ </span>+ )}+ </Command.Item>+ </CommandGroup>- <CommandGroup heading="Appearance" className="mt-4 mb-2">- <Command.Item- onSelect={() => {- setTheme("light");- setOpen(false);- }}- className={commandItemStyles}- >- <Sun className="w-4 h-4" />- Light mode- {theme === "light" && (- <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">- ✓- </span>- )}- </Command.Item>- <Command.Item- onSelect={() => {- setTheme("dark");- setOpen(false);- }}- className={commandItemStyles}- >- <Moon className="w-4 h-4" />- Dark mode- {theme === "dark" && (- <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">- ✓- </span>- )}- </Command.Item>- <Command.Item- onSelect={() => {- setTheme("system");- setOpen(false);- }}- className={commandItemStyles}- >- <Monitor className="w-4 h-4" />- System mode- {theme === "system" && (- <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">- ✓- </span>- )}- </Command.Item>- </CommandGroup>+ <CommandGroup heading="Project" className="mt-4">+ {project && (+ <Command.Item+ onSelect={() => {+ navigate({+ to: "/dashboard/workspace/$workspaceId/project/$projectId/board",+ params: {+ workspaceId: workspace?.id ?? "",+ projectId: project.id,+ },+ });+ setOpen(false);+ }}+ className={commandItemStyles}+ >+ <LayoutDashboard className="w-4 h-4" />+ Go to Board+ </Command.Item>+ )}++ {project && (+ <Command.Item+ className={commandItemStyles}+ onSelect={() => {+ navigate({+ to: "/dashboard/workspace/$workspaceId/project/$projectId/backlog",+ params: {+ workspaceId: workspace?.id ?? "",+ projectId: project?.id ?? "",+ },+ });+ setOpen(false);+ }}+ >+ <ListTodo className="w-4 h-4" />+ Go to Backlog+ </Command.Item>+ )}++ {project && (+ <Command.Item+ onSelect={() => {+ setOpen(false);+ navigate({+ to: "/dashboard/workspace/$workspaceId/project/$projectId/settings",+ params: {+ workspaceId: workspace?.id ?? "",+ projectId: project.id,+ },+ });+ }}+ className={commandItemStyles}+ >+ <Settings className="w-4 h-4" />+ Project settings+ </Command.Item>+ )}+ </CommandGroup>++ <CommandGroup heading="Workspace" className="mt-4">+ <Command.Item+ onSelect={() => {+ setOpen(false);+ setPendingAction({ type: "workspace" });+ }}+ className={commandItemStyles}+ >+ <Plus className="w-4 h-4" />+ Create new workspace+ </Command.Item>+ </CommandGroup>++ <CommandGroup heading="Appearance" className="mt-4 mb-2">+ <Command.Item+ onSelect={() => {+ setTheme("light");+ setOpen(false);+ }}+ className={commandItemStyles}+ >+ <Sun className="w-4 h-4" />+ Light mode+ {theme === "light" && (+ <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">+ ✓+ </span>+ )}+ </Command.Item>+ <Command.Item+ onSelect={() => {+ setTheme("dark");+ setOpen(false);+ }}+ className={commandItemStyles}+ >+ <Moon className="w-4 h-4" />+ Dark mode+ {theme === "dark" && (+ <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">+ ✓+ </span>+ )}+ </Command.Item>+ <Command.Item+ onSelect={() => {+ setTheme("system");+ setOpen(false);+ }}+ className={commandItemStyles}+ >+ <Monitor className="w-4 h-4" />+ System mode+ {theme === "system" && (+ <span className="ml-auto text-xs text-zinc-500 dark:text-zinc-400">+ ✓+ </span>+ )}+ </Command.Item>+ </CommandGroup>+ </>+ )}</Command.List></Command.Dialog></motion.div>diff --git a/apps/web/src/fetchers/search/global-search.ts b/apps/web/src/fetchers/search/global-search.tsnew file mode 100644index 000000000..99587cade--- /dev/null+++ b/apps/web/src/fetchers/search/global-search.ts@@ -0,0 +1,37 @@+import { client } from "@kaneo/libs";++type SearchParams = {+ q: string;+ type?:+ | "all"+ | "tasks"+ | "projects"+ | "workspaces"+ | "comments"+ | "activities";+ workspaceId?: string;+ projectId?: string;+ limit?: number;+};++async function globalSearch(params: SearchParams) {+ const queryParams = {+ ...params,+ limit: params.limit?.toString(),+ };++ const response = await client.search.$get({+ query: queryParams,+ });++ if (!response.ok) {+ const error = await response.text();+ throw new Error(error);+ }++ const data = await response.json();++ return data;+}++export default globalSearch;diff --git a/apps/web/src/hooks/queries/search/use-global-search.ts b/apps/web/src/hooks/queries/search/use-global-search.tsnew file mode 100644index 000000000..641c471b7--- /dev/null+++ b/apps/web/src/hooks/queries/search/use-global-search.ts@@ -0,0 +1,27 @@+import globalSearch from "@/fetchers/search/global-search";+import { useQuery } from "@tanstack/react-query";++type SearchParams = {+ q: string;+ type?:+ | "all"+ | "tasks"+ | "projects"+ | "workspaces"+ | "comments"+ | "activities";+ workspaceId?: string;+ projectId?: string;+ limit?: number;+};++function useGlobalSearch(params: SearchParams) {+ return useQuery({+ queryKey: ["search", params],+ queryFn: () => globalSearch(params),+ enabled: !!params.q && params.q.length > 2,+ staleTime: 1000 * 30, // 30 seconds+ });+}++export default useGlobalSearch;