Elffuss BraidHub

kikocis/continue public

307109b747b3 · 1.9 KiBRawPermalink
1import { SlashCommandDescription } from "core";
2import { useState } from "react";
3import { useBookmarkedSlashCommands } from "../../hooks/useBookmarkedSlashCommands";
4import { useAppDispatch, useAppSelector } from "../../redux/hooks";
5import { useMainEditor } from "../mainInput/TipTapEditor";
6import { ConversationStarterCard } from "./ConversationStarterCard";
7
8const NUM_CARDS_TO_RENDER = 5;
9
10/**
11 * Displays a grid of conversation starter cards for bookmarked slash commands
12 */
13export function ConversationStarterCards() {
14 const dispatch = useAppDispatch();
15 const { mainEditor } = useMainEditor();
16 const [showAll, setShowAll] = useState(false);
17 const { isCommandBookmarked } = useBookmarkedSlashCommands();
18 const slashCommands = useAppSelector(
19 (state) => state.config.config.slashCommands ?? [],
20 );
21
22 const bookmarkedSlashCommands = slashCommands.filter((command) =>
23 isCommandBookmarked(command.name),
24 );
25
26 function onClick(command: SlashCommandDescription) {
27 mainEditor?.commands.insertPrompt(command);
28 }
29
30 if (bookmarkedSlashCommands.length === 0) {
31 return null;
32 }
33
34 const visibleCommands = showAll
35 ? bookmarkedSlashCommands
36 : bookmarkedSlashCommands.slice(0, NUM_CARDS_TO_RENDER);
37
38 const remainingCount = bookmarkedSlashCommands.length - NUM_CARDS_TO_RENDER;
39
40 return (
41 <div className="flex w-full max-w-full flex-col">
42 <div className="lg:grid lg:grid-cols-3 lg:gap-4">
43 {visibleCommands.map((command, i) => (
44 <ConversationStarterCard
45 key={command.name + i}
46 command={command}
47 onClick={onClick}
48 />
49 ))}
50 </div>
51 {bookmarkedSlashCommands.length > NUM_CARDS_TO_RENDER && (
52 <span
53 className="text-lightgray mt-1 cursor-pointer text-xs hover:underline"
54 onClick={() => setShowAll(!showAll)}
55 >
56 {showAll ? "Show less" : `Show ${remainingCount} more...`}
57 </span>
58 )}
59 </div>
60 );
61}