Elffuss BraidHub

kikocis/continue public

3a9c9650314e · 2.0 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 { useAppDispatch } from "../../../../redux/hooks";
11import { fontSize } from "../../../../util";
12
13export 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"
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}