diff --git a/frontend/src/routes/_auth.chat.$chatId.tsx b/frontend/src/routes/_auth.chat.$chatId.tsx index 3e6a093ba..b5a2efdc9 100644 --- a/frontend/src/routes/_auth.chat.$chatId.tsx +++ b/frontend/src/routes/_auth.chat.$chatId.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef, useState, useCallback } from "react"; import { createFileRoute } from "@tanstack/react-router"; -import { AsteriskIcon, Check, Copy, UserIcon, ChevronDown } from "lucide-react"; +import { AsteriskIcon, Check, Copy, UserIcon, ChevronDown, SquarePenIcon } from "lucide-react"; import ChatBox from "@/components/ChatBox"; import { useOpenAI } from "@/ai/useOpenAi"; import { useLocalState } from "@/state/useLocalState"; @@ -11,7 +11,8 @@ import { Sidebar, SidebarToggle } from "@/components/Sidebar"; import { useQuery, useQueryClient } from "@tanstack/react-query"; import { Button } from "@/components/ui/button"; import { BillingStatus } from "@/billing/billingApi"; -import { useNavigate } from "@tanstack/react-router"; +import { useNavigate, useLocation } from "@tanstack/react-router"; +import { useIsMobile } from "@/utils/utils"; export const Route = createFileRoute("/_auth/chat/$chatId")({ component: ChatComponent @@ -84,12 +85,30 @@ function ChatComponent() { const queryClient = useQueryClient(); const [showScrollButton, setShowScrollButton] = useState(false); const navigate = useNavigate(); + const location = useLocation(); + const isMobile = useIsMobile(); const [error, setError] = useState(""); const [isSummarizing, setIsSummarizing] = useState(false); const chatContainerRef = useRef(null); + // Handle mobile new chat (matching sidebar behavior) + const handleMobileNewChat = useCallback(async () => { + // If we're already on "/", focus the chat box + if (location.pathname === "/") { + document.getElementById("message")?.focus(); + } else { + try { + await navigate({ to: "/" }); + // Ensure element is available after navigation + setTimeout(() => document.getElementById("message")?.focus(), 0); + } catch (error) { + console.error("Navigation failed:", error); + } + } + }, [navigate, location.pathname]); + // Memoize the scroll handler const handleScroll = useCallback(() => { const container = chatContainerRef.current; @@ -578,8 +597,20 @@ END OF INSTRUCTIONS`; ref={chatContainerRef} className="flex-1 min-h-0 overflow-y-auto flex flex-col relative" > -
-

+
+ {/* Mobile new chat button */} + {isMobile && ( + + )} +

{localChat.title}