import { useEffect, useState } from "react"; import type { TResType } from "./DiscussionListCard"; import { get } from "../../request"; import type { ICommentListResponse } from "../../api/Comment"; import DiscussionItem, { type IComment } from "./DiscussionItem"; interface IWidget { resId?: string; resType?: TResType; onSelect?: Function; onReply?: Function; } const QaListWidget = ({ resId, resType, onSelect, _____onReply }: IWidget) => { const [data, setData] = useState(); useEffect(() => { if (!resType || !resType) { return; } let url: string = `/v2/discussion?res_type=${resType}&view=res_id&id=${resId}`; url += "&dir=asc&type=qa&status=active,close"; console.info("api request", url); get(url).then((json) => { if (json.ok) { console.debug("discussion api response", json); const items: IComment[] = json.data.rows.map((item, _id) => { return { id: item.id, resId: item.res_id, resType: item.res_type, type: item.type, user: item.editor, title: item.title, parent: item.parent, tplId: item.tpl_id, content: item.content, summary: item.summary, status: item.status, childrenCount: item.children_count, createdAt: item.created_at, updatedAt: item.updated_at, }; }); setData(items); } }); }, []); return ( <> {data ?.filter((value) => !value.parent) .map((question, index) => { return (
, value: IComment ) => { if (typeof onSelect !== "undefined") { onSelect(e, value); } }} />
{data ?.filter((value) => value.parent === question.id) .map((item, id) => { return ; })}
); })} ); }; export default QaListWidget;