clean up course tabs, unify logic

This commit is contained in:
austinkelsay 2025-04-24 14:19:31 -05:00
parent f3d667a0ba
commit 156e2ffc7b
No known key found for this signature in database
GPG Key ID: 5A763922E5BA08EE
3 changed files with 29 additions and 30 deletions

View File

@ -118,7 +118,7 @@ const DocumentLesson = ({ lesson, course, decryptionPerformed, isPaid, setComple
} }
if (isPaid && !decryptionPerformed) { if (isPaid && !decryptionPerformed) {
return ( return (
<div className="w-full p-8 rounded-lg flex flex-col items-center justify-center bg-gray-100 dark:bg-gray-800"> <div className="w-full p-8 rounded-lg flex flex-col items-center justify-center">
<div className="mx-auto py-auto"> <div className="mx-auto py-auto">
<i className="pi pi-lock text-[60px] text-red-500"></i> <i className="pi pi-lock text-[60px] text-red-500"></i>
</div> </div>

View File

@ -11,7 +11,8 @@ const appConfig = {
], ],
authorPubkeys: [ authorPubkeys: [
'f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741', 'f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741',
'c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345' 'c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345',
'6260f29fa75c91aaa292f082e5e87b438d2ab4fdf96af398567b01802ee2fcd4'
], ],
customLightningAddresses: [ customLightningAddresses: [
{ {

View File

@ -186,6 +186,17 @@ const Course = () => {
const [activeTab, setActiveTab] = useState('overview'); // Default to overview tab const [activeTab, setActiveTab] = useState('overview'); // Default to overview tab
const navbarHeight = 60; // Match the height from Navbar component const navbarHeight = 60; // Match the height from Navbar component
// Memoized function to get the tab map based on view mode
const getTabMap = useMemo(() => {
const baseTabMap = ['overview', 'content', 'qa'];
if (isMobileView) {
const mobileTabMap = [...baseTabMap];
mobileTabMap.splice(2, 0, 'lessons');
return mobileTabMap;
}
return baseTabMap;
}, [isMobileView]);
useEffect(() => { useEffect(() => {
if (router.isReady && router.query.slug) { if (router.isReady && router.query.slug) {
const { slug } = router.query; const { slug } = router.query;
@ -320,22 +331,12 @@ const Course = () => {
}; };
const toggleTab = (index) => { const toggleTab = (index) => {
const tabMap = ['overview', 'content', 'qa']; const tabName = getTabMap[index];
// If mobile and we have the lessons tab, insert it at index 2
if (isMobileView) {
tabMap.splice(2, 0, 'lessons');
}
const tabName = tabMap[index];
setActiveTab(tabName); setActiveTab(tabName);
// Only show/hide sidebar on mobile - desktop keeps sidebar visible // Only show/hide sidebar on mobile - desktop keeps sidebar visible
if (isMobileView) { if (isMobileView) {
if (tabName === 'lessons') { setSidebarVisible(tabName === 'lessons');
setSidebarVisible(true);
} else {
setSidebarVisible(false);
}
} }
}; };
@ -345,12 +346,7 @@ const Course = () => {
// Map active tab name back to index for MenuTab // Map active tab name back to index for MenuTab
const getActiveTabIndex = () => { const getActiveTabIndex = () => {
const tabMap = ['overview', 'content', 'qa']; return getTabMap.indexOf(activeTab);
if (isMobileView) {
tabMap.splice(2, 0, 'lessons');
}
return tabMap.indexOf(activeTab);
}; };
// Create tab items for MenuTab // Create tab items for MenuTab
@ -387,11 +383,11 @@ const Course = () => {
const handleKeyDown = (e) => { const handleKeyDown = (e) => {
if (e.key === 'ArrowRight') { if (e.key === 'ArrowRight') {
const currentIndex = getActiveTabIndex(); const currentIndex = getActiveTabIndex();
const nextIndex = (currentIndex + 1) % getTabItems().length; const nextIndex = (currentIndex + 1) % getTabMap.length;
toggleTab(nextIndex); toggleTab(nextIndex);
} else if (e.key === 'ArrowLeft') { } else if (e.key === 'ArrowLeft') {
const currentIndex = getActiveTabIndex(); const currentIndex = getActiveTabIndex();
const prevIndex = (currentIndex - 1 + getTabItems().length) % getTabItems().length; const prevIndex = (currentIndex - 1 + getTabMap.length) % getTabMap.length;
toggleTab(prevIndex); toggleTab(prevIndex);
} }
}; };
@ -400,7 +396,7 @@ const Course = () => {
return () => { return () => {
document.removeEventListener('keydown', handleKeyDown); document.removeEventListener('keydown', handleKeyDown);
}; };
}, [activeTab]); }, [activeTab, getTabMap, toggleTab]);
// Render the QA section (empty for now) // Render the QA section (empty for now)
const renderQASection = () => { const renderQASection = () => {
@ -586,7 +582,12 @@ const Course = () => {
<CourseSidebar <CourseSidebar
lessons={uniqueLessons} lessons={uniqueLessons}
activeIndex={activeIndex} activeIndex={activeIndex}
onLessonSelect={handleLessonSelect} onLessonSelect={(index) => {
handleLessonSelect(index);
if (isMobileView) {
setActiveTab('content'); // Use the tab name directly
}
}}
completedLessons={completedLessons} completedLessons={completedLessons}
isMobileView={isMobileView} isMobileView={isMobileView}
sidebarVisible={sidebarVisible} sidebarVisible={sidebarVisible}
@ -604,12 +605,9 @@ const Course = () => {
activeIndex={activeIndex} activeIndex={activeIndex}
onLessonSelect={(index) => { onLessonSelect={(index) => {
handleLessonSelect(index); handleLessonSelect(index);
onLessonSelect={(index) => { if (isMobileView) {
handleLessonSelect(index); setActiveTab('content'); // Use the tab name directly
if (isMobileView) { }
setActiveTab('content'); // Use the tab name directly
}
}}
}} }}
completedLessons={completedLessons} completedLessons={completedLessons}
isMobileView={isMobileView} isMobileView={isMobileView}