mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-19 13:51:47 +00:00
Add global Ctrl+K command palette for navigation and search.
Provides quick access to sidebar destinations, org switching, server-filtered entity lookup, and common actions from anywhere in the authenticated layout.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"use client";
|
||||
|
||||
import { ListUserOrgsResponse } from "@server/routers/org";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export type OrganizationCommand = {
|
||||
id: string;
|
||||
orgId: string;
|
||||
name: string;
|
||||
isPrimaryOrg?: boolean;
|
||||
href: string;
|
||||
};
|
||||
|
||||
export function useCommandPaletteOrganizations(
|
||||
orgs: ListUserOrgsResponse["orgs"] | undefined
|
||||
): OrganizationCommand[] {
|
||||
const pathname = usePathname();
|
||||
|
||||
return useMemo(() => {
|
||||
if (!orgs?.length) return [];
|
||||
|
||||
const sortedOrgs = [...orgs].sort((a, b) => {
|
||||
const aPrimary = Boolean(a.isPrimaryOrg);
|
||||
const bPrimary = Boolean(b.isPrimaryOrg);
|
||||
if (aPrimary && !bPrimary) return -1;
|
||||
if (!aPrimary && bPrimary) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
return sortedOrgs.map((org) => {
|
||||
const newPath = pathname.includes("/settings/")
|
||||
? pathname.replace(/^\/[^/]+/, `/${org.orgId}`)
|
||||
: `/${org.orgId}`;
|
||||
|
||||
return {
|
||||
id: `org-${org.orgId}`,
|
||||
orgId: org.orgId,
|
||||
name: org.name,
|
||||
isPrimaryOrg: org.isPrimaryOrg,
|
||||
href: newPath
|
||||
};
|
||||
});
|
||||
}, [orgs, pathname]);
|
||||
}
|
||||
Reference in New Issue
Block a user