diff --git a/frontend/src/components/session/EditSessionTitleDialog.tsx b/frontend/src/components/session/EditSessionTitleDialog.tsx new file mode 100644 index 00000000..9b43c6a6 --- /dev/null +++ b/frontend/src/components/session/EditSessionTitleDialog.tsx @@ -0,0 +1,99 @@ +import { Dialog, DialogContent } from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import { X, Check } from "lucide-react"; +import { useState, useRef } from "react"; +import { useMobile } from "@/hooks/useMobile"; + +interface EditSessionTitleDialogProps { + isOpen: boolean; + currentTitle: string; + onClose: () => void; + onSave: (newTitle: string) => void; +} + +export function EditSessionTitleDialog({ isOpen, currentTitle, onClose, onSave }: EditSessionTitleDialogProps) { + const [editTitle, setEditTitle] = useState(currentTitle); + const inputRef = useRef(null); + const isMobile = useMobile(); + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Escape') { + setEditTitle(currentTitle); + onClose(); + } else if (e.key === 'Enter') { + if (editTitle.trim() && editTitle !== currentTitle) { + onSave(editTitle.trim()); + } + onClose(); + } + }; + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + if (editTitle.trim() && editTitle !== currentTitle) { + onSave(editTitle.trim()); + } + onClose(); + }; + + const handleCancel = () => { + setEditTitle(currentTitle); + onClose(); + }; + + return ( + + +
+

Change session title

+
+ setEditTitle(e.target.value)} + onKeyDown={handleKeyDown} + className="text-base font-semibold bg-background border border-border rounded px-3 py-2.5 pr-10 outline-none w-full focus:border-primary focus:ring-2 focus:ring-primary/20" + autoFocus + /> + {editTitle && ( + + )} +
+
+ + +
+
+
+
+ ); +} \ No newline at end of file diff --git a/frontend/src/components/session/SessionDetailHeader.tsx b/frontend/src/components/session/SessionDetailHeader.tsx index 26638770..6ceb9cfe 100644 --- a/frontend/src/components/session/SessionDetailHeader.tsx +++ b/frontend/src/components/session/SessionDetailHeader.tsx @@ -3,8 +3,10 @@ import { ContextUsageIndicator } from "@/components/session/ContextUsageIndicato import { BranchSwitcher } from "@/components/repo/BranchSwitcher"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; -import { Loader2, Settings, CornerUpLeft, Plug, FolderOpen, MoreVertical, Upload } from "lucide-react"; +import { EditSessionTitleDialog } from "@/components/session/EditSessionTitleDialog"; +import { Loader2, Settings, CornerUpLeft, Plug, FolderOpen, MoreVertical, Upload, X } from "lucide-react"; import { useState } from "react"; +import { useMobile } from "@/hooks/useMobile"; interface Repo { id: number; @@ -53,6 +55,7 @@ export function SessionDetailHeader({ onAttachFile, }: SessionDetailHeaderProps) { const [isEditing, setIsEditing] = useState(false); + const isMobile = useMobile(); const [editTitle, setEditTitle] = useState(sessionTitle); if (repo.cloneStatus !== 'ready') { @@ -84,12 +87,7 @@ export function SessionDetailHeader({ setIsEditing(false); }; - const handleTitleBlur = () => { - if (editTitle.trim() && editTitle !== sessionTitle) { - onSessionTitleUpdate(editTitle.trim()); - } - setIsEditing(false); - }; + const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Escape') { @@ -100,6 +98,10 @@ export function SessionDetailHeader({ } }; + + + + return (
@@ -124,29 +126,55 @@ export function SessionDetailHeader({ )}
- {isEditing ? ( -
+ {isMobile && ( + setIsEditing(false)} + onSave={(newTitle) => { + onSessionTitleUpdate(newTitle); + setIsEditing(false); + }} + /> + )} + {isEditing && !isMobile ? ( + setEditTitle(e.target.value)} - onBlur={handleTitleBlur} + onBlur={(e) => { + if (!e.relatedTarget?.closest('button')) { + handleTitleSubmit(e); + } + }} onKeyDown={handleKeyDown} - className="text-[16px] sm:text-base font-semibold bg-background border border-border rounded px-1 outline-none w-full truncate focus:border-primary sm:max-w-[250px]" + className="text-[16px] sm:text-base font-semibold bg-background border border-border rounded-l px-2 py-1 outline-none w-full truncate focus:border-primary sm:max-w-[250px] h-7" autoFocus /> + ) : ( -

- {sessionTitle} -

+ <> +

+ {sessionTitle} +

+

+ {repoName} +

+ )} -

- {repoName} -