fix ux concern to manage message state in dialog component

This commit is contained in:
Ethan Garber 2025-06-18 21:26:40 -04:00 committed by Louis
parent 00e960b9ef
commit 1d5852fbb5

View File

@ -79,6 +79,14 @@ const EditDialog = ({
message: string message: string
setMessage: (message: string) => void setMessage: (message: string) => void
}) => { }) => {
const [draft, setDraft] = useState(message)
const handleSave = () => {
if (draft !== message) {
setMessage(draft)
}
}
return ( return (
<Dialog> <Dialog>
<DialogTrigger> <DialogTrigger>
@ -97,10 +105,8 @@ const EditDialog = ({
<DialogHeader> <DialogHeader>
<DialogTitle>Edit Message</DialogTitle> <DialogTitle>Edit Message</DialogTitle>
<Textarea <Textarea
value={message} value={draft}
onChange={(e) => { onChange={(e) => setDraft(e.target.value)}
setMessage(e.target.value)
}}
className="mt-2 resize-none h-full w-full" className="mt-2 resize-none h-full w-full"
onKeyDown={(e) => { onKeyDown={(e) => {
// Prevent key from being captured by parent components // Prevent key from being captured by parent components
@ -114,7 +120,12 @@ const EditDialog = ({
</Button> </Button>
</DialogClose> </DialogClose>
<DialogClose asChild> <DialogClose asChild>
<Button disabled={!message}>Save</Button> <Button
disabled={draft === message || !draft}
onClick={handleSave}
>
Save
</Button>
</DialogClose> </DialogClose>
</DialogFooter> </DialogFooter>
</DialogHeader> </DialogHeader>