Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy course display fix to staging #67

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions frontend/src/routes/_dashboardLayout/courses/$courseSlug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,46 @@ const SingleCourse: React.FC = () => {
(status) => status.course?.documentId === course.documentId,
);

if (!courseStatus) return;

const progressMap: Record<string, number> = courseStatus.sections.reduce(
(acc, sectionStatus) => ({
...acc,
...Object.fromEntries(
sectionStatus.modules.map((moduleStatus) => [
moduleStatus.module.documentId,
moduleStatus.progress,
]),
),
}),
{},
);
let progressMap: Record<string, number> = {};

if (courseStatus) {
progressMap = courseStatus.sections.reduce(
(acc, sectionStatus) => ({
...acc,
...Object.fromEntries(
sectionStatus.modules.map((moduleStatus) => [
moduleStatus.module.documentId,
moduleStatus.progress,
]),
),
}),
{},
);
}

setModuleProgress(progressMap);

// Ensure active states are only set if not already
if (!activeModuleDocumentId && !activeSectionDocumentId) {
const firstIncompleteModule = course.sections
.flatMap((section) => section.modules)
.find((module) => (progressMap[module.documentId] || 0) < 100);
let firstIncompleteModule: Module | undefined;

if (courseStatus) {
firstIncompleteModule = course.sections
.flatMap((section) => section.modules)
.find((module) => (progressMap[module.documentId] || 0) < 100);
}

// If no progress or all modules are complete, select the first module
if (!firstIncompleteModule) {
firstIncompleteModule = course.sections[0]?.modules[0];
}

if (firstIncompleteModule) {
setActiveModuleDocumentId(firstIncompleteModule.documentId);
setActiveSectionDocumentId(
course.sections.find((section) =>
section.modules.some(
(module) =>
module.documentId === firstIncompleteModule.documentId,
module.documentId === firstIncompleteModule?.documentId,
),
)?.documentId || null,
);
Expand Down Expand Up @@ -339,7 +349,7 @@ const SingleCourse: React.FC = () => {
className="mb-6 flex items-center justify-center gap-2 rounded-3xl border border-slate-400 p-2 px-4 text-left text-black hover:bg-white dark:text-white dark:hover:text-black"
>
<ArrowLeft />
<span className="text-md font-semibol">Back to courses</span>
<span className="text-md font-semibold">Back to courses</span>
</Link>
<ul className="mb-6 flex flex-wrap gap-2">
{course.categories.map((category) => (
Expand Down
Loading