diff --git a/packages/web/src/components/apps/AiFeedbackModal.tsx b/packages/web/src/components/apps/AiFeedbackModal.tsx new file mode 100644 index 00000000..9396d3ed --- /dev/null +++ b/packages/web/src/components/apps/AiFeedbackModal.tsx @@ -0,0 +1,60 @@ +import * as React from 'react'; +import { + Button, + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@srcbook/components'; +import TextareaAutosize from 'react-textarea-autosize'; + +interface AiFeedbackModalProps { + isOpen: boolean; + onClose: () => void; + onSubmit: (feedback: string) => void; +} + +export function AiFeedbackModal({ isOpen, onClose, onSubmit }: AiFeedbackModalProps) { + const [feedback, setFeedback] = React.useState(''); + + const handleSubmit = () => { + onSubmit(feedback); + setFeedback(''); + onClose(); + }; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { + e.preventDefault(); + handleSubmit(); + } + }; + + return ( + + + + Provide Feedback + +
+ setFeedback(e.target.value)} + onKeyDown={handleKeyDown} + minRows={3} + maxRows={10} + /> +
+ + + + +
+
+ ); +} diff --git a/packages/web/src/components/chat.tsx b/packages/web/src/components/chat.tsx index 48d688e3..a0b19bbf 100644 --- a/packages/web/src/components/chat.tsx +++ b/packages/web/src/components/chat.tsx @@ -9,7 +9,6 @@ import { import Markdown from './apps/markdown.js'; import { diffFiles } from './apps/lib/diff.js'; import TextareaAutosize from 'react-textarea-autosize'; -import { toast } from 'sonner'; import { ArrowUp, Minus, @@ -47,6 +46,7 @@ import type { import { DiffStats } from './apps/diff-stats.js'; import { useApp } from './apps/use-app.js'; import { usePackageJson } from './apps/use-package-json.js'; +import { AiFeedbackModal } from './apps/AiFeedbackModal'; function Chat({ history, @@ -264,6 +264,21 @@ function DiffBox({ version: number; planId: string; }) { + const [showFeedbackToast, setShowFeedbackToast] = React.useState(false); + const [feedbackGiven, _setFeedbackGiven] = React.useState(null); + const [isFeedbackModalOpen, setIsFeedbackModalOpen] = React.useState(false); + + const setFeedbackGiven = (feedback: 'positive' | 'negative') => { + setShowFeedbackToast(true); + _setFeedbackGiven(feedback); + setTimeout(() => setShowFeedbackToast(false), 2500); + }; + + const handleFeedbackSubmit = (feedbackText: string) => { + setFeedbackGiven('negative'); + aiGenerationFeedback(app.id, { planId, feedback: { type: 'negative', text: feedbackText } }); + }; + return ( <>
@@ -287,30 +302,38 @@ function DiffBox({
+ {showFeedbackToast && ( +

Thanks for the feedback!

+ )}
+ setIsFeedbackModalOpen(false)} + onSubmit={handleFeedbackSubmit} + /> ); }