/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/shared-chat/components/SharedSessionList.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ "use client"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Search, Plus, Loader2, ChevronLeft, ChevronRight, MessageSquare } from "lucide-react"; import { Badge } from "@/components/ui/badge"; interface SharedSession { id: string; update_time: string; name?: string; } interface SharedSessionListProps { sessions: SharedSession[]; selectedSession: string | null; isLoading: boolean; searchTerm: string; isCollapsed: boolean; setSearchTerm: (value: string) => void; setSelectedSession: (value: string | null) => void; onNewSession: () => void; onToggleCollapse: () => void; agentName?: string; } export function SharedSessionList({ sessions, selectedSession, isLoading, searchTerm, isCollapsed, setSearchTerm, setSelectedSession, onNewSession, onToggleCollapse, agentName = "Shared Agent" }: SharedSessionListProps) { const filteredSessions = sessions.filter((session) => session.id.toLowerCase().includes(searchTerm.toLowerCase()) || (session.name && session.name.toLowerCase().includes(searchTerm.toLowerCase())) ); const sortedSessions = [...filteredSessions].sort((a, b) => { const updateTimeA = new Date(a.update_time).getTime(); const updateTimeB = new Date(b.update_time).getTime(); return updateTimeB - updateTimeA; }); const formatDateTime = (dateTimeStr: string) => { try { const date = new Date(dateTimeStr); const day = date.getDate().toString().padStart(2, "0"); const month = (date.getMonth() + 1).toString().padStart(2, "0"); const year = date.getFullYear(); const hours = date.getHours().toString().padStart(2, "0"); const minutes = date.getMinutes().toString().padStart(2, "0"); return `${day}/${month}/${year} ${hours}:${minutes}`; } catch (error) { return "Invalid date"; } }; const getDisplayName = (session: SharedSession) => { if (session.name) return session.name; return `Session ${session.id.substring(0, 8)}`; }; if (isCollapsed) { return (
); } return (

{agentName}

Shared Sessions

setSearchTerm(e.target.value)} />
{isLoading ? (
) : sortedSessions.length > 0 ? (
{sortedSessions.map((session) => (
setSelectedSession(session.id)} >
{getDisplayName(session)}
Shared
{formatDateTime(session.update_time)}
))}
) : searchTerm ? (
No results found
) : (
Click "New" to start
)}
); }