parent
730ac56d5a
commit
efff2d3018
3 changed files with 54 additions and 35 deletions
|
|
@ -1,33 +1,63 @@
|
|||
import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon, ChatBubbleLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid";
|
||||
import { SlashCommandDescription } from "core";
|
||||
import { defaultBorderRadius, vscInputBackground } from "..";
|
||||
import { useState } from "react";
|
||||
import { defaultBorderRadius, GhostButton, vscInputBackground } from "..";
|
||||
|
||||
interface ConversationStarterCardProps {
|
||||
command: SlashCommandDescription;
|
||||
onClick: (command: SlashCommandDescription) => void;
|
||||
onBookmark: (command: SlashCommandDescription) => void;
|
||||
isBookmarked: boolean;
|
||||
}
|
||||
|
||||
export function ConversationStarterCard({
|
||||
command,
|
||||
onClick,
|
||||
onBookmark,
|
||||
isBookmarked = false,
|
||||
}: ConversationStarterCardProps) {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={() => onClick(command)}
|
||||
className="mb-2 w-full shadow-md hover:cursor-pointer hover:brightness-110"
|
||||
className="mb-2 w-full shadow-md hover:brightness-110"
|
||||
style={{
|
||||
borderRadius: defaultBorderRadius,
|
||||
backgroundColor: vscInputBackground,
|
||||
}}
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
>
|
||||
<div className="flex items-center px-3 py-2">
|
||||
<div className="flex items-center px-3 py-1.5">
|
||||
<div className="mr-3 flex-shrink-0">
|
||||
<ChatBubbleLeftIcon className="text-lightgray h-5 w-5" />
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<div
|
||||
onClick={() => onClick(command)}
|
||||
className="flex flex-1 flex-col hover:cursor-pointer"
|
||||
>
|
||||
<div className="font-medium">{command.name}</div>
|
||||
<div className="text-lightgray text-sm">{command.description}</div>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<GhostButton
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onBookmark(command);
|
||||
}}
|
||||
aria-label={
|
||||
isBookmarked ? "Remove bookmarked prompt" : "Bookmark prompt"
|
||||
}
|
||||
className={isHovered || isBookmarked ? "opacity-100" : "opacity-0"}
|
||||
>
|
||||
{isBookmarked ? (
|
||||
<BookmarkIconSolid className="h-4 w-4" />
|
||||
) : (
|
||||
<BookmarkIcon className="h-4 w-4" />
|
||||
)}
|
||||
</GhostButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,19 +10,13 @@ const NUM_CARDS_TO_RENDER_COLLAPSED = 3;
|
|||
|
||||
export function ConversationStarterCards() {
|
||||
const dispatch = useAppDispatch();
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [bookmarkedCommands, setBookmarkedCommands] = useState<string[]>([]);
|
||||
|
||||
const slashCommands =
|
||||
useAppSelector((state) => state.config.config.slashCommands) ?? [];
|
||||
|
||||
const filteredSlashCommands = slashCommands?.filter(isDeprecatedCommandName);
|
||||
|
||||
const numFilteredSlashCommands = filteredSlashCommands.length;
|
||||
const displayedCommands = isExpanded
|
||||
? filteredSlashCommands
|
||||
: filteredSlashCommands.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED);
|
||||
const hasMoreCommands =
|
||||
numFilteredSlashCommands > NUM_CARDS_TO_RENDER_COLLAPSED;
|
||||
|
||||
function onClick(command: SlashCommandDescription) {
|
||||
if (command.prompt) {
|
||||
dispatch(
|
||||
|
|
@ -31,8 +25,14 @@ export function ConversationStarterCards() {
|
|||
}
|
||||
}
|
||||
|
||||
function handleToggleExpand() {
|
||||
setIsExpanded(!isExpanded);
|
||||
function handleBookmarkCommand(command: SlashCommandDescription) {
|
||||
setBookmarkedCommands((prev) => {
|
||||
if (prev.includes(command.name)) {
|
||||
return prev.filter((name) => name !== command.name);
|
||||
} else {
|
||||
return [...prev, command.name];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!filteredSlashCommands || filteredSlashCommands.length === 0) {
|
||||
|
|
@ -40,29 +40,18 @@ export function ConversationStarterCards() {
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center">
|
||||
<h4 className="mb-2 w-full max-w-md self-start">Prompts</h4>
|
||||
|
||||
<div className="w-full max-w-md">
|
||||
{displayedCommands.map((command, i) => (
|
||||
<div className="flex w-full max-w-full flex-col lg:grid lg:grid-cols-3 lg:gap-4">
|
||||
{filteredSlashCommands
|
||||
.slice(0, NUM_CARDS_TO_RENDER_COLLAPSED)
|
||||
.map((command, i) => (
|
||||
<ConversationStarterCard
|
||||
key={command.name + i}
|
||||
command={command}
|
||||
onClick={onClick}
|
||||
onBookmark={handleBookmarkCommand}
|
||||
isBookmarked={bookmarkedCommands.includes(command.name)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{hasMoreCommands && (
|
||||
<p
|
||||
onClick={handleToggleExpand}
|
||||
className="text-lightgray cursor-pointer self-start text-xs hover:underline"
|
||||
>
|
||||
{isExpanded
|
||||
? "Show less"
|
||||
: `Show ${numFilteredSlashCommands - NUM_CARDS_TO_RENDER_COLLAPSED} more...`}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import styled from "styled-components";
|
||||
import { getFontSize, isJetBrains } from "../util";
|
||||
import { getFontSize } from "../util";
|
||||
|
||||
export const VSC_INPUT_BACKGROUND_VAR = "--vscode-input-background";
|
||||
export const VSC_BACKGROUND_VAR = "--vscode-sideBar-background";
|
||||
|
|
@ -151,7 +151,7 @@ export const SecondaryButton = styled.button`
|
|||
`;
|
||||
|
||||
export const GhostButton = styled.button`
|
||||
padding: 10px 12px;
|
||||
padding: 6px 8px;
|
||||
margin: 8px 0;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue