diff --git a/apps/rowboat/app/lib/components/editable-field-with-immediate-save.tsx b/apps/rowboat/app/lib/components/editable-field-with-immediate-save.tsx deleted file mode 100644 index 472053ac..00000000 --- a/apps/rowboat/app/lib/components/editable-field-with-immediate-save.tsx +++ /dev/null @@ -1,204 +0,0 @@ -import { Button, Input, Textarea } from "@heroui/react"; -import { useEffect, useRef, useState } from "react"; -import { useClickAway } from "../../../hooks/use-click-away"; -import MarkdownContent from "./markdown-content"; -import clsx from "clsx"; -import { Label } from "./label"; -import { SparklesIcon } from "lucide-react"; - -interface EditableFieldProps { - value: string; - onChange: (value: string) => void; - label?: string; - placeholder?: string; - markdown?: boolean; - multiline?: boolean; - locked?: boolean; - className?: string; - validate?: (value: string) => { valid: boolean; errorMessage?: string }; - light?: boolean; - error?: string | null; - inline?: boolean; - showGenerateButton?: { - show: boolean; - setShow: (show: boolean) => void; - }; - disabled?: boolean; - type?: string; -} - -export function EditableField({ - value, - onChange, - label, - placeholder = "Click to edit...", - markdown = false, - multiline = false, - locked = false, - className = "flex flex-col gap-1 w-full", - validate, - light = false, - error, - inline = false, - showGenerateButton, - disabled = false, - type = "text", -}: EditableFieldProps) { - const [isEditing, setIsEditing] = useState(false); - const [localValue, setLocalValue] = useState(value); - const ref = useRef(null); - - const validationResult = validate?.(localValue); - const isValid = !validate || validationResult?.valid; - - useEffect(() => { - setLocalValue(value); - }, [value]); - - useClickAway(ref, () => { - if (isEditing) { - if (isValid && localValue !== value) { - onChange(localValue); - } else { - setLocalValue(value); - } - setIsEditing(false); - } - }); - - const onValueChange = (newValue: string) => { - setLocalValue(newValue); - onChange(newValue); // Always save immediately - }; - - const commonProps = { - autoFocus: true, - value: localValue, - onValueChange: onValueChange, - variant: "bordered" as const, - labelPlacement: "outside" as const, - placeholder: markdown ? '' : placeholder, - classNames: { - input: "rounded-md", - inputWrapper: "rounded-md border-medium" - }, - radius: "md" as const, - isInvalid: !isValid, - errorMessage: validationResult?.errorMessage, - onKeyDown: (e: React.KeyboardEvent) => { - if (!multiline && e.key === "Enter") { - e.preventDefault(); - if (isValid && localValue !== value) { - onChange(localValue); - } - setIsEditing(false); - } - if (e.key === "Escape") { - setLocalValue(value); - setIsEditing(false); - } - }, - }; - - if (isEditing) { - return ( -
- {label && ( -
-
- )} - {multiline &&