import { FC, useState, useEffect, useCallback } from "react"; import { observer } from "mobx-react"; // components import { TextArea } from "@plane/ui"; // types import { TIssueOperations } from "./issue-detail"; // hooks import useDebounce from "hooks/use-debounce"; export type IssueTitleInputProps = { disabled?: boolean; value: string | undefined | null; workspaceSlug: string; isSubmitting: "submitting" | "submitted" | "saved"; setIsSubmitting: (value: "submitting" | "submitted" | "saved") => void; issueOperations: TIssueOperations; projectId: string; issueId: string; }; export const IssueTitleInput: FC = observer((props) => { const { disabled, value, workspaceSlug, setIsSubmitting, issueId, issueOperations, projectId } = props; // states const [title, setTitle] = useState(""); // hooks const debouncedValue = useDebounce(title, 1500); useEffect(() => { if (value) setTitle(value); }, [value]); useEffect(() => { if (debouncedValue && debouncedValue !== value) { issueOperations.update(workspaceSlug, projectId, issueId, { name: debouncedValue }, false).finally(() => { setIsSubmitting("saved"); }); } // DO NOT Add more dependencies here. It will cause multiple requests to be sent. // eslint-disable-next-line react-hooks/exhaustive-deps }, [debouncedValue]); const handleTitleChange = useCallback( (e: React.ChangeEvent) => { setIsSubmitting("submitting"); setTitle(e.target.value); }, [setIsSubmitting] ); return (