Elffuss BraidHub

kikocis/continue public

6fe634474097 · 3.5 KiBRawPermalink
1import {
2 BookmarkIcon as BookmarkOutline,
3 PencilIcon,
4} from "@heroicons/react/24/outline";
5import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid";
6import { SlashCommandDescription } from "core";
7import { useBookmarkedSlashCommands } from "../../../../hooks/useBookmarkedSlashCommands";
8import { useAppSelector } from "../../../../redux/hooks";
9import { fontSize } from "../../../../util";
10import { useMainEditor } from "../../TipTapEditor";
11import { useLump } from "../LumpContext";
12import { ExploreBlocksButton } from "./ExploreBlocksButton";
13
14interface PromptRowProps {
15 prompt: SlashCommandDescription;
16 isBookmarked: boolean;
17 setIsBookmarked: (isBookmarked: boolean) => void;
18 onEdit?: () => void;
19}
20
21/**
22 * Displays a single prompt row with bookmark and edit controls
23 */
24function PromptRow({
25 prompt,
26 isBookmarked,
27 setIsBookmarked,
28 onEdit,
29}: PromptRowProps) {
30 const { mainEditor } = useMainEditor();
31 const { hideLump } = useLump();
32
33 const handlePromptClick = (e: React.MouseEvent) => {
34 e.stopPropagation();
35 mainEditor?.commands.insertPrompt(prompt);
36 hideLump();
37 };
38
39 const handleBookmarkClick = (e: React.MouseEvent) => {
40 e.stopPropagation();
41 setIsBookmarked(!isBookmarked);
42 };
43
44 const handleEditClick = (e: React.MouseEvent) => {
45 e.stopPropagation();
46 if (onEdit) {
47 onEdit();
48 }
49 };
50
51 return (
52 <div
53 className="hover:bg-list-active hover:text-list-active-foreground flex items-center justify-between gap-3 rounded-md px-2 py-1 hover:cursor-pointer"
54 onClick={handlePromptClick}
55 style={{
56 fontSize: fontSize(-3),
57 }}
58 >
59 <div className="flex min-w-0 flex-col">
60 <span className="text-vscForeground shrink-0 font-medium">
61 {prompt.name}
62 </span>
63 <span className="line-clamp-2 text-[11px] text-gray-400">
64 {prompt.description}
65 </span>
66 </div>
67 <div className="flex items-center gap-2">
68 <PencilIcon
69 className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125"
70 onClick={handleEditClick}
71 />
72 <div
73 onClick={handleBookmarkClick}
74 className="cursor-pointer pt-0.5 text-gray-400 hover:brightness-125"
75 >
76 {isBookmarked ? (
77 <BookmarkSolid className="h-3 w-3" />
78 ) : (
79 <BookmarkOutline className="h-3 w-3" />
80 )}
81 </div>
82 </div>
83 </div>
84 );
85}
86
87/**
88 * Section that displays all available prompts with bookmarking functionality
89 */
90export function PromptsSection() {
91 const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands();
92
93 const slashCommands = useAppSelector(
94 (state) => state.config.config.slashCommands ?? [],
95 );
96
97 const handleEdit = (prompt: any) => {
98 // Handle edit action here
99 console.log("Editing prompt:", prompt);
100 };
101
102 const sortedCommands = [...slashCommands].sort((a, b) => {
103 const aBookmarked = isCommandBookmarked(a.name);
104 const bBookmarked = isCommandBookmarked(b.name);
105 if (aBookmarked && !bBookmarked) return -1;
106 if (!aBookmarked && bBookmarked) return 1;
107 return 0;
108 });
109
110 return (
111 <div className="flex flex-col">
112 {sortedCommands.map((prompt) => (
113 <PromptRow
114 key={prompt.name}
115 prompt={prompt}
116 isBookmarked={isCommandBookmarked(prompt.name)}
117 setIsBookmarked={() => toggleBookmark(prompt)}
118 onEdit={() => handleEdit(prompt)}
119 />
120 ))}
121 <ExploreBlocksButton blockType="prompts" />
122 </div>
123 );
124}