import React, { useState } from 'react'; import { usePageContext } from '../renderer/usePageContext'; import CourseSidebar from './CourseSidebar'; export default function CourseLayout({ title, coursePages }: { title?: string; coursePages: Array; }) { const pageContext = usePageContext(); let pageQuery = 1; const { search } = pageContext.urlParsed; if (search?.page) { const pageInt = parseInt(search.page, 10); pageQuery = isNaN(pageInt) || pageInt < 1 ? 1 : pageInt; } const [currentPageIndex, setCurrentPage] = useState(pageQuery - 1); const nextIsDisabled = currentPageIndex >= coursePages.length - 1; const prevIsDisabled = currentPageIndex === 0; const currentView = coursePages[currentPageIndex]; const handleForward = () => { if (currentPageIndex < coursePages.length - 1) { setCurrentPage(currentPageIndex + 1); } }; const handleBackward = () => { if (currentPageIndex > 0) { setCurrentPage(currentPageIndex - 1); } }; return (
{title && (

{title}

)}
{currentView}
); }