training_data/apps/web/src/components/models/course/detail/CourseDetailDescription.tsx

91 lines
2.9 KiB
TypeScript
Raw Normal View History

2025-02-26 15:48:11 +08:00
import { Course, TaxonomySlug } from "@nice/common";
2025-02-24 11:50:33 +08:00
import React, { useContext, useMemo } from "react";
2025-02-26 15:48:11 +08:00
import { Image, Typography, Skeleton, Tag } from "antd"; // 引入 antd 组件
2025-02-23 22:51:22 +08:00
import { CourseDetailContext } from "./CourseDetailContext";
2025-02-26 15:48:11 +08:00
import { useNavigate, useParams } from "react-router-dom";
2025-02-27 21:45:40 +08:00
import { useStaff } from "@nice/client";
import { useAuth } from "@web/src/providers/auth-provider";
import TermInfo from "@web/src/app/main/path/components/TermInfo";
import { PictureOutlined } from "@ant-design/icons";
2025-02-23 22:51:22 +08:00
2025-02-24 10:16:39 +08:00
export const CourseDetailDescription: React.FC = () => {
2025-02-27 21:45:40 +08:00
const {
course,
canEdit,
isLoading,
selectedLectureId,
setSelectedLectureId,
userIsLearning,
lecture = null,
} = useContext(CourseDetailContext);
const { Paragraph } = Typography;
const { user } = useAuth();
const { update } = useStaff();
2025-02-24 11:50:33 +08:00
const firstLectureId = useMemo(() => {
return course?.sections?.[0]?.lectures?.[0]?.id;
}, [course]);
const navigate = useNavigate();
2025-02-26 15:48:11 +08:00
const { id } = useParams();
2025-02-23 22:51:22 +08:00
return (
2025-02-26 22:38:28 +08:00
// <div className="w-full bg-white shadow-md rounded-lg border border-gray-200 p-5 my-4">
2025-02-26 23:01:58 +08:00
<div className="w-full px-5 my-2">
2025-02-23 22:51:22 +08:00
{isLoading || !course ? (
<Skeleton active paragraph={{ rows: 4 }} />
) : (
2025-02-26 15:48:11 +08:00
<div className="space-y-2">
2025-02-27 21:45:40 +08:00
{!selectedLectureId && (
<div className="relative mb-4 overflow-hidden flex justify-center items-center">
{
2025-02-27 23:50:07 +08:00
<div
className="w-full rounded-xl aspect-video bg-cover bg-center z-0"
style={{
backgroundImage: `url(${course?.meta?.thumbnail || "/placeholder.webp"})`,
}}
2025-02-24 10:16:39 +08:00
/>
2025-02-27 21:45:40 +08:00
}
<div
onClick={async () => {
setSelectedLectureId(firstLectureId);
if (!userIsLearning) {
await update.mutateAsync({
where: { id: user?.id },
data: {
learningPosts: {
connect: {
id: course.id,
},
},
},
});
}
}}
2025-02-27 23:50:07 +08:00
className="absolute rounded-xl top-0 left-0 right-0 bottom-0 z-10 bg-[rgba(0,0,0,0.3)] transition-all duration-300 ease-in-out hover:bg-[rgba(0,0,0,0.7)] cursor-pointer group">
2025-02-27 21:45:40 +08:00
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-white text-4xl z-10 opacity-0 group-hover:opacity-100 transition-opacity duration-300">
2025-02-24 11:50:33 +08:00
</div>
2025-02-24 10:16:39 +08:00
</div>
2025-02-27 21:45:40 +08:00
</div>
2025-02-24 10:16:39 +08:00
)}
2025-02-24 09:33:03 +08:00
<div className="text-lg font-bold">{"课程简介:"}</div>
2025-02-26 22:38:28 +08:00
<div className="flex flex-col gap-2">
<div className="flex gap-2 flex-wrap items-center float-start">
{course?.subTitle && <div>{course?.subTitle}</div>}
2025-02-27 21:45:40 +08:00
<TermInfo post={course}></TermInfo>
2025-02-26 15:48:11 +08:00
</div>
2025-02-24 09:33:03 +08:00
</div>
2025-02-23 22:51:22 +08:00
<Paragraph
2025-02-24 09:33:03 +08:00
className="text-gray-600"
2025-02-23 22:51:22 +08:00
ellipsis={{
rows: 3,
expandable: true,
symbol: "展开",
onExpand: () => console.log("展开"),
}}>
2025-02-24 09:33:03 +08:00
{course?.content}
2025-02-23 22:51:22 +08:00
</Paragraph>
</div>
)}
</div>
);
};