diff --git a/apps/web/src/app/main/layout/BasePost/FilterSection.tsx b/apps/web/src/app/main/layout/BasePost/FilterSection.tsx index d7eccd4..084878c 100755 --- a/apps/web/src/app/main/layout/BasePost/FilterSection.tsx +++ b/apps/web/src/app/main/layout/BasePost/FilterSection.tsx @@ -28,7 +28,7 @@ export default function FilterSection() { handleTermChange( diff --git a/apps/web/src/app/main/path/components/TermInfo.tsx b/apps/web/src/app/main/path/components/TermInfo.tsx index 718096f..8f7e7ac 100644 --- a/apps/web/src/app/main/path/components/TermInfo.tsx +++ b/apps/web/src/app/main/path/components/TermInfo.tsx @@ -1,12 +1,12 @@ import { Tag } from "antd"; -import { PostDto, TaxonomySlug } from "@nice/common"; +import { PostDto, TaxonomySlug, TermDto } from "@nice/common"; -const TermInfo = ({ post }: { post: PostDto }) => { +const TermInfo = ({ terms = [] }: { terms?: TermDto[] }) => { return (
- {post?.terms && post?.terms?.length > 0 ? ( + {terms && terms?.length > 0 ? (
- {post?.terms?.map((term: any) => { + {terms?.map((term: any) => { return ( {
{course?.subTitle &&
{course?.subTitle}
} - +
- +
); } - diff --git a/apps/web/src/components/models/term/term-parent-selector.tsx b/apps/web/src/components/models/term/term-parent-selector.tsx index 2b479b6..58c1765 100755 --- a/apps/web/src/components/models/term/term-parent-selector.tsx +++ b/apps/web/src/components/models/term/term-parent-selector.tsx @@ -1,50 +1,56 @@ import { api } from "@nice/client/"; -import { Checkbox, Form } from "antd"; +import { Checkbox, Skeleton } from "antd"; import { TermDto } from "@nice/common"; -import { useCallback, useEffect, useState } from "react"; +import React from "react"; export default function TermParentSelector({ - value, - onChange, - className, - placeholder = "选择分类", - multiple = true, - taxonomyId, - domainId, - style, -}: any) { - const [selectedValues, setSelectedValues] = useState<string[]>([]); // 用于存储选中的值 - const { - data, - isLoading, - }: { data: TermDto[]; isLoading: boolean } = api.term.findMany.useQuery({ - where: { - taxonomy: { - id: taxonomyId, - }, - parentId: null - }, - }); - const handleCheckboxChange = (checkedValues: string[]) => { - setSelectedValues(checkedValues); // 更新选中的值 - if (onChange) { - onChange(checkedValues); // 调用外部传入的 onChange 回调 - } - }; - return ( - <div className={className} style={style}> - <Form onFinish={null}> - <Form.Item name="categories"> - <Checkbox.Group onChange={handleCheckboxChange}> - {data?.map((category) => ( - <div className="w-full h-9 p-2 my-1"> - <Checkbox checked={value?.includes(category.id)} className="text-base text-slate-700" key={category.id} value={category.id}> - {category.name} - </Checkbox> - </div> - ))} - </Checkbox.Group> - </Form.Item> - </Form> - </div> - ) -} \ No newline at end of file + value, + onChange, + className, + taxonomyId, + domainId = undefined, + style, +}: { + value?: string[]; + onChange?: (value: string[]) => void; + className?: string; + taxonomyId: string; + domainId?: string; + style?: React.CSSProperties; +}) { + const { data, isLoading }: { data: TermDto[]; isLoading: boolean } = + api.term.findMany.useQuery({ + where: { + taxonomyId: taxonomyId, + parentId: null, + domainId, + }, + }); + const handleCheckboxChange = (checkedValues: string[]) => { + // setSelectedValues(checkedValues); // 更新选中的值 + if (onChange) { + onChange(checkedValues); // 调用外部传入的 onChange 回调 + } + }; + return ( + <div className={className} style={style}> + {isLoading ? ( + <Skeleton + paragraph={{ + rows: 4, + }}></Skeleton> + ) : ( + <Checkbox.Group value={value} onChange={handleCheckboxChange}> + {data?.map((category) => ( + <div className="w-full h-9 p-2 my-1" key={category.id}> + <Checkbox + className="text-base text-slate-700" + value={category.id}> + {category.name} + </Checkbox> + </div> + ))} + </Checkbox.Group> + )} + </div> + ); +}