From 6923132655ef0e9fd5acbc797cd465f57534787c Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Mon, 12 May 2025 11:36:36 -0700 Subject: [PATCH] Restructured how BackstoryTextField works to not propogate changes until Enter --- frontend/src/BackstoryTextField.tsx | 30 ++-- frontend/src/Conversation.tsx | 9 +- frontend/src/Message.tsx | 2 +- frontend/src/StyledMarkdown.tsx | 9 +- src/utils/agents/job_description.py | 218 +++++++++++++++------------- 5 files changed, 140 insertions(+), 128 deletions(-) diff --git a/frontend/src/BackstoryTextField.tsx b/frontend/src/BackstoryTextField.tsx index bb7bc44..39e0243 100644 --- a/frontend/src/BackstoryTextField.tsx +++ b/frontend/src/BackstoryTextField.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useEffect, ChangeEvent, KeyboardEvent } from 'react'; +import React, { useRef, useEffect, ChangeEvent, KeyboardEvent, useState } from 'react'; import { useTheme } from '@mui/material/styles'; import './BackstoryTextField.css'; @@ -7,8 +7,7 @@ interface BackstoryTextFieldProps { disabled?: boolean; multiline?: boolean; placeholder?: string; - onChange?: (e: ChangeEvent) => void; - onKeyDown?: (e: KeyboardEvent) => void; + onEnter: (value: string) => void; } const BackstoryTextField: React.FC = ({ @@ -16,12 +15,12 @@ const BackstoryTextField: React.FC = ({ disabled = false, multiline = false, placeholder, - onChange, - onKeyDown, + onEnter }) => { const theme = useTheme(); const textareaRef = useRef(null); const shadowRef = useRef(null); + const [editValue, setEditValue] = useState(value); useEffect(() => { if (multiline && textareaRef.current && shadowRef.current) { @@ -43,15 +42,10 @@ const BackstoryTextField: React.FC = ({ } }, [value, multiline, textareaRef, shadowRef, placeholder]); - const handleChange = (e: ChangeEvent) => { - if (onChange) { - onChange(e); - } - }; - - const handleKeyDown = (e: KeyboardEvent) => { - if (onKeyDown) { - onKeyDown(e); + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Enter' && (!multiline || !event.shiftKey)) { + setEditValue(''); + onEnter(event.currentTarget.value); } }; @@ -74,10 +68,10 @@ const BackstoryTextField: React.FC = ({ { setEditValue(e.target.value); }} onKeyDown={handleKeyDown} style={sharedStyle} /> @@ -89,10 +83,10 @@ const BackstoryTextField: React.FC = ({