| 1 | import { BlockType } from "@continuedev/config-yaml"; |
| 2 | import { |
| 3 | ArrowTopRightOnSquareIcon, |
| 4 | PlusIcon, |
| 5 | } from "@heroicons/react/24/outline"; |
| 6 | import { useContext } from "react"; |
| 7 | import { GhostButton } from "../../.."; |
| 8 | import { useAuth } from "../../../../context/Auth"; |
| 9 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 10 | import { useAppDispatch } from "../../../../redux/hooks"; |
| 11 | import { fontSize } from "../../../../util"; |
| 12 | |
| 13 | export function ExploreBlocksButton(props: { blockType: string }) { |
| 14 | const { selectedProfile } = useAuth(); |
| 15 | const ideMessenger = useContext(IdeMessengerContext); |
| 16 | const dispatch = useAppDispatch(); |
| 17 | |
| 18 | const isLocal = selectedProfile?.profileType === "local"; |
| 19 | |
| 20 | const Icon = isLocal ? PlusIcon : ArrowTopRightOnSquareIcon; |
| 21 | const text = `${isLocal ? "Add" : "Explore"} ${ |
| 22 | props.blockType === "mcpServers" |
| 23 | ? "MCP Servers" |
| 24 | : props.blockType.charAt(0).toUpperCase() + props.blockType.slice(1) |
| 25 | }`; |
| 26 | |
| 27 | const handleClick = () => { |
| 28 | if (isLocal) { |
| 29 | ideMessenger.request("config/addLocalWorkspaceBlock", { |
| 30 | blockType: props.blockType as BlockType, |
| 31 | }); |
| 32 | // switch (props.blockType) { |
| 33 | // case "docs": |
| 34 | // dispatch(setShowDialog(true)); |
| 35 | // dispatch(setDialogMessage(<AddDocsDialog />)); |
| 36 | // break; |
| 37 | // default: |
| 38 | // ideMessenger.request("config/openProfile", { |
| 39 | // profileId: selectedProfile.id, |
| 40 | // }); |
| 41 | // } |
| 42 | } else { |
| 43 | ideMessenger.request("controlPlane/openUrl", { |
| 44 | path: `new?type=block&blockType=${props.blockType}`, |
| 45 | orgSlug: undefined, |
| 46 | }); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | return ( |
| 51 | <GhostButton |
| 52 | className="w-full cursor-pointer rounded px-2 py-0.5 text-center text-gray-400 hover:text-gray-300" |
| 53 | style={{ |
| 54 | fontSize: fontSize(-3), |
| 55 | }} |
| 56 | onClick={(e) => { |
| 57 | e.preventDefault(); |
| 58 | handleClick(); |
| 59 | }} |
| 60 | > |
| 61 | <div className="flex items-center justify-center gap-1"> |
| 62 | <Icon className="h-3 w-3 pr-1" /> |
| 63 | <span className="text-[11px]">{text}</span> |
| 64 | </div> |
| 65 | </GhostButton> |
| 66 | ); |
| 67 | } |