Skip to content

Commit

Permalink
fix: clean up code formatting and improve readability in PureMultimod…
Browse files Browse the repository at this point in the history
…alInput component
  • Loading branch information
athrael-soju committed Dec 19, 2024
1 parent 86d0d50 commit 4b2300e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions components/multimodal-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ function PureMultimodalInput({
setMessages: Dispatch<SetStateAction<Array<Message>>>;
append: (
message: Message | CreateMessage,
chatRequestOptions?: ChatRequestOptions,
chatRequestOptions?: ChatRequestOptions
) => Promise<string | null | undefined>;
handleSubmit: (
event?: {
preventDefault?: () => void;
},
chatRequestOptions?: ChatRequestOptions,
chatRequestOptions?: ChatRequestOptions
) => void;
className?: string;
}) {
Expand All @@ -77,13 +77,15 @@ function PureMultimodalInput({
const adjustHeight = () => {
if (textareaRef.current) {
textareaRef.current.style.height = 'auto';
textareaRef.current.style.height = `${textareaRef.current.scrollHeight + 2}px`;
textareaRef.current.style.height = `${
textareaRef.current.scrollHeight + 2
}px`;
}
};

const [localStorageInput, setLocalStorageInput] = useLocalStorage(
'input',
'',
''
);

useEffect(() => {
Expand Down Expand Up @@ -169,7 +171,7 @@ function PureMultimodalInput({
const uploadPromises = files.map((file) => uploadFile(file));
const uploadedAttachments = await Promise.all(uploadPromises);
const successfullyUploadedAttachments = uploadedAttachments.filter(
(attachment) => attachment !== undefined,
(attachment) => attachment !== undefined
);

setAttachments((currentAttachments) => [
Expand All @@ -182,7 +184,7 @@ function PureMultimodalInput({
setUploadQueue([]);
}
},
[setAttachments],
[setAttachments]
);

return (
Expand Down Expand Up @@ -229,12 +231,13 @@ function PureMultimodalInput({
onChange={handleInput}
className={cx(
'min-h-[24px] max-h-[calc(75dvh)] overflow-hidden resize-none rounded-2xl !text-base bg-muted pb-10 dark:border-zinc-700',
className,
className
)}
rows={2}
autoFocus
onKeyDown={(event) => {
if (event.key === 'Enter' && !event.shiftKey) {
// Only handle Enter submission on desktop
if (event.key === 'Enter' && !event.shiftKey && width > 768) {
event.preventDefault();

if (isLoading) {
Expand Down Expand Up @@ -273,7 +276,7 @@ export const MultimodalInput = memo(
if (!equal(prevProps.attachments, nextProps.attachments)) return false;

return true;
},
}
);

function PureAttachmentsButton({
Expand Down

0 comments on commit 4b2300e

Please sign in to comment.