Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions frontend/src/routes/_auth.chat.$chatId.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -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<HTMLDivElement>(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;
Expand Down Expand Up @@ -578,8 +597,20 @@ END OF INSTRUCTIONS`;
ref={chatContainerRef}
className="flex-1 min-h-0 overflow-y-auto flex flex-col relative"
>
<div className="mt-4 md:mt-8 w-full h-10 flex items-center justify-center">
<h2 className="text-lg font-semibold self-center truncate max-w-[20rem] mx-[6rem] py-2">
<div className="mt-4 md:mt-8 w-full h-10 flex items-center justify-center relative">
{/* Mobile new chat button */}
{isMobile && (
<Button
variant="outline"
size="icon"
className="absolute right-4"
onClick={handleMobileNewChat}
aria-label="New chat"
>
<SquarePenIcon className="h-4 w-4" />
</Button>
)}
<h2 className="text-base font-semibold self-center truncate max-w-[20rem] mx-[6rem] py-2">
{localChat.title}
</h2>
</div>
Expand Down