-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathConversationStarterCards.tsx
37 lines (32 loc) · 1.17 KB
/
ConversationStarterCards.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { SlashCommandDescription } from "core";
import { useAppDispatch } from "../../redux/hooks";
import { setMainEditorContentTrigger } from "../../redux/slices/sessionSlice";
import { getParagraphNodeFromString } from "../mainInput/utils";
import { ConversationStarterCard } from "./ConversationStarterCard";
import { useBookmarkedSlashCommands } from "./useBookmarkedSlashCommands";
const NUM_CARDS_TO_RENDER = 3;
export function ConversationStarterCards() {
const dispatch = useAppDispatch();
const { cmdsSortedByBookmark } = useBookmarkedSlashCommands();
function onClick(command: SlashCommandDescription) {
if (command.prompt) {
dispatch(
setMainEditorContentTrigger(getParagraphNodeFromString(command.prompt)),
);
}
}
if (!cmdsSortedByBookmark || cmdsSortedByBookmark.length === 0) {
return null;
}
return (
<div className="flex w-full max-w-full flex-col lg:grid lg:grid-cols-3 lg:gap-4">
{cmdsSortedByBookmark.slice(0, NUM_CARDS_TO_RENDER).map((command, i) => (
<ConversationStarterCard
key={command.name + i}
command={command}
onClick={onClick}
/>
))}
</div>
);
}