import { FC, useState, useEffect } from "react"; import { observer } from "mobx-react"; // components import { Loader } from "@plane/ui"; import { RichReadOnlyEditor, RichTextEditor } from "@plane/rich-text-editor"; // store hooks import { useMention, useWorkspace } from "hooks/store"; // services import { FileService } from "services/file.service"; const fileService = new FileService(); // types import { TIssueOperations } from "./issue-detail"; // hooks import useDebounce from "hooks/use-debounce"; export type IssueDescriptionInputProps = { 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 IssueDescriptionInput: FC = observer((props) => { const { disabled, value, workspaceSlug, setIsSubmitting, issueId, issueOperations, projectId } = props; // states const [descriptionHTML, setDescriptionHTML] = useState(value); const [localIssueDescription, setLocalIssueDescription] = useState({ id: issueId, description_html: typeof value === "string" && value != "" ? value : "

", }); // store hooks const { mentionHighlights, mentionSuggestions } = useMention(); const { getWorkspaceBySlug } = useWorkspace(); // hooks const debouncedValue = useDebounce(descriptionHTML, 1500); // computed values const workspaceId = getWorkspaceBySlug(workspaceSlug)?.id as string; useEffect(() => { if (value) setDescriptionHTML(value); }, [value]); useEffect(() => { if (issueId && value) setLocalIssueDescription({ id: issueId, description_html: typeof value === "string" && value != "" ? value : "

", }); // eslint-disable-next-line react-hooks/exhaustive-deps }, [issueId, value]); useEffect(() => { if (debouncedValue || debouncedValue === "") { setIsSubmitting("submitted"); issueOperations .update(workspaceSlug, projectId, issueId, { description_html: 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]); if (!descriptionHTML && descriptionHTML !== "") { return ( ); } if (disabled) { return ( ); } return ( { // setShowAlert(true); setIsSubmitting("submitting"); setDescriptionHTML(description_html); }} mentionSuggestions={mentionSuggestions} mentionHighlights={mentionHighlights} /> ); });