mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
* feat: impl Coco server related APIs * chore: remove unused method * fix: invoke Rust interfaces in tauri::run() * chore: add invoke * feat: add add_coco_server * fix: trim the tailing forward slash * feat: interface get_user_profiles * chore: add * fix: store the servers in add interface * chore: ass * fix: skip non-publich servers with no token * feat: add * feat: get datasources and connectors * fix: invoke interfaces in tauri::run() * chore: add SidebarRef * refactor: refactoring coco-app * refactor: refactoring coco app * refactor: refactoring project layout * refactor: refactoring server management * chore: cleanup code * chore: display error when connect failed * refactor: refactoring refresh server's info * refactor: refactoring how to connect the coco serverg * chore: rename to cloud * refactor: refactoring remove coco server * fix: refresh current selected server * fix: reset server selection * chore: update login status * feat: add error message tips * fix: fix login and logout * refactor: refactoring http client * fix: fix the datasources * chore: minor fix * refactor: refactoring code * fix: fix search api * chore: optimize part of icons * chore: fix build * refactor: search list icon * refactor: search list icon * chore: lib * feat: add plugin-os --------- Co-authored-by: rain <15911122312@163.com> Co-authored-by: medcl <m@medcl.net>
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { useEffect, useRef, useImperativeHandle, forwardRef } from "react";
|
|
|
|
interface AutoResizeTextareaProps {
|
|
input: string;
|
|
setInput: (value: string) => void;
|
|
handleKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
connected: boolean;
|
|
}
|
|
|
|
// Forward ref to allow parent to interact with this component
|
|
const AutoResizeTextarea = forwardRef<
|
|
{ reset: () => void; focus: () => void },
|
|
AutoResizeTextareaProps
|
|
>(({ input, setInput, handleKeyDown, connected }, ref) => {
|
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
|
|
useEffect(() => {
|
|
const textarea = textareaRef.current;
|
|
if (textarea) {
|
|
const prevHeight = textarea.style.height;
|
|
textarea.style.height = "auto"; // Reset height to recalculate
|
|
if (textarea.style.height !== prevHeight) {
|
|
textarea.style.height = `${textarea.scrollHeight}px`; // Adjust based on content
|
|
}
|
|
}
|
|
}, [input]);
|
|
|
|
// Expose methods to the parent via ref
|
|
useImperativeHandle(ref, () => ({
|
|
reset: () => {
|
|
setInput("");
|
|
const textarea = textareaRef.current;
|
|
if (textarea) {
|
|
textarea.style.height = "auto";
|
|
}
|
|
},
|
|
focus: () => {
|
|
textareaRef.current?.focus();
|
|
},
|
|
}));
|
|
|
|
return (
|
|
<textarea
|
|
ref={textareaRef}
|
|
autoFocus
|
|
autoComplete="off"
|
|
autoCapitalize="none"
|
|
spellCheck="false"
|
|
className="text-base flex-1 outline-none min-w-[200px] text-[#333] dark:text-[#d8d8d8] placeholder-text-xs placeholder-[#999] dark:placeholder-gray-500 bg-transparent"
|
|
placeholder={connected ? "Ask whatever you want ..." : ""}
|
|
aria-label="Ask whatever you want ..."
|
|
value={input}
|
|
onChange={(e) => setInput(e.target.value)}
|
|
onKeyDown={(e) => handleKeyDown?.(e)}
|
|
rows={1}
|
|
style={{
|
|
resize: "none", // Prevent manual resize
|
|
overflow: "auto", // Enable scrollbars when needed
|
|
maxHeight: "4.5rem", // Limit height to 3 rows (3 * 1.5 line-height)
|
|
lineHeight: "1.5rem", // Line height to match row height
|
|
}}
|
|
/>
|
|
);
|
|
});
|
|
|
|
export default AutoResizeTextarea;
|