diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHeader.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHeader.tsx index 085109e1c..79cc2fb5f 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHeader.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHeader.tsx @@ -22,7 +22,6 @@ const ChatHeaderLayout = ({ onNewChatClick: () => void currentTitle: string | undefined displayTitle: string | undefined - onSaveTitle: (newTitle: string) => Promise }) => ReactNode }) => { const currentTitle = useCurrentTitle() @@ -43,13 +42,6 @@ const ChatHeaderLayout = ({ blockActions.clearBlocks({ keepSpecialTypes: true }) }, [chatActions, blockActions]) - const handleTitleSave = useCallback( - async (newTitle: string) => { - await chatActions.editChatTitle(newTitle) - }, - [chatActions], - ) - const isFloating = useAIChatPanelStyle() === AIChatPanelStyle.Floating const { isScrolledBeyondThreshold } = useAIRootState() @@ -73,11 +65,11 @@ const ChatHeaderLayout = ({ )}
-
- + + } />
@@ -87,7 +79,6 @@ const ChatHeaderLayout = ({ onNewChatClick: handleNewChatClick, currentTitle, displayTitle, - onSaveTitle: handleTitleSave, })}
@@ -108,8 +99,6 @@ export const ChatHeader = () => { - - { - -
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHistoryDropdown.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHistoryDropdown.tsx index 52119c9f8..2c113e309 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHistoryDropdown.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatHistoryDropdown.tsx @@ -89,7 +89,7 @@ export const ChatHistoryDropdown = ({ {triggerElement || defaultTrigger} - + {loading ? (
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/EditableTitle.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/EditableTitle.tsx index 63f01453a..aad3d4f36 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/EditableTitle.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/EditableTitle.tsx @@ -1,139 +1,39 @@ -import { Input } from "@follow/components/ui/input/Input.js" import { cn } from "@follow/utils/utils" -import { useCallback, useEffect, useState } from "react" +import type { ButtonHTMLAttributes } from "react" -interface EditableTitleProps { +interface EditableTitleProps extends Omit, "type"> { title?: string - onSave: (newTitle: string) => Promise - className?: string placeholder?: string - maxLength?: number } -export const EditableTitle = ({ +export const EditableTitle = function EditableTitle({ + ref, title = "", - onSave, - className, placeholder = "Untitled Chat", - maxLength = 100, -}: EditableTitleProps) => { - const [isEditing, setIsEditing] = useState(false) - const [editValue, setEditValue] = useState("") - const [isSaving, setIsSaving] = useState(false) - const [originalTitle, setOriginalTitle] = useState("") - const [saveSuccess, setSaveSuccess] = useState(false) - + className, + ...buttonProps +}: EditableTitleProps & { ref?: React.RefObject }) { const displayTitle = title || placeholder - - const handleStartEdit = useCallback(() => { - setOriginalTitle(title) - setEditValue(title) - setIsEditing(true) - }, [title]) - - const handleSave = useCallback(async () => { - if (isSaving) return - - const trimmedValue = editValue.trim() - - // If no changes, just exit edit mode - if (trimmedValue === originalTitle) { - setIsEditing(false) - return - } - - try { - setIsSaving(true) - await onSave(trimmedValue) - - // Show success feedback briefly - setSaveSuccess(true) - setTimeout(() => setSaveSuccess(false), 2000) - - setIsEditing(false) - } catch (error) { - console.error("Failed to save title:", error) - // Keep in edit mode on error to allow retry - } finally { - setIsSaving(false) - } - }, [editValue, originalTitle, onSave, isSaving]) - - const handleCancel = useCallback(() => { - setEditValue(originalTitle) - setIsEditing(false) - setIsSaving(false) - }, [originalTitle]) - - const handleKeyDown = useCallback( - (event: React.KeyboardEvent) => { - if (event.key === "Enter") { - event.preventDefault() - handleSave() - } else if (event.key === "Escape") { - event.preventDefault() - handleCancel() - } - }, - [handleSave, handleCancel], - ) - - const handleBlur = useCallback(() => { - if (!isSaving) { - handleSave() - } - }, [handleSave, isSaving]) - - // Auto-focus input when entering edit mode - useEffect(() => { - if (isEditing) { - const input = document.activeElement as HTMLInputElement - if (input?.select) { - input.select() - } - } - }, [isEditing]) - - if (isEditing) { - return ( -
- ref?.focus()} - value={editValue} - onChange={(e) => setEditValue(e.target.value)} - onKeyDown={handleKeyDown} - onBlur={handleBlur} - maxLength={maxLength} - disabled={isSaving} - className={cn( - "text-text border-accent/50 focus:border-accent bg-transparent font-bold", - "h-auto p-2 text-base leading-none", - isSaving && "cursor-not-allowed opacity-60", - className, - )} - placeholder={placeholder} - /> - {isSaving && ( -
- -
- )} -
- ) - } + const { ["aria-label"]: ariaLabelProp, ...restButtonProps } = buttonProps + const ariaLabel = ariaLabelProp ?? displayTitle return ( -
-

+

{displayTitle}

- {saveSuccess && ( - - )} - -
+ + ) } diff --git a/apps/desktop/layer/renderer/src/modules/ai-task/components/ai-task-modal-header.tsx b/apps/desktop/layer/renderer/src/modules/ai-task/components/ai-task-modal-header.tsx deleted file mode 100644 index 357427866..000000000 --- a/apps/desktop/layer/renderer/src/modules/ai-task/components/ai-task-modal-header.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { ActionButton } from "@follow/components/ui/button/index.js" -import { memo } from "react" - -import { EditableTitle } from "~/modules/ai-chat/components/layouts/EditableTitle" - -interface AITaskModalHeaderProps { - title: string - error?: string - placeholder?: string - maxLength?: number - onClose: () => void - onSaveTitle: (newTitle: string) => Promise | void -} - -export const AITaskModalHeader = memo(function AITaskModalHeader({ - title, - error, - placeholder = "AI Task", - maxLength = 50, - onClose, - onSaveTitle, -}: AITaskModalHeaderProps) { - return ( -
- { - await onSaveTitle(newTitle.trim() || placeholder) - }} - className="py-3" - /> - - - - {error &&
{error}
} -
- ) -})