Files
supabase/packages/ui-patterns/CommandMenu/prepackaged/DocsAi/index.tsx
T
Charis 84732ff44c feat: add new command menu to studio (#28432)
Add new command menu to studio. Ports over commands from old menu (with some minor reorganization), then adds:
- Branch switcher
- Project switcher
2024-08-08 16:42:07 -04:00

41 lines
1.0 KiB
TypeScript

import { AiIconAnimation } from 'ui'
import { useRegisterCommands } from '../../api/hooks/commandsHooks'
import { useRegisterPage, useSetPage } from '../../api/hooks/pagesHooks'
import type { ICommand, CommandOptions } from '../../api/types'
import { PageType } from '../../api/utils'
import { DocsAiPage } from './DocsAiPage'
const DOCS_AI_COMMANDS = {
PAGE_NAME: 'Ask Supabase AI',
SECTION_NAME: 'Docs',
}
const identity = <T,>(x: T) => x
const useDocsAiCommands = ({
modify = identity,
options,
}: { modify?: (command: ICommand) => ICommand; options?: CommandOptions } = {}) => {
const setCommandPage = useSetPage()
useRegisterPage(DOCS_AI_COMMANDS.PAGE_NAME, { type: PageType.Component, component: DocsAiPage })
useRegisterCommands(
DOCS_AI_COMMANDS.SECTION_NAME,
[
{
id: 'ai-docs',
name: 'Ask Supabase AI',
action: () => {
setCommandPage(DOCS_AI_COMMANDS.PAGE_NAME, true)
},
icon: () => <AiIconAnimation />,
},
].map(modify),
options
)
}
export { useDocsAiCommands }