From 3b26a6b60041be1b55ad08413b3f7de6dd541795 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Thu, 4 Sep 2025 15:56:22 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20(navigation.tsx):=20remove=20unu?= =?UTF-8?q?sed=20code=20and=20streamline=20navigation=20component=20for=20?= =?UTF-8?q?better=20performance=20and=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/navigation.tsx | 230 ------------------------- 1 file changed, 230 deletions(-) delete mode 100644 frontend/src/components/navigation.tsx diff --git a/frontend/src/components/navigation.tsx b/frontend/src/components/navigation.tsx deleted file mode 100644 index 30ac9a4b..00000000 --- a/frontend/src/components/navigation.tsx +++ /dev/null @@ -1,230 +0,0 @@ -"use client" - -import { useState, useEffect, useRef } from "react" -import { useRouter, usePathname } from "next/navigation" -import { Button } from "@/components/ui/button" -import { Plus, MessageSquare, Database, Settings, GitBranch } from "lucide-react" -import { useChat } from "@/contexts/chat-context" -import { useAuth } from "@/contexts/auth-context" - -interface Conversation { - id: string - title: string - endpoint: string - last_activity: string - created_at: string - response_id: string - messages?: Array<{ - role: string - content: string - timestamp?: string - response_id?: string - }> -} - -export function Navigation() { - const router = useRouter() - const pathname = usePathname() - const { user } = useAuth() - const { - refreshTrigger, - refreshTriggerSilent, - loadConversation, - startNewConversation, - currentConversationId, - placeholderConversation, - } = useChat() - - const [conversations, setConversations] = useState([]) - const [loading, setLoading] = useState(false) - - // Load conversations from backend - const loadConversations = async () => { - if (!user) return - - try { - setLoading(true) - const response = await fetch("/api/conversations") - if (response.ok) { - const data = await response.json() - setConversations(data.conversations || []) - } - } catch (error) { - console.error("Failed to load conversations:", error) - } finally { - setLoading(false) - } - } - - // Load conversations on mount and when refreshTrigger changes (with loading state) - useEffect(() => { - loadConversations() - }, [refreshTrigger, user]) - - // Silent refresh - update data without loading state - useEffect(() => { - const loadSilent = async () => { - if (!user) return - - try { - // Don't show loading state for silent refresh - const response = await fetch("/api/conversations") - if (response.ok) { - const data = await response.json() - setConversations(data.conversations || []) - } - } catch (error) { - console.error("Silent conversation refresh failed:", error) - } - } - - // Only do silent refresh if we have a silent trigger change (not initial load) - if (refreshTriggerSilent > 0) { - loadSilent() - } - }, [refreshTriggerSilent, user]) - - const handleNewConversation = () => { - startNewConversation() - // Dispatch custom event to notify chat page - window.dispatchEvent(new CustomEvent('newConversation')) - router.push('/chat') - } - - const handleConversationClick = async (conversation: Conversation) => { - try { - // Load full conversation data from backend - const response = await fetch(`/api/conversations/${conversation.response_id}`) - if (response.ok) { - const fullConversation = await response.json() - loadConversation(fullConversation) - router.push('/chat') - } - } catch (error) { - console.error("Failed to load conversation:", error) - } - } - - const formatRelativeTime = (timestamp: string) => { - const date = new Date(timestamp) - const now = new Date() - const diffMs = now.getTime() - date.getTime() - const diffHours = Math.floor(diffMs / (1000 * 60 * 60)) - const diffDays = Math.floor(diffHours / 24) - - if (diffDays > 0) { - return `${diffDays}d ago` - } else if (diffHours > 0) { - return `${diffHours}h ago` - } else { - return 'Just now' - } - } - - return ( - - ) -} \ No newline at end of file