"use client"; import { useEffect, useState, useCallback } from "react"; import { Plus, Search, MessageSquare, Bot } from "lucide-react"; // Removed Library, Sparkles, Archive import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarMenu, SidebarHeader, SidebarMenuItem, SidebarMenuButton, useSidebar, } from "./ui/sidebar"; import { getAllChats, createChat } from "@/lib/storage"; import type { Chat } from "@/lib/types"; import ChatButton from "@/components/sidebar/chatButton"; import { chatEventEmitter, CHAT_RENAMED_EVENT } from "@/lib/chatEventEmitter"; import { useChatStore } from "@/stores/chatStore"; import { cn } from "@/lib/utils"; import SearchModal from "./search-modal"; const AppSidebar = () => { const [chats, setChats] = useState([]); const [isSearchModalOpen, setIsSearchModalOpen] = useState(false); const { loadChat, selectedChatId, updateChatName, deleteChat } = useChatStore(); const { state } = useSidebar(); const isCollapsed = state === "collapsed"; const loadChats = useCallback(async () => { try { const loadedChats = await getAllChats(); setChats(loadedChats.reverse()); } catch (error) { console.error("Failed to load chats:", error); } }, []); const handleChatDelete = async (chatId: string) => { try { const deleted = await deleteChat(chatId); if (!deleted) return false; setChats((prevChats) => prevChats.filter((chat) => chat.id !== chatId)); return true; } catch (error) { console.error("Failed to delete chat:", error); return false; } }; const handleChatRename = async (chatId: string, newTitle: string) => { try { await updateChatName(chatId, newTitle); setChats((prevChats) => prevChats.map((chat) => chat.id === chatId ? { ...chat, title: newTitle } : chat ) ); return true; } catch (error) { console.error("Failed to rename chat:", error); return false; } }; useEffect(() => { loadChats(); chatEventEmitter.on(CHAT_RENAMED_EVENT, loadChats); return () => { chatEventEmitter.off(CHAT_RENAMED_EVENT, loadChats); }; }, [loadChats]); const handleNewChat = async () => { try { const chatName = "New Chat"; const newChat = await createChat(chatName, []); loadChat(newChat.id); setChats((prevChats) => [newChat, ...prevChats]); } catch (error) { console.error("Failed to create new chat:", error); } }; const menuItems = [ { icon: Plus, label: "New chat", action: handleNewChat }, { icon: Search, label: "Search chats", action: () => setIsSearchModalOpen(true), }, ]; return ( <> {!isCollapsed && (

Transcriptinator 6000

)}
{/* Menu Items */} {menuItems.map((item, index) => ( {!isCollapsed && ( {item.label} )} ))} {!isCollapsed && ( Recent Chats )} {!isCollapsed ? ( chats.length > 0 ? ( chats.map((chat) => ( )) ) : (

No conversations yet

Create your first chat to get started

) ) : ( // Collapsed state - show recent chats as icons chats.slice(0, 8).map((chat) => ( loadChat(chat.id)} tooltip={chat.title} className={cn( "justify-center w-10 h-10 rounded-lg transition-all duration-200", // Explicitly set w-10 h-10 selectedChatId === chat.id ? "bg-primary/20 border border-primary/30 text-primary" : "hover:bg-accent/50" )} > )) )}
); }; export default AppSidebar;