Spaces:
Running
Running
File size: 6,001 Bytes
1904e4c |
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 |
import React from "react";
import { format } from "date-fns";
import { Bot, TrashIcon, User, FileText, Settings, PanelLeft, Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { Chat } from "@/types/chat";
import { ModeToggle } from "@/components/layout/ModeToggle";
interface ChatSidebarProps {
chats: Chat[];
activeChat: Chat | null;
isGeneratingTitle: boolean;
createNewChat: () => void;
selectChat: (id: string) => void;
onRequestDelete: (id: string) => void;
onOpenSettings: () => void;
onOpenSources: () => void;
openProfileModal: () => void;
isSidebarOpen: boolean;
setIsSidebarOpen: (open: boolean) => void;
}
export const ChatSidebar: React.FC<ChatSidebarProps> = ({
chats,
activeChat,
isGeneratingTitle,
createNewChat,
selectChat,
onRequestDelete,
onOpenSettings,
onOpenSources,
openProfileModal,
isSidebarOpen,
setIsSidebarOpen,
}) => {
return (
<div className={cn(
"fixed top-0 bottom-0 left-0 z-20 bg-background/90 backdrop-blur-lg",
"transition-transform duration-300 ease-in-out",
isSidebarOpen ? 'translate-x-0' : '-translate-x-full md:translate-x-0',
"w-72 lg:w-80 border-r border-border/50 flex-shrink-0",
"md:relative md:inset-auto h-full md:z-0"
)}>
<div className="flex flex-col h-full">
<div className="p-4 pb-0">
<div className="flex justify-between items-center">
<div className="flex items-center space-x-2">
<div className="h-8 w-8 bg-primary/90 rounded-md flex items-center justify-center">
<span className="text-white font-bold text-lg">AI</span>
</div>
<h1 className="text-xl font-semibold">
Insight AI
</h1>
</div>
<Button className="md:hidden" variant="ghost" size="icon" onClick={() => setIsSidebarOpen(false)}>
<PanelLeft className="h-5 w-5" />
</Button>
</div>
<div className="py-4">
<Button
onClick={createNewChat}
className="w-full justify-start gap-2"
variant="outline"
>
<Plus className="h-4 w-4" />
New Chat
</Button>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Bot className="h-5 w-5 text-primary" />
<span className="font-medium">Recent Chats</span>
</div>
</div>
</div>
<div className="flex-1 overflow-y-auto p-2 space-y-1 scrollbar-thin">
{chats.length === 0 ? (
<div className="text-center text-muted-foreground p-4">
No conversations yet. Start a new one!
</div>
) : (
chats.map(chat => (
<div
key={chat.id}
onClick={() => selectChat(chat.id)}
className={cn(
"flex items-center justify-between p-2 px-3 rounded-lg cursor-pointer group transition-all",
activeChat?.id === chat.id
? "bg-primary/10 border border-primary/20"
: "hover:bg-muted/50 border border-transparent"
)}
>
<div className="flex-1 truncate">
<div className={cn(
"font-medium truncate flex items-center",
activeChat?.id === chat.id && "text-primary"
)}>
<Bot className="h-3.5 w-3.5 mr-1.5 opacity-70" />
{chat.title}
{chat.id === activeChat?.id && isGeneratingTitle && (
<span className="ml-1.5 inline-block h-2 w-2 rounded-full bg-primary/70 animate-pulse"></span>
)}
</div>
<div className="text-xs text-muted-foreground">
{chat.messages.filter(m => m.sender === "user").length} messages • {format(new Date(chat.updatedAt), "MMM d")}
</div>
</div>
<Button
variant="ghost"
size="icon"
className="h-7 w-7 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-destructive/10 hover:text-destructive"
onClick={(e) => {
e.stopPropagation();
onRequestDelete(chat.id);
}}
>
<TrashIcon className="h-3.5 w-3.5" />
</Button>
</div>
))
)}
</div>
{/* Sidebar Footer */}
<div className="p-3 space-y-2">
<Button
onClick={openProfileModal}
variant="ghost"
className="w-full justify-start gap-2 text-muted-foreground hover:text-foreground"
size="sm"
>
<User className="h-4 w-4" />
Profile
</Button>
<Button
onClick={onOpenSources}
variant="ghost"
className="w-full justify-start gap-2 text-muted-foreground hover:text-foreground"
size="sm"
>
<FileText className="h-4 w-4" />
View Sources
</Button>
<Button
onClick={onOpenSettings}
variant="ghost"
className="w-full justify-start gap-2 text-muted-foreground hover:text-foreground"
size="sm"
>
<Settings className="h-4 w-4" />
Settings
</Button>
<div className="flex items-center justify-between pt-2 border-t">
<span className="text-xs text-muted-foreground">Theme</span>
<ModeToggle />
</div>
</div>
</div>
</div>
);
};
|