Elffuss BraidHub

kikocis/continue public

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