updated UI

This commit is contained in:
Harivansh Rathi 2024-12-08 15:12:28 -05:00
parent b06ae009cc
commit 171fe6e04f
12 changed files with 653 additions and 385 deletions

View file

@ -182,62 +182,79 @@ export default function AskQuestion() {
}
return (
<div className="h-full flex flex-col">
{/* Header */}
<div className="flex-none border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<div className="flex h-14 items-center justify-between px-4">
<div className="flex items-center gap-2">
<MessageSquarePlus className="h-5 w-5 text-muted-foreground" />
<div>
<h1 className="text-sm font-semibold">Ask a Question</h1>
{chat && (
<p className="text-xs text-muted-foreground line-clamp-1">
{chat.title}
</p>
<div className="h-[calc(100vh-4rem)] flex flex-col">
{/* Main Chat Container */}
<div className="flex-1 flex flex-col relative">
{/* Sticky Subheader */}
<div className="sticky top-0 z-10 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 border-b">
<div className="flex h-14 items-center justify-between px-4">
<div className="flex items-center gap-2">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary/10">
<MessageSquarePlus className="h-4 w-4 text-primary" />
</div>
<div>
<h1 className="text-sm font-medium">Ask a Question</h1>
{chat && (
<p className="text-xs text-muted-foreground line-clamp-1">
{chat.title}
</p>
)}
</div>
</div>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="sm"
onClick={handleNewChat}
className="text-muted-foreground hover:text-primary hover:bg-primary/10"
>
<MessageSquarePlus className="mr-2 h-4 w-4" />
New Chat
</Button>
{chatId && !isNewChat && messages.length > 0 && (
<Button
variant="ghost"
size="sm"
onClick={clearChat}
className="text-muted-foreground hover:text-primary hover:bg-primary/10"
>
<X className="mr-2 h-4 w-4" />
Clear chat
</Button>
)}
{hasExistingChats && (
<Link to="/dashboard/history">
<Button
variant="ghost"
size="sm"
className="text-muted-foreground hover:text-primary hover:bg-primary/10"
>
<History className="mr-2 h-4 w-4" />
History
</Button>
</Link>
)}
</div>
</div>
<div className="flex items-center gap-2">
<Button variant="ghost" size="sm" onClick={handleNewChat}>
<MessageSquarePlus className="mr-2 h-4 w-4" />
New Chat
</Button>
{chatId && !isNewChat && messages.length > 0 && (
<Button variant="ghost" size="sm" onClick={clearChat}>
<X className="mr-2 h-4 w-4" />
Clear chat
</Button>
)}
{hasExistingChats && (
<Link to="/dashboard/history">
<Button variant="ghost" size="sm">
<History className="mr-2 h-4 w-4" />
History
</Button>
</Link>
)}
</div>
{/* Error Message */}
{error && (
<div className="flex-none mx-4 mt-4 flex items-center gap-2 rounded-lg bg-destructive/10 p-3 text-sm text-destructive">
<AlertCircle className="h-4 w-4" />
{error}
</div>
</div>
</div>
)}
{/* Error Message */}
{error && (
<div className="flex-none mx-4 mt-4 flex items-center gap-2 rounded-lg bg-destructive/10 p-3 text-sm text-destructive">
<AlertCircle className="h-4 w-4" />
{error}
</div>
)}
{/* Messages Area */}
<div className="flex-1 min-h-0 relative">
<div className="absolute inset-0 overflow-y-auto">
{/* Messages Container */}
<div className="flex-1 overflow-y-auto">
<div className="flex flex-col space-y-6 p-4">
{!isNewChat && !chatId ? (
<div className="h-full flex items-center justify-center min-h-[calc(100vh-16rem)]">
<div className="h-full flex items-center justify-center min-h-[calc(100vh-12rem)]">
<div className="max-w-md w-full space-y-8">
<div className="flex flex-col items-center text-center">
<div className="rounded-full bg-blue-500/20 p-6 mb-8">
<div className="h-16 w-16 rounded-full bg-gradient-to-br from-blue-400 to-blue-600 shadow-lg" />
<div className="rounded-full bg-purple-500/20 p-6 mb-8">
<div className="h-16 w-16 rounded-full bg-gradient-to-br from-purple-300 to-purple-500 shadow-lg" />
</div>
<h2 className="text-xl font-semibold mb-2">Welcome to StudyAI Chat</h2>
<p className="text-sm text-muted-foreground mb-6">
@ -245,7 +262,7 @@ export default function AskQuestion() {
</p>
<Button
onClick={handleNewChat}
className="w-full bg-blue-500 hover:bg-blue-600 mb-8"
className="w-full bg-gradient-to-r from-purple-400 to-purple-500 hover:from-purple-500 hover:to-purple-600 text-white mb-8"
>
<MessageSquarePlus className="mr-2 h-5 w-5" />
Start New Chat
@ -289,11 +306,11 @@ export default function AskQuestion() {
</div>
</div>
) : messages.length === 0 ? (
<div className="h-full flex items-center justify-center min-h-[calc(100vh-16rem)]">
<div className="h-full flex items-center justify-center min-h-[calc(100vh-12rem)]">
<div className="max-w-md w-full space-y-8">
<div className="flex flex-col items-center text-center">
<div className="rounded-full bg-blue-500/20 p-6 mb-8">
<div className="h-16 w-16 rounded-full bg-gradient-to-br from-blue-400 to-blue-600 shadow-lg" />
<div className="rounded-full bg-purple-500/20 p-6 mb-8">
<div className="h-16 w-16 rounded-full bg-gradient-to-br from-purple-300 to-purple-500 shadow-lg" />
</div>
<h2 className="text-xl font-semibold mb-2">Ask Your First Question</h2>
<p className="text-sm text-muted-foreground mb-6">
@ -334,17 +351,17 @@ export default function AskQuestion() {
/>
))}
{isTyping && (
<div className="flex w-full items-start gap-3 px-4">
<div className="flex w-full items-start gap-3">
<Avatar className="h-8 w-8">
<AvatarFallback className="bg-gradient-to-br from-blue-400 to-blue-600 text-white text-xs font-medium">
<AvatarFallback className="bg-gradient-to-br from-purple-300 to-purple-500 text-white text-xs font-medium">
AI
</AvatarFallback>
</Avatar>
<div className="flex max-w-3xl items-center space-x-4 rounded-2xl bg-muted/50 px-4 py-3 text-sm shadow-sm border border-border/50">
<div className="flex max-w-3xl items-center space-x-4 rounded-2xl bg-primary/5 px-4 py-3 text-sm shadow-sm">
<div className="flex space-x-2">
<div className="h-2 w-2 animate-bounce rounded-full bg-muted-foreground/50 [animation-delay:0ms]" />
<div className="h-2 w-2 animate-bounce rounded-full bg-muted-foreground/50 [animation-delay:150ms]" />
<div className="h-2 w-2 animate-bounce rounded-full bg-muted-foreground/50 [animation-delay:300ms]" />
<div className="h-2 w-2 animate-bounce rounded-full bg-primary/40 [animation-delay:0ms]" />
<div className="h-2 w-2 animate-bounce rounded-full bg-primary/40 [animation-delay:150ms]" />
<div className="h-2 w-2 animate-bounce rounded-full bg-primary/40 [animation-delay:300ms]" />
</div>
</div>
</div>
@ -354,42 +371,43 @@ export default function AskQuestion() {
)}
</div>
</div>
</div>
{/* Input Area */}
<div className="flex-none border-t bg-background p-4">
<form onSubmit={handleSubmit} className="mx-auto max-w-3xl">
<div className="relative flex items-center gap-2">
<input
type="text"
value={question}
onChange={(e) => setQuestion(e.target.value)}
placeholder="Ask me anything..."
className={cn(
'w-full rounded-full border bg-background px-4 py-2 text-sm',
'focus:outline-none focus:ring-2 focus:ring-blue-500/20',
'placeholder:text-muted-foreground'
)}
disabled={loading}
/>
<Button
type="submit"
disabled={loading || !question.trim()}
className={cn(
'rounded-full bg-blue-500 text-white h-8 w-8 p-0',
'hover:bg-blue-600',
'focus:outline-none focus:ring-2 focus:ring-blue-500/20',
'disabled:bg-blue-500/50'
)}
>
{loading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Send className="h-4 w-4" />
)}
</Button>
</div>
</form>
{/* Input Box - Fixed at Bottom */}
<div className="sticky bottom-0 left-0 right-0 p-3 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<form onSubmit={handleSubmit} className="mx-auto max-w-3xl">
<div className="flex items-center gap-2">
<input
type="text"
value={question}
onChange={(e) => setQuestion(e.target.value)}
placeholder="Ask me anything..."
className={cn(
'flex-1 rounded-full px-4 py-2 text-sm',
'bg-primary/5 border-primary/10',
'focus:outline-none focus:ring-2 focus:ring-primary/20',
'placeholder:text-muted-foreground'
)}
disabled={loading}
/>
<Button
type="submit"
disabled={loading || !question.trim()}
className={cn(
'rounded-full bg-gradient-to-r from-purple-400 to-purple-500 text-white h-8 w-8 p-0',
'hover:from-purple-500 hover:to-purple-600',
'focus:outline-none focus:ring-2 focus:ring-primary/20',
'disabled:opacity-50'
)}
>
{loading ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Send className="h-4 w-4" />
)}
</Button>
</div>
</form>
</div>
</div>
</div>
);