2026-02-25 11:41:44 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
|
2026-02-26 17:35:45 +00:00
|
|
|
const { forwardRef, useEffect, useImperativeHandle, useRef, useState } = React;
|
|
|
|
|
|
|
|
|
|
export interface ChatInputHandle {
|
|
|
|
|
appendToInput(text: string): void;
|
|
|
|
|
}
|
2026-02-25 11:41:44 +00:00
|
|
|
|
|
|
|
|
interface ChatInputProps {
|
|
|
|
|
loading: boolean;
|
|
|
|
|
queuedMessages: { id: string; text: string }[];
|
|
|
|
|
onSubmit: (message: string) => void;
|
|
|
|
|
onCancel: () => void;
|
|
|
|
|
onRemoveQueuedMessage: (id: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 17:35:45 +00:00
|
|
|
export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
|
|
|
|
|
function ChatInput(
|
|
|
|
|
{ loading, queuedMessages, onSubmit, onCancel, onRemoveQueuedMessage },
|
|
|
|
|
ref,
|
|
|
|
|
) {
|
|
|
|
|
const [input, setInput] = useState("");
|
|
|
|
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
|
|
|
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
|
|
appendToInput(text: string) {
|
|
|
|
|
setInput((prev) => (prev ? `${prev}\n${text}` : text));
|
|
|
|
|
},
|
|
|
|
|
}));
|
2026-02-25 11:41:44 +00:00
|
|
|
|
2026-02-26 17:35:45 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
inputRef.current?.focus();
|
|
|
|
|
}, []);
|
2026-02-25 11:41:44 +00:00
|
|
|
|
2026-02-26 17:35:45 +00:00
|
|
|
const handleSubmit = () => {
|
|
|
|
|
if (!input.trim()) return;
|
|
|
|
|
onSubmit(input);
|
|
|
|
|
setInput("");
|
|
|
|
|
};
|
2026-02-25 11:41:44 +00:00
|
|
|
|
2026-02-26 17:35:45 +00:00
|
|
|
return (
|
2026-02-25 11:41:44 +00:00
|
|
|
<div
|
|
|
|
|
style={{
|
2026-02-26 17:35:45 +00:00
|
|
|
padding: "24px",
|
|
|
|
|
background: "#171717",
|
2026-02-25 11:41:44 +00:00
|
|
|
display: "flex",
|
2026-02-26 17:35:45 +00:00
|
|
|
justifyContent: "center",
|
2026-02-25 11:41:44 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2026-02-26 17:35:45 +00:00
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
maxWidth: "768px",
|
|
|
|
|
width: "100%",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "8px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* Queued message indicators */}
|
|
|
|
|
{queuedMessages.map(({ id, text }) => (
|
|
|
|
|
<div
|
|
|
|
|
key={id}
|
|
|
|
|
data-testid="queued-message-indicator"
|
|
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
gap: "8px",
|
|
|
|
|
padding: "8px 12px",
|
|
|
|
|
background: "#1e1e1e",
|
|
|
|
|
border: "1px solid #3a3a3a",
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
fontSize: "0.875rem",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
color: "#666",
|
|
|
|
|
flexShrink: 0,
|
|
|
|
|
fontSize: "0.7rem",
|
|
|
|
|
fontWeight: 700,
|
|
|
|
|
letterSpacing: "0.05em",
|
|
|
|
|
textTransform: "uppercase",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Queued
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
color: "#888",
|
|
|
|
|
flex: 1,
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{text}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
title="Edit queued message"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setInput(text);
|
|
|
|
|
onRemoveQueuedMessage(id);
|
|
|
|
|
inputRef.current?.focus();
|
|
|
|
|
}}
|
|
|
|
|
style={{
|
|
|
|
|
background: "none",
|
|
|
|
|
border: "none",
|
|
|
|
|
color: "#666",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
padding: "2px 6px",
|
|
|
|
|
fontSize: "0.8rem",
|
|
|
|
|
flexShrink: 0,
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Edit
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
title="Cancel queued message"
|
|
|
|
|
onClick={() => onRemoveQueuedMessage(id)}
|
|
|
|
|
style={{
|
|
|
|
|
background: "none",
|
|
|
|
|
border: "none",
|
|
|
|
|
color: "#666",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
padding: "2px 4px",
|
|
|
|
|
fontSize: "0.875rem",
|
|
|
|
|
flexShrink: 0,
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
✕
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
{/* Input row */}
|
2026-02-25 11:41:44 +00:00
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "8px",
|
2026-02-26 17:35:45 +00:00
|
|
|
alignItems: "center",
|
2026-02-25 11:41:44 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2026-02-26 17:35:45 +00:00
|
|
|
<textarea
|
|
|
|
|
ref={inputRef}
|
|
|
|
|
value={input}
|
|
|
|
|
onChange={(e) => setInput(e.target.value)}
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handleSubmit();
|
|
|
|
|
}
|
2026-02-25 11:41:44 +00:00
|
|
|
}}
|
2026-02-26 17:35:45 +00:00
|
|
|
placeholder="Send a message..."
|
|
|
|
|
rows={1}
|
2026-02-25 11:41:44 +00:00
|
|
|
style={{
|
|
|
|
|
flex: 1,
|
2026-02-26 17:35:45 +00:00
|
|
|
padding: "14px 20px",
|
|
|
|
|
borderRadius: "24px",
|
|
|
|
|
border: "1px solid #333",
|
|
|
|
|
outline: "none",
|
|
|
|
|
fontSize: "1rem",
|
|
|
|
|
fontWeight: "500",
|
|
|
|
|
background: "#2f2f2f",
|
|
|
|
|
color: "#ececec",
|
|
|
|
|
boxShadow: "0 2px 6px rgba(0,0,0,0.02)",
|
|
|
|
|
resize: "none",
|
|
|
|
|
overflowY: "auto",
|
|
|
|
|
fontFamily: "inherit",
|
2026-02-25 11:41:44 +00:00
|
|
|
}}
|
2026-02-26 17:35:45 +00:00
|
|
|
/>
|
2026-02-25 11:41:44 +00:00
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-02-26 17:35:45 +00:00
|
|
|
onClick={loading && !input.trim() ? onCancel : handleSubmit}
|
|
|
|
|
disabled={!loading && !input.trim()}
|
2026-02-25 11:41:44 +00:00
|
|
|
style={{
|
2026-02-26 17:35:45 +00:00
|
|
|
background: "#ececec",
|
|
|
|
|
color: "black",
|
2026-02-25 11:41:44 +00:00
|
|
|
border: "none",
|
2026-02-26 17:35:45 +00:00
|
|
|
borderRadius: "50%",
|
|
|
|
|
width: "32px",
|
|
|
|
|
height: "32px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
2026-02-25 11:41:44 +00:00
|
|
|
cursor: "pointer",
|
2026-02-26 17:35:45 +00:00
|
|
|
opacity: !loading && !input.trim() ? 0.5 : 1,
|
2026-02-25 11:41:44 +00:00
|
|
|
flexShrink: 0,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-02-26 17:35:45 +00:00
|
|
|
{loading && !input.trim() ? "■" : "↑"}
|
2026-02-25 11:41:44 +00:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-26 17:35:45 +00:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|