This commit is contained in:
rgrgogu
2026-07-20 03:24:40 +08:00
parent 51133a51a5
commit 84311e632b
4 changed files with 30 additions and 6 deletions
@@ -211,7 +211,7 @@ export default function AddLesson() {
const navigate = useNavigate();
const { courseId, unitId } = useParams();
const {
createLesson, saveLessonPage, fetchUnit, unit, loading,
createLesson, saveLessonPage, fetchUnit, fetchCourse, unit, course, loading,
syncLessonRequirements,
} = useCourses();
const { user } = useAuth();
@@ -232,6 +232,9 @@ export default function AddLesson() {
useEffect(() => {
fetchUnit(courseId, unitId);
if (!course || String(course.course_id) !== String(courseId)) {
fetchCourse(courseId);
}
}, [courseId, unitId]);
const handleNext = async () => {
@@ -288,7 +291,11 @@ export default function AddLesson() {
</Button>
<div>
<h1 className="text-xl font-semibold">Create Lesson</h1>
<p className="text-sm text-muted-foreground">Add a new lesson to this unit.</p>
<p className="text-sm text-muted-foreground">
Creates a new lesson in the shared Lessons Library and attaches it to
{unit ? ` "${unit.title}"` : " this unit"} — affiliated with
{course ? ` "${course.title}"` : " this course"}.
</p>
</div>
</div>
@@ -34,7 +34,7 @@ function FieldError({ message }) {
export default function EditLesson() {
const navigate = useNavigate();
const { courseId, unitId, lessonId } = useParams();
const { fetchLesson, updateLesson, course, unit, loading, fetchLessonRequirements, syncLessonRequirements } = useCourses();
const { fetchLesson, updateLesson, fetchCourse, fetchUnit, course, unit, loading, fetchLessonRequirements, syncLessonRequirements } = useCourses();
const { user } = useAuth();
const [lessonTitle, setLessonTitle] = useState("");
@@ -60,6 +60,10 @@ export default function EditLesson() {
objectives: lesson.objectives?.map((v) => ({ value: v.text })) ?? [],
});
})();
fetchUnit(courseId, unitId);
if (!course || String(course.course_id) !== String(courseId)) {
fetchCourse(courseId);
}
}, [courseId, unitId, lessonId]);
const onSubmit = async (data) => {
@@ -90,7 +94,11 @@ export default function EditLesson() {
</Button>
<div>
<h1 className="text-xl font-semibold">Edit Lesson</h1>
<p className="text-sm text-muted-foreground">Update lesson details.</p>
<p className="text-sm text-muted-foreground">
Lessons live in the shared Library — changes here apply everywhere this
lesson is used, not just{unit ? ` "${unit.title}"` : " this unit"}
{course ? ` (${course.title})` : ""}.
</p>
</div>
</div>
@@ -70,6 +70,9 @@ export default function LessonsList() {
{unit?.description && (
<p className="text-sm text-muted-foreground mt-0.5">{unit.description}</p>
)}
<p className="text-xs text-muted-foreground mt-1.5">
Affiliated with course: <span className="font-medium text-foreground">{course?.title ?? "—"}</span>
</p>
</div>
{/* Stats row */}
@@ -30,7 +30,7 @@ function FieldError({ message }) {
export default function EditUnit() {
const [unitTitle, setUnitTitle] = useState("");
const { courseId, unitId } = useParams();
const { fetchUnit, updateUnit, course, loading, fetchUnitRequirements, syncUnitRequirements } = useCourses();
const { fetchUnit, updateUnit, fetchCourse, course, loading, fetchUnitRequirements, syncUnitRequirements } = useCourses();
const { user } = useAuth();
const navigate = useNavigate();
@@ -51,6 +51,9 @@ export default function EditUnit() {
});
setUnitTitle(unit.title ?? "");
})();
if (!course || String(course.course_id) !== String(courseId)) {
fetchCourse(courseId);
}
}, [courseId, unitId]);
@@ -76,7 +79,10 @@ export default function EditUnit() {
</Button>
<div>
<h1 className="text-xl font-semibold">Edit Unit</h1>
<p className="text-sm text-muted-foreground">Update unit details.</p>
<p className="text-sm text-muted-foreground">
Units live in the shared Library — changes here apply everywhere this unit
is used{course ? `, not just "${course.title}"` : ""}.
</p>
</div>
</div>