Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(chat): migrate chat input to ContentEditor + unified SubmitButton
Naiyuan Qing6097f7392e18
diff --git a/packages/ui/components/common/submit-button.tsx b/packages/ui/components/common/submit-button.tsxnew file mode 100644index 0000000000..09e39fe5f5--- /dev/null+++ b/packages/ui/components/common/submit-button.tsx@@ -0,0 +1,34 @@+"use client";++import { ArrowUp, Loader2, Square } from "lucide-react";+import { Button } from "@multica/ui/components/ui/button";++interface SubmitButtonProps {+ onClick: () => void;+ disabled?: boolean;+ loading?: boolean;+ running?: boolean;+ onStop?: () => void;+}++function SubmitButton({ onClick, disabled, loading, running, onStop }: SubmitButtonProps) {+ if (running) {+ return (+ <Button size="icon-sm" onClick={onStop}>+ <Square className="fill-current" />+ </Button>+ );+ }++ return (+ <Button size="icon-sm" disabled={disabled || loading} onClick={onClick}>+ {loading ? (+ <Loader2 className="animate-spin" />+ ) : (+ <ArrowUp />+ )}+ </Button>+ );+}++export { SubmitButton, type SubmitButtonProps };diff --git a/packages/views/chat/components/chat-fab.tsx b/packages/views/chat/components/chat-fab.tsxindex dbc4e965be..eea3ef5c8c 100644--- a/packages/views/chat/components/chat-fab.tsx+++ b/packages/views/chat/components/chat-fab.tsx@@ -15,7 +15,7 @@ export function ChatFab() {if (isOpen) return null;return (- <Tooltip delay={300}>+ <Tooltip><TooltipTriggeronClick={toggle}className="fixed bottom-4 right-4 z-50 flex size-10 cursor-pointer items-center justify-center rounded-full border bg-background text-muted-foreground shadow-sm transition-transform hover:scale-110 hover:text-accent-foreground active:scale-95"diff --git a/packages/views/chat/components/chat-input.tsx b/packages/views/chat/components/chat-input.tsxindex 60df43572b..652220ba8f 100644--- a/packages/views/chat/components/chat-input.tsx+++ b/packages/views/chat/components/chat-input.tsx@@ -1,7 +1,8 @@"use client";-import { useState, useRef, useCallback } from "react";-import { ArrowUp, Square } from "lucide-react";+import { useRef, useState } from "react";+import { ContentEditor, type ContentEditorRef } from "../../editor";+import { SubmitButton } from "@multica/ui/components/common/submit-button";interface ChatInputProps {onSend: (content: string) => void;@@ -11,70 +12,36 @@ interface ChatInputProps {}export function ChatInput({ onSend, onStop, isRunning, disabled }: ChatInputProps) {- const [value, setValue] = useState("");- const textareaRef = useRef<HTMLTextAreaElement>(null);+ const editorRef = useRef<ContentEditorRef>(null);+ const [isEmpty, setIsEmpty] = useState(true);- const handleSend = useCallback(() => {- const trimmed = value.trim();- if (!trimmed || isRunning || disabled) return;- onSend(trimmed);- setValue("");- if (textareaRef.current) {- textareaRef.current.style.height = "auto";- }- textareaRef.current?.focus();- }, [value, isRunning, disabled, onSend]);-- const handleKeyDown = useCallback(- (e: React.KeyboardEvent<HTMLTextAreaElement>) => {- if (e.key === "Enter" && !e.shiftKey) {- e.preventDefault();- handleSend();- }- },- [handleSend],- );-- const handleInput = useCallback(() => {- const el = textareaRef.current;- if (!el) return;- el.style.height = "auto";- el.style.height = Math.min(el.scrollHeight, 120) + "px";- }, []);+ const handleSend = () => {+ const content = editorRef.current?.getMarkdown()?.replace(/(\n\s*)+$/, "").trim();+ if (!content || isRunning || disabled) return;+ onSend(content);+ editorRef.current?.clearContent();+ setIsEmpty(true);+ };return (- <div className="border-t bg-muted/30 p-3">- <div className="rounded-lg border bg-background">- <textarea- ref={textareaRef}- value={value}- onChange={(e) => {- setValue(e.target.value);- handleInput();- }}- onKeyDown={handleKeyDown}- placeholder={disabled ? "This session is archived" : "Ask Multica..."}- disabled={isRunning || disabled}- className="block w-full resize-none bg-transparent px-3 pt-3 pb-2 text-sm placeholder:text-muted-foreground focus:outline-none disabled:opacity-50"- rows={1}- />- <div className="flex items-center justify-end px-2 pb-2">- {isRunning ? (- <button- onClick={onStop}- className="flex size-7 items-center justify-center rounded-full bg-foreground text-background transition-opacity hover:opacity-80"- >- <Square className="size-3 fill-current" />- </button>- ) : (- <button- onClick={handleSend}- disabled={!value.trim() || disabled}- className="flex size-7 items-center justify-center rounded-full bg-foreground text-background transition-opacity hover:opacity-80 disabled:opacity-30"- >- <ArrowUp className="size-4" />- </button>- )}+ <div className="p-2 pt-0">+ <div className="relative flex min-h-16 max-h-40 flex-col rounded-lg bg-card pb-8 ring-1 ring-border">+ <div className="flex-1 min-h-0 overflow-y-auto px-3 py-2">+ <ContentEditor+ ref={editorRef}+ placeholder={disabled ? "This session is archived" : "Ask Multica..."}+ onUpdate={(md) => setIsEmpty(!md.trim())}+ onSubmit={handleSend}+ debounceMs={100}+ />+ </div>+ <div className="absolute bottom-1 right-1.5 flex items-center gap-1">+ <SubmitButton+ onClick={handleSend}+ disabled={isEmpty || !!disabled}+ running={isRunning}+ onStop={onStop}+ /></div></div></div>diff --git a/packages/views/issues/components/comment-input.tsx b/packages/views/issues/components/comment-input.tsxindex efd87dafa8..cbbe7d1dd7 100644--- a/packages/views/issues/components/comment-input.tsx+++ b/packages/views/issues/components/comment-input.tsx@@ -66,14 +66,14 @@ function CommentInput({ issueId, onSubmit }: CommentInputProps) {onSelect={(file) => editorRef.current?.uploadFile(file)}/><Button- size="icon-xs"+ size="icon-sm"disabled={isEmpty || submitting}onClick={handleSubmit}>{submitting ? (- <Loader2 className="h-3.5 w-3.5 animate-spin" />+ <Loader2 className="animate-spin" />) : (- <ArrowUp className="h-3.5 w-3.5" />+ <ArrowUp />)}</Button></div>