From 63fb170a8fc42bfc2c6c42b8a4bd83a275b5bcc0 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Fri, 26 Jun 2026 03:52:00 -0700 Subject: [PATCH] Align exam-prep practice lists with Learn English card grid. Reuse ModulePracticeCard across catalog course, unit, and lesson practice views with optional delete in the card menu. Co-authored-by: Cursor --- .../LessonPracticesPage.tsx | 26 ++- .../CatalogCoursePracticesPanel.tsx | 167 +----------------- .../components/ModulePracticeCard.tsx | 14 ++ .../components/UnitPracticesPanel.tsx | 167 +----------------- 4 files changed, 55 insertions(+), 319 deletions(-) diff --git a/src/pages/content-management/LessonPracticesPage.tsx b/src/pages/content-management/LessonPracticesPage.tsx index 494ff57..4dce5b7 100644 --- a/src/pages/content-management/LessonPracticesPage.tsx +++ b/src/pages/content-management/LessonPracticesPage.tsx @@ -24,6 +24,7 @@ import { import { Badge } from "../../components/ui/badge"; import { Button } from "../../components/ui/button"; import { PracticeActionButton } from "./components/PracticeActionButton"; +import { ModulePracticeCard } from "./components/ModulePracticeCard"; import { Card, CardContent } from "../../components/ui/card"; import { Dialog, @@ -426,7 +427,12 @@ export function LessonPracticesPage() {
-
+
+ ) : isExamPrep ? ( +
+ {filteredPractices.map((p) => ( + void navigate(editPracticeHref(p.id))} + onPublish={() => + void handlePracticePublishStatus(p.id, "PUBLISHED") + } + onSaveAsDraft={() => + void handlePracticePublishStatus(p.id, "DRAFT") + } + onDelete={() => setPracticeToDelete(p)} + /> + ))} +
) : ( filteredPractices.map((p, i) => ( void - onDelete?: () => void - onTogglePublishStatus?: (nextStatus: PracticePublishStatus) => void - publishStatusUpdating?: boolean -}) { - const [imgFailed, setImgFailed] = useState(false) - const thumb = resolveThumbnailForPreview(practice.story_image) - const showThumb = Boolean(thumb) && !imgFailed - - return ( - - -
-
-
- {showThumb ? ( - <> - setImgFailed(true)} - /> -
- - ) : ( -
-
- -
- - No cover image - -
- )} -
-
- {index + 1} / {total} -
-
- -
-
-
-

- {practice.title || "Untitled practice"} -

- {practice.story_description ? ( -

- {practice.story_description} -

- ) : null} -
- {onTogglePublishStatus ? ( - - ) : null} -
- - {practice.quick_tips?.trim() ? ( -
-

- Quick tips -

-

- {practice.quick_tips} -

-
- ) : null} - -
- - - Question set {practice.question_set_id} - - - - {formatPracticeDate(practice.created_at)} - - {onEdit ? ( - - ) : null} - {onDelete ? ( - - ) : null} -
-
-
- - - ) -} - type CatalogCoursePracticesPanelProps = { catalogCourseId: number programType: string @@ -353,19 +205,16 @@ export function CatalogCoursePracticesPanel({

) : ( -
- {filteredPractices.map((practice, index) => ( - + {filteredPractices.map((practice) => ( + navigate(editPracticeHref(practice.id))} + onPublish={() => void handlePracticePublishStatus(practice.id, "PUBLISHED")} + onSaveAsDraft={() => void handlePracticePublishStatus(practice.id, "DRAFT")} onDelete={() => setPracticeToDelete(practice)} - onTogglePublishStatus={(nextStatus) => - void handlePracticePublishStatus(practice.id, nextStatus) - } - publishStatusUpdating={publishStatusUpdatingId === practice.id} /> ))}
diff --git a/src/pages/content-management/components/ModulePracticeCard.tsx b/src/pages/content-management/components/ModulePracticeCard.tsx index e40c0c2..9d3ad64 100644 --- a/src/pages/content-management/components/ModulePracticeCard.tsx +++ b/src/pages/content-management/components/ModulePracticeCard.tsx @@ -27,6 +27,7 @@ type ModulePracticeCardProps = { onEdit?: () => void; onPublish?: () => void; onSaveAsDraft?: () => void; + onDelete?: () => void; }; export function ModulePracticeCard({ @@ -35,6 +36,7 @@ export function ModulePracticeCard({ onEdit, onPublish, onSaveAsDraft, + onDelete, }: ModulePracticeCardProps) { const isPublished = isPracticePublished(practice); const statusLabel = practicePublishStatus(practice) ?? "DRAFT"; @@ -134,6 +136,18 @@ export function ModulePracticeCard({ > {isPublished ? "Save as draft" : "Publish practice"} + {onDelete ? ( + { + e.stopPropagation(); + onDelete(); + }} + > + Delete practice + + ) : null}
diff --git a/src/pages/content-management/components/UnitPracticesPanel.tsx b/src/pages/content-management/components/UnitPracticesPanel.tsx index 96231bf..2d617d0 100644 --- a/src/pages/content-management/components/UnitPracticesPanel.tsx +++ b/src/pages/content-management/components/UnitPracticesPanel.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useMemo, useState } from "react" import { useNavigate } from "react-router-dom" -import { BookOpen, Clock, Edit2, Hash, Loader2, RefreshCw, Trash2 } from "lucide-react" +import { BookOpen, Loader2, RefreshCw } from "lucide-react" import { toast } from "sonner" import { deleteExamPrepPractice, @@ -8,9 +8,7 @@ import { setExamPrepPracticePublishStatus, } from "../../../api/courses.api" import { unwrapPracticesList } from "../../../lib/parentContextPractice" -import { Badge } from "../../../components/ui/badge" import { Button } from "../../../components/ui/button" -import { Card, CardContent } from "../../../components/ui/card" import { Dialog, DialogContent, @@ -19,13 +17,11 @@ import { DialogTitle, } from "../../../components/ui/dialog" import { ContentListSearchFilterBar } from "./ContentListSearchFilterBar" -import { ContentPublishStatusChip } from "./ContentPublishStatusChip" +import { ModulePracticeCard } from "./ModulePracticeCard" import { filterBySearchAndPublishStatus, type PublishStatusFilter, } from "../../../lib/contentListFilters" -import { resolveThumbnailForPreview } from "../../../lib/videoPreview" -import { cn } from "../../../lib/utils" import type { ParentContextPractice, PracticePublishStatus, @@ -45,150 +41,6 @@ function extractPracticesPage( return { practices, totalCount } } -function formatPracticeDate(iso: string): string { - const d = new Date(iso) - return Number.isNaN(d.getTime()) - ? iso - : d.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" }) -} - -function PracticeCard({ - practice, - index, - total, - onEdit, - onDelete, - onTogglePublishStatus, - publishStatusUpdating, -}: { - practice: ParentContextPractice - index: number - total: number - onEdit?: () => void - onDelete?: () => void - onTogglePublishStatus?: (nextStatus: PracticePublishStatus) => void - publishStatusUpdating?: boolean -}) { - const [imgFailed, setImgFailed] = useState(false) - const thumb = resolveThumbnailForPreview(practice.story_image) - const showThumb = Boolean(thumb) && !imgFailed - - return ( - - -
-
-
- {showThumb ? ( - <> - setImgFailed(true)} - /> -
- - ) : ( -
-
- -
- - No cover image - -
- )} -
-
- {index + 1} / {total} -
-
- -
-
-
-

- {practice.title || "Untitled practice"} -

- {practice.story_description ? ( -

- {practice.story_description} -

- ) : null} -
- {onTogglePublishStatus ? ( - - ) : null} -
- - {practice.quick_tips?.trim() ? ( -
-

- Quick tips -

-

- {practice.quick_tips} -

-
- ) : null} - -
- - - Question set {practice.question_set_id} - - - - {formatPracticeDate(practice.created_at)} - - {onEdit ? ( - - ) : null} - {onDelete ? ( - - ) : null} -
-
-
- - - ) -} - type UnitPracticesPanelProps = { unitId: number programType: string @@ -355,19 +207,16 @@ export function UnitPracticesPanel({

) : ( -
- {filteredPractices.map((practice, index) => ( - + {filteredPractices.map((practice) => ( + navigate(editPracticeHref(practice.id))} + onPublish={() => void handlePracticePublishStatus(practice.id, "PUBLISHED")} + onSaveAsDraft={() => void handlePracticePublishStatus(practice.id, "DRAFT")} onDelete={() => setPracticeToDelete(practice)} - onTogglePublishStatus={(nextStatus) => - void handlePracticePublishStatus(practice.id, nextStatus) - } - publishStatusUpdating={publishStatusUpdatingId === practice.id} /> ))}