mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add edit session title dialog with clear button for mobile, inline editing for desktop
This commit is contained in:
1 parent
005861ddf9
commit
9c8bb3b8f6
2 files changed
+147
-20
No files matched your search
@@ -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<HTMLInputElement>(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 (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
<DialogContent
|
||||
hideCloseButton
|
||||
className={isMobile
|
||||
? "w-screen max-w-none left-0 top-0 translate-x-0 translate-y-0 rounded-none border-0 border-b bg-background p-4 gap-0"
|
||||
: "p-6 gap-0"
|
||||
}
|
||||
>
|
||||
<form onSubmit={handleSubmit} className="min-w-0">
|
||||
<p className="text-sm text-muted-foreground mb-2">Change session title</p>
|
||||
<div className="relative">
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
value={editTitle}
|
||||
onChange={(e) => 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 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setEditTitle("");
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 p-1.5 rounded-full hover:bg-red-500/10 text-red-500 transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={handleCancel}
|
||||
className="flex-1 h-10"
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
className="flex-1 h-10"
|
||||
>
|
||||
<Check className="w-4 h-4 mr-2" />
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="sticky top-0 z-10 border-b border-border bg-gradient-to-b from-background via-background to-background backdrop-blur-sm px-2 sm:px-4 py-1.5 sm:py-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
@@ -124,29 +126,55 @@ export function SessionDetailHeader({
|
||||
<BackButton to={`/repos/${repoId}`} className="text-xs sm:text-sm" />
|
||||
)}
|
||||
<div className="min-w-0 flex-1">
|
||||
{isEditing ? (
|
||||
<form onSubmit={handleTitleSubmit} className="min-w-0">
|
||||
{isMobile && (
|
||||
<EditSessionTitleDialog
|
||||
isOpen={isEditing}
|
||||
currentTitle={sessionTitle}
|
||||
onClose={() => setIsEditing(false)}
|
||||
onSave={(newTitle) => {
|
||||
onSessionTitleUpdate(newTitle);
|
||||
setIsEditing(false);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{isEditing && !isMobile ? (
|
||||
<form onSubmit={handleTitleSubmit} className="flex items-center gap-1 min-w-0">
|
||||
<input
|
||||
type="text"
|
||||
value={editTitle}
|
||||
onChange={(e) => 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
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 rounded-l-none border border-l-0 border-border hover:bg-accent flex-shrink-0 mt-0"
|
||||
onClick={() => setEditTitle("")}
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</Button>
|
||||
</form>
|
||||
) : (
|
||||
<h1
|
||||
className="text-xs text-green-500 sm:text-base font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={handleTitleClick}
|
||||
>
|
||||
{sessionTitle}
|
||||
</h1>
|
||||
<>
|
||||
<h1
|
||||
className="text-xs text-green-500 sm:text-base font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={handleTitleClick}
|
||||
>
|
||||
{sessionTitle}
|
||||
</h1>
|
||||
<p className="text-[10px] sm:text-xs text-green-600 dark:text-green-400 truncate">
|
||||
{repoName}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<p className="text-[10px] sm:text-xs text-green-600 dark:text-green-400 truncate">
|
||||
{repoName}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 sm:gap-4 flex-shrink-0">
|
||||
|
||||
Reference in new issue
Block a user