@@ -31,12 +31,6 @@ const MemberValidShow = dynamic<any>(
3131 ssr : false ,
3232 }
3333) ;
34- const MemberNotValidShow = dynamic < any > (
35- ( ) => import ( '@/components/user/MemberNotValidShow' ) ,
36- {
37- ssr : false ,
38- }
39- ) ;
4034
4135import dynamic from 'next/dynamic' ;
4236import { isActiveLesson } from '@/utils/basics/links' ;
@@ -64,27 +58,28 @@ export default function PostLayout({
6458 const [ videoProgress , setVideoProgress ] = useState ( 0 ) ;
6559 const [ playing , setPlaying ] = useState ( false ) ;
6660 const [ currentLesson , setCurrentLesson ] = useState < string | null > ( null ) ;
61+ const [ sectionLesson , setSectionLesson ] = useState < Post | undefined > (
62+ undefined
63+ ) ;
6764 useEffect ( ( ) => {
6865 setHref ( location . href ) ;
6966 setPlaying ( false ) ;
7067 setVideoProgress ( 0 ) ;
7168 setCurrentLesson ( post . id ) ;
72- } , [ post ] ) ;
7369
74- function isLockedLesson ( ) {
7570 // Only lockdown lessons
7671 if ( post . _type != PostType . lesson ) {
77- return false ;
72+ setSectionLesson ( undefined ) ;
7873 }
7974 //If lesson, without assigned course (or course is not yet published)
8075 if ( post . _type == PostType . lesson && ! course ) {
81- return true ;
76+ setSectionLesson ( undefined ) ;
8277 }
8378 const lessons : Post [ ] = [ ] ;
8479 course ?. sections ?. map ( ( s ) => s ?. lessons ?. map ( ( l ) => lessons . push ( l ) ) ) ;
85- const currentLesson = lessons . find ( ( l ) => l . slug === post . slug ) ;
86- return currentLesson ?. access_mode != AccessMode . free ;
87- }
80+ setSectionLesson ( lessons . find ( ( l ) => l . slug === post . slug ) ) ;
81+ } , [ post , course ] ) ;
82+
8883 const pluralType = pluralize ( post ) ;
8984
9085 function backButton ( ) {
@@ -308,7 +303,7 @@ export default function PostLayout({
308303 </ >
309304 ) ;
310305 } ;
311-
306+ console . log ( sectionLesson ) ;
312307 return (
313308 < >
314309 { /* DIV TO AVOID GRID GAP */ }
@@ -317,32 +312,21 @@ export default function PostLayout({
317312 { post . _type !== PostType . page && (
318313 < section className = "" >
319314 { /* MEDIA */ }
320- { ! isLockedLesson ( ) ? (
321- < PostMedia
322- post = { post }
323- playing = { playing }
324- setPlaying = { setPlaying }
325- videoProgress = { videoProgress }
326- setVideoProgress = { setVideoProgress }
327- />
328- ) : user && user ?. uid ? (
329- < >
330- < MemberValidShow user = { user } >
331- < PostMedia
332- post = { post }
333- playing = { playing }
334- setPlaying = { setPlaying }
335- videoProgress = { videoProgress }
336- setVideoProgress = { setVideoProgress }
337- />
338- </ MemberValidShow >
339- < MemberNotValidShow user = { user } >
340- < PostMediaLocked />
341- </ MemberNotValidShow >
342- </ >
343- ) : (
344- < PostMediaLocked />
345- ) }
315+ < >
316+ < MemberValidShow
317+ user = { user }
318+ sectionLesson = { sectionLesson }
319+ notValidComponent = { < PostMediaLocked /> }
320+ >
321+ < PostMedia
322+ post = { post }
323+ playing = { playing }
324+ setPlaying = { setPlaying }
325+ videoProgress = { videoProgress }
326+ setVideoProgress = { setVideoProgress }
327+ />
328+ </ MemberValidShow >
329+ </ >
346330 </ section >
347331 ) }
348332
@@ -452,26 +436,30 @@ export default function PostLayout({
452436 </ section >
453437
454438 { /* BLOG POST */ }
455- { ! isLockedLesson ( ) ? (
456- < div className = "flex flex-wrap gap-4 px-4 pb-4 mt-2 xl:flex-nowrap lg:px-10 lg:pb-10" >
457- < section className = "flex flex-col w-full gap-4" >
458- < > { showPost ( ) } </ >
459- </ section >
460- </ div >
461- ) : user && user ?. uid ? (
462- < >
463- < MemberValidShow user = { user } >
439+ < >
440+ < MemberValidShow
441+ user = { user }
442+ sectionLesson = { sectionLesson }
443+ notValidComponent = { < PostMediaLocked /> }
444+ >
445+ < >
464446 < div className = "flex flex-wrap gap-4 px-4 pb-4 mt-2 xl:flex-nowrap lg:px-10 lg:pb-10" >
465447 < section className = "flex flex-col w-full gap-4" >
466448 < > { showPost ( ) } </ >
467449 </ section >
468450 </ div >
469- </ MemberValidShow >
470- < div className = "inline-block w-full xl:hidden" > { recents ( ) } </ div >
471- </ >
472- ) : (
473- < div className = "inline-block w-full" > { recents ( ) } </ div >
474- ) }
451+ < >
452+ { user && user ?. uid ? (
453+ < div className = "inline-block w-full xl:hidden" >
454+ { recents ( ) }
455+ </ div >
456+ ) : (
457+ < div className = "inline-block w-full" > { recents ( ) } </ div >
458+ ) }
459+ </ >
460+ </ >
461+ </ MemberValidShow >
462+ </ >
475463 </ div >
476464 < style global jsx > { `
477465 article > * {
0 commit comments