lanna_lalala;- commited on
Commit
2f3fcdf
Β·
1 Parent(s): 90985ea

lesson css try

Browse files
Files changed (1) hide show
  1. phase/Student_view/lesson.py +31 -50
phase/Student_view/lesson.py CHANGED
@@ -37,6 +37,8 @@ _SS_DEFAULTS = {
37
 
38
  }
39
 
 
 
40
  def _ensure_state():
41
  for k, v in _SS_DEFAULTS.items():
42
  if k not in st.session_state:
@@ -416,10 +418,10 @@ def _get_topics(level: str, module_id: int) -> List[Tuple[str, str]]:
416
 
417
 
418
  def _render_lesson():
419
- ensure_quiz_state() # make sure quiz keys exist
420
-
421
- level = st.session_state.level
422
- module_id = st.session_state.module_id
423
  if module_id is None:
424
  st.session_state.mode = "catalog"
425
  st.rerun()
@@ -441,6 +443,7 @@ def _render_lesson():
441
  padding: 2rem;
442
  margin-bottom: 1.5rem;
443
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
 
444
  }
445
  .unit-header {
446
  display: flex;
@@ -556,31 +559,21 @@ def _render_lesson():
556
  st.markdown(f'<div class="lesson-header">{mod["title"]}</div>', unsafe_allow_html=True)
557
 
558
  topics = _get_topics(level, module_id)
 
559
 
560
  if not topics:
561
- plan = _topic_plan(level, module_id)
562
- topics = [(title, _fallback_text(title, module_id, i + 1)) for i, (title, _) in enumerate(plan)]
563
- st.session_state.topics_cache[(level, module_id)] = topics
564
 
565
  col_main, col_sidebar = st.columns([2, 1])
566
 
567
  with col_main:
568
- t_title, t_text = topics[st.session_state.topic_idx]
569
-
570
- # Special Quiz placeholder
571
- if t_title.strip().lower() == "quiz":
572
- with st.spinner("Generating quiz…"):
573
- ok = start_quiz(level, module_id, mod["title"])
574
- if ok:
575
- st.rerun()
576
- else:
577
- st.error("Quiz could not be generated. Please try again or skip.")
578
- return
579
 
580
  st.markdown(f"""
581
  <div class="lesson-card">
582
  <div class="unit-header">
583
- <span class="unit-info">Unit {st.session_state.topic_idx + 1} of {len(topics)}</span>
584
  <div class="read-time">
585
  <span>πŸ•</span>
586
  <span>5-8 min read</span>
@@ -590,18 +583,15 @@ def _render_lesson():
590
  """, unsafe_allow_html=True)
591
 
592
  if t_text:
593
- cleaned = t_text.replace(FALLBACK_TAG, "")
594
- st.markdown(cleaned, unsafe_allow_html=True)
595
  else:
596
  st.info("Content coming soon.")
597
 
598
- st.markdown("</div>", unsafe_allow_html=True)
599
-
600
  if t_text:
601
- takeaways = _extract_takeaways(cleaned)
602
  if takeaways:
603
  st.markdown("""
604
- <div class="takeaways-section">
605
  <div class="takeaways-header">
606
  <span style="color: #10b981;">●</span>
607
  <span>Key Takeaways</span>
@@ -618,35 +608,25 @@ def _render_lesson():
618
 
619
  st.markdown("</div>", unsafe_allow_html=True)
620
 
621
- st.markdown("</div>", unsafe_allow_html=True)
622
 
623
  st.markdown('<div class="nav-buttons">', unsafe_allow_html=True)
624
 
625
  col1, col2, col3 = st.columns([1, 1, 1])
626
  with col1:
627
- if st.button("← Previous", disabled=st.session_state.topic_idx == 0, key="prev_btn"):
628
  st.session_state.topic_idx -= 1
629
  st.rerun()
630
 
631
  with col3:
632
- is_last = st.session_state.topic_idx >= len(topics) - 1
633
  if is_last:
634
- if not st.session_state.get("_auto_quiz_started", False):
635
- st.session_state["_auto_quiz_started"] = True
636
- with st.spinner("Generating quiz…"):
637
- ok = start_quiz(level, module_id, mod["title"])
638
- if ok:
639
- st.rerun()
640
- else:
641
- st.error("Quiz could not be generated. Please try again.")
642
- else:
643
- if st.button("Take Lesson Quiz β†’", key="quiz_btn"):
644
- with st.spinner("Generating quiz…"):
645
- ok = start_quiz(level, module_id, mod["title"])
646
- if ok:
647
- st.rerun()
648
- else:
649
- st.error("Quiz could not be generated. Please try again.")
650
  else:
651
  if st.button("Next Unit β†’", key="next_btn"):
652
  st.session_state.topic_idx += 1
@@ -657,25 +637,25 @@ def _render_lesson():
657
  with col_sidebar:
658
  # Module Progress Card
659
  st.markdown("""
660
- <div class="sidebar-card">
661
  <h4>Module Progress</h4>
662
  """, unsafe_allow_html=True)
663
 
664
- progress = (st.session_state.topic_idx + 1) / max(1, len(topics))
665
  st.progress(progress)
666
- st.markdown(f"<p style='color: #6b7280; font-size: 0.875rem; margin-top: 0.5rem;'>Unit {st.session_state.topic_idx + 1} of {len(topics)}</p>", unsafe_allow_html=True)
667
 
668
  st.markdown("</div>", unsafe_allow_html=True)
669
 
670
  # Module Units Card
671
  st.markdown("""
672
- <div class="sidebar-card">
673
  <h4>Module Units</h4>
674
  """, unsafe_allow_html=True)
675
 
676
  for i, (tt, _) in enumerate(topics):
677
- is_current = i == st.session_state.topic_idx
678
- is_completed = i < st.session_state.topic_idx
679
 
680
  if is_current:
681
  st.markdown(f"""
@@ -705,6 +685,7 @@ def _render_lesson():
705
  if st.button("← Back to Modules", key="back_modules"):
706
  st.session_state.mode = "catalog"
707
  st.session_state.module_id = None
 
708
  st.rerun()
709
 
710
 
 
37
 
38
  }
39
 
40
+
41
+
42
  def _ensure_state():
43
  for k, v in _SS_DEFAULTS.items():
44
  if k not in st.session_state:
 
418
 
419
 
420
  def _render_lesson():
421
+ """Render the lesson interface"""
422
+ level = st.session_state.get("level", "beginner")
423
+ module_id = st.session_state.get("module_id")
424
+
425
  if module_id is None:
426
  st.session_state.mode = "catalog"
427
  st.rerun()
 
443
  padding: 2rem;
444
  margin-bottom: 1.5rem;
445
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
446
+ min-height: 400px;
447
  }
448
  .unit-header {
449
  display: flex;
 
559
  st.markdown(f'<div class="lesson-header">{mod["title"]}</div>', unsafe_allow_html=True)
560
 
561
  topics = _get_topics(level, module_id)
562
+ topic_idx = st.session_state.get("topic_idx", 0)
563
 
564
  if not topics:
565
+ st.error("No lesson content available for this module.")
566
+ return
 
567
 
568
  col_main, col_sidebar = st.columns([2, 1])
569
 
570
  with col_main:
571
+ t_title, t_text = topics[topic_idx]
 
 
 
 
 
 
 
 
 
 
572
 
573
  st.markdown(f"""
574
  <div class="lesson-card">
575
  <div class="unit-header">
576
+ <span class="unit-info">Unit {topic_idx + 1} of {len(topics)}</span>
577
  <div class="read-time">
578
  <span>πŸ•</span>
579
  <span>5-8 min read</span>
 
583
  """, unsafe_allow_html=True)
584
 
585
  if t_text:
586
+ st.markdown(t_text.strip(), unsafe_allow_html=True)
 
587
  else:
588
  st.info("Content coming soon.")
589
 
 
 
590
  if t_text:
591
+ takeaways = _extract_takeaways(t_text)
592
  if takeaways:
593
  st.markdown("""
594
+ <div class="takeaways-section" style="min-height: 150px;">
595
  <div class="takeaways-header">
596
  <span style="color: #10b981;">●</span>
597
  <span>Key Takeaways</span>
 
608
 
609
  st.markdown("</div>", unsafe_allow_html=True)
610
 
611
+ st.markdown("</div></div>", unsafe_allow_html=True)
612
 
613
  st.markdown('<div class="nav-buttons">', unsafe_allow_html=True)
614
 
615
  col1, col2, col3 = st.columns([1, 1, 1])
616
  with col1:
617
+ if st.button("← Previous", disabled=topic_idx == 0, key="prev_btn"):
618
  st.session_state.topic_idx -= 1
619
  st.rerun()
620
 
621
  with col3:
622
+ is_last = topic_idx >= len(topics) - 1
623
  if is_last:
624
+ if st.button("Complete Module β†’", key="complete_btn"):
625
+ st.session_state.mode = "catalog"
626
+ st.session_state.module_id = None
627
+ st.session_state.topic_idx = 0
628
+ st.success("Module completed! πŸŽ‰")
629
+ st.rerun()
 
 
 
 
 
 
 
 
 
 
630
  else:
631
  if st.button("Next Unit β†’", key="next_btn"):
632
  st.session_state.topic_idx += 1
 
637
  with col_sidebar:
638
  # Module Progress Card
639
  st.markdown("""
640
+ <div class="sidebar-card" style="min-height: 120px;">
641
  <h4>Module Progress</h4>
642
  """, unsafe_allow_html=True)
643
 
644
+ progress = (topic_idx + 1) / max(1, len(topics))
645
  st.progress(progress)
646
+ st.markdown(f"<p style='color: #6b7280; font-size: 0.875rem; margin-top: 0.5rem;'>Unit {topic_idx + 1} of {len(topics)}</p>", unsafe_allow_html=True)
647
 
648
  st.markdown("</div>", unsafe_allow_html=True)
649
 
650
  # Module Units Card
651
  st.markdown("""
652
+ <div class="sidebar-card" style="min-height: 300px;">
653
  <h4>Module Units</h4>
654
  """, unsafe_allow_html=True)
655
 
656
  for i, (tt, _) in enumerate(topics):
657
+ is_current = i == topic_idx
658
+ is_completed = i < topic_idx
659
 
660
  if is_current:
661
  st.markdown(f"""
 
685
  if st.button("← Back to Modules", key="back_modules"):
686
  st.session_state.mode = "catalog"
687
  st.session_state.module_id = None
688
+ st.session_state.topic_idx = 0
689
  st.rerun()
690
 
691