import React from 'react'; import NavBar from '../../components/Navigation/NavBar'; import { ContentHeader, GlobalTypes } from '@thoughtindustries/content'; import { CourseGroup } from '@thoughtindustries/content/src/graphql/global-types'; import { gql, useQuery } from '@apollo/client'; import { usePageContext } from '../../renderer/usePageContext'; export { Page }; export { documentProps }; interface PageProps { courseGroup?: CourseGroup | null; error?: string; } const documentProps = { title: 'Course Detail', description: 'Course detail page' }; // Use the same query as the server-side for consistency const COURSE_GROUP_QUERY = gql` query CourseGroupBySlug($slug: Slug!) { CourseGroupBySlug(slug: $slug) { id title description slug asset detailAsset videoAsset rating ratingsCount language archived metaTitle metaDescription authors courses { id title } customFields } } `; function Page(props: PageProps) { const pageContext = usePageContext(); const courseSlug = pageContext.routeParams?.courseSlug; // For Client Routing: ALWAYS fetch data on the client // pageProps will be empty {} during client navigation // Only skip if we have SSR data from initial page load const hasSSRData = props.courseGroup !== undefined && props.courseGroup !== null; const { data, loading, error: queryError } = useQuery(COURSE_GROUP_QUERY, { variables: { slug: courseSlug }, skip: !courseSlug || (hasSSRData && pageContext.isHydration !== false), fetchPolicy: 'cache-first', // Use cache if available notifyOnNetworkStatusChange: true }); // Use SSR data if available, otherwise use client-fetched data const courseGroup = hasSSRData ? props.courseGroup : data?.CourseGroupBySlug ?? null; const error = props.error || queryError?.message; // Show loading state during client-side data fetching if (loading) { return (

Loading course...

); } if (error) { return (
⚠️

Error Loading Course

{error}

); } if (!courseGroup) { return (

Loading course...

); } return (
{/* Header with Navigation */} {/* Main Content Area */}
{/* Left Section - Main Content */}
{/* Content Header Component */}
{/* Right Sidebar */}
{/* Enroll Today Box */}

ENROLL TODAY

{courseGroup.courses && courseGroup.courses.length === 1 ? ( Enroll Now ) : courseGroup.courses && courseGroup.courses.length > 1 ? (
{courseGroup.courses.map((course, index) => (
{course.title || `Course ${index + 1}`}
Enroll Now
{index < (courseGroup.courses?.length || 0) - 1 && (
)}
))}
) : (

No courses available for enrollment

)}
{/* What's Included Box */}

WHAT'S INCLUDED

Access your courses anytime, anywhere, with a computer, tablet or smartphone

Videos, quizzes and interactive content designed for a proven learning experience

Unlimited access. Take your courses at your time and pace

{/* Footer */}
); }