Spaces:
Sleeping
Sleeping
File size: 10,018 Bytes
56a0c74 760b33c 50f2833 760b33c 52fd618 56b7341 760b33c 56a0c74 760b33c 52fd618 760b33c 50f2833 56a0c74 50f2833 760b33c 52fd618 56b7341 52fd618 56b7341 50f2833 52fd618 760b33c 56a0c74 3cdbc9d 760b33c 50f2833 56a0c74 760b33c 56a0c74 50f2833 56a0c74 760b33c 56b7341 760b33c 56a0c74 52fd618 56b7341 52fd618 3cdbc9d 760b33c 52fd618 56a0c74 52fd618 56a0c74 52fd618 50f2833 52fd618 50f2833 52fd618 760b33c 52fd618 74c282e 52fd618 56b7341 52fd618 74c282e 56b7341 52fd618 56a0c74 8c94444 8a3c12f 6b883a8 8a3c12f 8c94444 8a3c12f 50f2833 56a0c74 8a3c12f 50f2833 8c94444 50f2833 56a0c74 8a3c12f 50f2833 8c94444 50f2833 56a0c74 8a3c12f 50f2833 8c94444 52fd618 56a0c74 52fd618 56b7341 52fd618 760b33c 52fd618 760b33c 52fd618 760b33c 52fd618 56b7341 52fd618 56a0c74 52fd618 3cdbc9d 74c282e 52fd618 74c282e 56a0c74 74c282e 56b7341 74c282e 760b33c 74c282e 52fd618 74c282e 52fd618 74c282e 760b33c 52fd618 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
// web/src/components/RightPanel.tsx
import React, { useState } from 'react';
import { Button } from './ui/button';
import { Input } from './ui/input';
import { Label } from './ui/label';
import { Card } from './ui/card';
import { Separator } from './ui/separator';
import { Textarea } from './ui/textarea';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select';
import { LogIn, LogOut, FileText, MessageSquare, Download, ClipboardList, Sparkles } from 'lucide-react';
import type { User } from '../App';
import { toast } from 'sonner';
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogFooter,
} from './ui/dialog';
interface RightPanelProps {
user: User | null;
onLogin: (name: string, emailOrId: string) => void;
onLogout: () => void;
isLoggedIn: boolean;
onClose?: () => void;
exportResult: string;
setExportResult: (result: string) => void;
resultType: 'export' | 'quiz' | 'summary' | null;
setResultType: (type: 'export' | 'quiz' | 'summary' | null) => void;
// ✅ Actions buttons callbacks (来自 App.tsx)
onExport: () => void;
onQuiz: () => void;
onSummary: () => void;
}
export function RightPanel({
user,
onLogin,
onLogout,
isLoggedIn,
exportResult,
setExportResult,
resultType,
setResultType,
onExport,
onQuiz,
onSummary,
}: RightPanelProps) {
const [showLoginForm, setShowLoginForm] = useState(false);
const [name, setName] = useState('');
const [emailOrId, setEmailOrId] = useState('');
const [feedbackDialogOpen, setFeedbackDialogOpen] = useState(false);
const [feedbackText, setFeedbackText] = useState('');
const [feedbackCategory, setFeedbackCategory] = useState<'general' | 'bug' | 'feature'>('general');
const handleLoginClick = () => {
if (!name.trim() || !emailOrId.trim()) {
toast.error('Please fill in all fields');
return;
}
onLogin(name.trim(), emailOrId.trim());
setShowLoginForm(false);
setName('');
setEmailOrId('');
};
const handleLogoutClick = () => {
onLogout();
setShowLoginForm(false);
};
const handleFeedbackSubmit = () => {
if (!feedbackText.trim()) {
toast.error('Please provide feedback text');
return;
}
console.log('Feedback submitted:', feedbackText, feedbackCategory);
setFeedbackDialogOpen(false);
setFeedbackText('');
toast.success('Feedback submitted!');
};
return (
<div className="flex-1 overflow-auto p-4 space-y-4">
{/* Account */}
<Card className="p-4">
{!isLoggedIn ? (
<div className="space-y-4">
<div className="flex flex-col items-center py-4">
<h3 className="mb-2">Welcome to Clare!</h3>
<p className="text-sm text-muted-foreground text-center mb-4">
Log in to start your learning session
</p>
</div>
{!showLoginForm ? (
<Button onClick={() => setShowLoginForm(true)} className="w-full gap-2">
<LogIn className="h-4 w-4" />
Student Login
</Button>
) : (
<div className="space-y-3">
<div className="space-y-2">
<Label htmlFor="name">Name</Label>
<Input
id="name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Enter your name"
/>
</div>
<div className="space-y-2">
<Label htmlFor="emailOrId">Email / Student ID</Label>
<Input
id="emailOrId"
value={emailOrId}
onChange={(e) => setEmailOrId(e.target.value)}
placeholder="Enter your email or ID"
/>
</div>
<div className="flex gap-2">
<Button onClick={handleLoginClick} className="flex-1">
Enter
</Button>
<Button variant="outline" onClick={() => setShowLoginForm(false)}>
Cancel
</Button>
</div>
</div>
)}
</div>
) : (
<div className="space-y-4">
<div className="flex items-center gap-3">
<div className="w-12 h-12 rounded-full bg-gradient-to-br from-purple-500 to-blue-500 flex items-center justify-center text-white">
{user?.name?.charAt(0).toUpperCase()}
</div>
<div className="flex-1 min-w-0">
<h4 className="truncate">{user?.name}</h4>
<p className="text-sm text-muted-foreground truncate">{user?.email}</p>
<p className="text-xs text-muted-foreground truncate">user_id: {user?.user_id}</p>
</div>
</div>
<Button variant="destructive" onClick={handleLogoutClick} className="w-full gap-2">
<LogOut className="h-4 w-4" />
Log Out
</Button>
</div>
)}
</Card>
{/* ✅ Actions:三按钮并排(同宽) */}
{/* Actions */}
{/* Actions */}
<Card className="p-4">
<div className="flex items-center justify-between mb-3">
<h3 className="text-base font-medium">Actions TEST 123</h3>
</div>
{/* 强制一排三个:不用 grid,直接 flex,最稳 */}
<div className="flex items-stretch gap-2">
<Button
variant="outline"
onClick={onExport}
disabled={!isLoggedIn}
title="Export"
className="flex-1 h-10 p-0 flex items-center justify-center rounded-xl"
>
<Download className="h-4 w-4" />
</Button>
<Button
variant="outline"
onClick={onQuiz}
disabled={!isLoggedIn}
title="Quiz"
className="flex-1 h-10 p-0 flex items-center justify-center rounded-xl"
>
<ClipboardList className="h-4 w-4" />
</Button>
<Button
variant="outline"
onClick={onSummary}
disabled={!isLoggedIn}
title="Summary"
className="flex-1 h-10 p-0 flex items-center justify-center rounded-xl"
>
<Sparkles className="h-4 w-4" />
</Button>
</div>
</Card>
<Separator />
{/* Results */}
<div className="space-y-3">
<h3>
{resultType === 'export' && 'Exported Conversation'}
{resultType === 'quiz' && 'Micro-Quiz'}
{resultType === 'summary' && 'Summarization'}
{!resultType && 'Results'}
</h3>
<Card className="p-4 min-h-[200px] bg-muted/30">
{exportResult ? (
<div className="space-y-3">
<div className="flex items-center justify-between">
<FileText className="h-4 w-4 text-muted-foreground" />
<Button
variant="ghost"
size="sm"
onClick={() => {
navigator.clipboard.writeText(exportResult);
toast.success('Copied to clipboard!');
}}
>
Copy
</Button>
</div>
<div className="text-sm whitespace-pre-wrap text-foreground">{exportResult}</div>
</div>
) : (
<div className="flex items-center justify-center h-full text-sm text-muted-foreground text-left">
Results (export / summary / quiz) will appear here after actions run
</div>
)}
</Card>
</div>
<Separator />
{/* Feedback */}
<div className="space-y-3">
<h3>Feedback</h3>
<Button
variant="outline"
className="w-full justify-start gap-2"
onClick={() => setFeedbackDialogOpen(true)}
>
<MessageSquare className="h-4 w-4" />
Provide Feedback
</Button>
</div>
<Dialog open={feedbackDialogOpen} onOpenChange={setFeedbackDialogOpen}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Provide Feedback</DialogTitle>
<DialogDescription>Help us improve Clare by sharing your thoughts and suggestions.</DialogDescription>
</DialogHeader>
<div className="space-y-3">
<div className="space-y-2">
<Label htmlFor="feedbackCategory">Category</Label>
<Select value={feedbackCategory} onValueChange={(v) => setFeedbackCategory(v as any)}>
<SelectTrigger>
<SelectValue placeholder="Select a category" />
</SelectTrigger>
<SelectContent>
<SelectItem value="general">General Feedback</SelectItem>
<SelectItem value="bug">Bug Report</SelectItem>
<SelectItem value="feature">Feature Request</SelectItem>
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label htmlFor="feedbackText">Feedback</Label>
<Textarea
id="feedbackText"
value={feedbackText}
onChange={(e) => setFeedbackText(e.target.value)}
placeholder="Enter your feedback here..."
className="min-h-[100px]"
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setFeedbackDialogOpen(false)}>
Cancel
</Button>
<Button onClick={handleFeedbackSubmit}>Submit</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
|