clears conversations and no new line on enter

This commit is contained in:
Danny Avila 2023-02-08 08:27:23 -05:00
parent 51d93da3f8
commit 58498ed951
3 changed files with 19 additions and 7 deletions

View file

@ -15,6 +15,9 @@ export default function Conversation({ id, parentMessageId, title = 'New convers
); );
const clickHandler = async () => { const clickHandler = async () => {
if (conversationId === id) {
return;
}
dispatch(setConversation({ conversationId: id, parentMessageId })); dispatch(setConversation({ conversationId: id, parentMessageId }));
const data = await trigger(); const data = await trigger();

View file

@ -24,10 +24,12 @@ export default function ClearConvos() {
}; };
return ( return (
<NavLink <a
svg={TrashIcon} className="flex cursor-pointer items-center gap-3 rounded-md py-3 px-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10"
text="Clear conversations"
onClick={clickHandler} onClick={clickHandler}
/> >
<TrashIcon />
Clear conversations
</a>
); );
} }

View file

@ -51,7 +51,13 @@ export default function TextChat({ messages, reloadConvos }) {
handleSubmit({ text: payload, messageHandler, convo, convoHandler, errorHandler }); handleSubmit({ text: payload, messageHandler, convo, convoHandler, errorHandler });
}; };
const handleKeyPress = (e) => { const handleKeyDown = (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
}
};
const handleKeyUp = (e) => {
if (e.key === 'Enter' && e.shiftKey) { if (e.key === 'Enter' && e.shiftKey) {
console.log('Enter + Shift'); console.log('Enter + Shift');
} }
@ -60,12 +66,12 @@ export default function TextChat({ messages, reloadConvos }) {
if (!!isSubmitting) { if (!!isSubmitting) {
return; return;
} }
submitMessage(); submitMessage();
} }
}; };
const changeHandler = (e) => { const changeHandler = (e) => {
// console.log('changeHandler', JSON.stringify(e.target.value));
const { value } = e.target; const { value } = e.target;
if (isSubmitting && (value === '' || value === '\n')) { if (isSubmitting && (value === '' || value === '\n')) {
return; return;
@ -84,7 +90,8 @@ export default function TextChat({ messages, reloadConvos }) {
// style={{maxHeight: '200px', height: '24px', overflowY: 'hidden'}} // style={{maxHeight: '200px', height: '24px', overflowY: 'hidden'}}
rows="1" rows="1"
value={text} value={text}
onKeyUp={handleKeyPress} onKeyUp={handleKeyUp}
onKeyDown={handleKeyDown}
onChange={changeHandler} onChange={changeHandler}
placeholder="" placeholder=""
className="m-0 h-auto max-h-52 resize-none overflow-auto border-0 bg-transparent p-0 pl-2 pr-7 leading-6 focus:outline-none focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-0" className="m-0 h-auto max-h-52 resize-none overflow-auto border-0 bg-transparent p-0 pl-2 pr-7 leading-6 focus:outline-none focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-0"