lanna_lalala;- commited on
Commit ·
fc82d73
1
Parent(s): d03d1fd
lesson css try
Browse files- phase/Student_view/lesson.py +262 -67
phase/Student_view/lesson.py
CHANGED
|
@@ -370,10 +370,6 @@ def _render_catalog():
|
|
| 370 |
<div class="learn-title">You'll Learn</div>
|
| 371 |
""", unsafe_allow_html=True)
|
| 372 |
|
| 373 |
-
for topic in mod['topics'][:2]:
|
| 374 |
-
st.markdown(f'<div class="learn-item">• {topic}</div>', unsafe_allow_html=True)
|
| 375 |
-
|
| 376 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 377 |
|
| 378 |
with st.expander("📋 All Topics"):
|
| 379 |
for topic in mod['topics']:
|
|
@@ -395,7 +391,7 @@ def _render_catalog():
|
|
| 395 |
""", unsafe_allow_html=True)
|
| 396 |
|
| 397 |
# Actual hidden Streamlit button to handle clicks
|
| 398 |
-
if st.button("", key=btn_key, help=f"
|
| 399 |
st.session_state.topics_cache.pop((level, mod["id"]), None)
|
| 400 |
try:
|
| 401 |
st.cache_data.clear()
|
|
@@ -442,9 +438,134 @@ def _render_lesson():
|
|
| 442 |
|
| 443 |
mod = next(m for m in MODULES_META[level] if m["id"] == module_id)
|
| 444 |
|
| 445 |
-
st.markdown(
|
| 446 |
-
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
topics = _get_topics(level, module_id)
|
| 450 |
|
|
@@ -453,76 +574,150 @@ def _render_lesson():
|
|
| 453 |
topics = [(title, _fallback_text(title, module_id, i + 1)) for i, (title, _) in enumerate(plan)]
|
| 454 |
st.session_state.topics_cache[(level, module_id)] = topics
|
| 455 |
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
else:
|
| 469 |
-
st.
|
| 470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
|
| 472 |
-
|
| 473 |
-
source_note = "Default" if FALLBACK_TAG in t_text else "Backend"
|
| 474 |
-
st.caption(f"Source: {source_note}")
|
| 475 |
-
if t_text:
|
| 476 |
-
cleaned = t_text.replace(FALLBACK_TAG, "")
|
| 477 |
-
st.markdown(cleaned, unsafe_allow_html=True)
|
| 478 |
-
|
| 479 |
-
takeaways = _extract_takeaways(cleaned)
|
| 480 |
-
if takeaways:
|
| 481 |
-
st.markdown("#### Key Takeaways")
|
| 482 |
-
for it in takeaways:
|
| 483 |
-
st.write("✅ ", it)
|
| 484 |
-
else:
|
| 485 |
-
st.info("Content coming soon.")
|
| 486 |
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
st.
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
st.
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
if not st.session_state.get("_auto_quiz_started", False):
|
| 501 |
-
st.session_state["_auto_quiz_started"] = True
|
| 502 |
-
with st.spinner("Generating quiz…"):
|
| 503 |
-
ok = start_quiz(level, module_id, mod["title"])
|
| 504 |
-
if ok:
|
| 505 |
-
st.rerun()
|
| 506 |
-
else:
|
| 507 |
-
st.error("Quiz could not be generated. Please try again.")
|
| 508 |
-
else:
|
| 509 |
-
if st.button("Take Lesson Quiz →"):
|
| 510 |
with st.spinner("Generating quiz…"):
|
| 511 |
ok = start_quiz(level, module_id, mod["title"])
|
| 512 |
if ok:
|
| 513 |
st.rerun()
|
| 514 |
else:
|
| 515 |
st.error("Quiz could not be generated. Please try again.")
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
for i, (tt, _) in enumerate(topics):
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
|
| 527 |
|
| 528 |
def _render_results():
|
|
|
|
| 370 |
<div class="learn-title">You'll Learn</div>
|
| 371 |
""", unsafe_allow_html=True)
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
with st.expander("📋 All Topics"):
|
| 375 |
for topic in mod['topics']:
|
|
|
|
| 391 |
""", unsafe_allow_html=True)
|
| 392 |
|
| 393 |
# Actual hidden Streamlit button to handle clicks
|
| 394 |
+
if st.button("Start Learning", key=btn_key, help=f"start_{level}_{mod['id']}"):
|
| 395 |
st.session_state.topics_cache.pop((level, mod["id"]), None)
|
| 396 |
try:
|
| 397 |
st.cache_data.clear()
|
|
|
|
| 438 |
|
| 439 |
mod = next(m for m in MODULES_META[level] if m["id"] == module_id)
|
| 440 |
|
| 441 |
+
st.markdown("""
|
| 442 |
+
<style>
|
| 443 |
+
.lesson-header {
|
| 444 |
+
font-size: 2rem;
|
| 445 |
+
font-weight: 600;
|
| 446 |
+
color: #1f2937;
|
| 447 |
+
margin-bottom: 2rem;
|
| 448 |
+
}
|
| 449 |
+
.lesson-card {
|
| 450 |
+
background: white;
|
| 451 |
+
border: 1px solid #e5e7eb;
|
| 452 |
+
border-radius: 12px;
|
| 453 |
+
padding: 2rem;
|
| 454 |
+
margin-bottom: 1.5rem;
|
| 455 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
| 456 |
+
}
|
| 457 |
+
.unit-header {
|
| 458 |
+
display: flex;
|
| 459 |
+
justify-content: space-between;
|
| 460 |
+
align-items: center;
|
| 461 |
+
margin-bottom: 1.5rem;
|
| 462 |
+
padding-bottom: 1rem;
|
| 463 |
+
border-bottom: 1px solid #f3f4f6;
|
| 464 |
+
}
|
| 465 |
+
.unit-info {
|
| 466 |
+
font-size: 0.875rem;
|
| 467 |
+
color: #6b7280;
|
| 468 |
+
font-weight: 500;
|
| 469 |
+
}
|
| 470 |
+
.read-time {
|
| 471 |
+
display: flex;
|
| 472 |
+
align-items: center;
|
| 473 |
+
gap: 0.5rem;
|
| 474 |
+
font-size: 0.875rem;
|
| 475 |
+
color: #6b7280;
|
| 476 |
+
}
|
| 477 |
+
.lesson-content {
|
| 478 |
+
font-size: 1rem;
|
| 479 |
+
line-height: 1.6;
|
| 480 |
+
color: #374151;
|
| 481 |
+
margin-bottom: 2rem;
|
| 482 |
+
}
|
| 483 |
+
.takeaways-section {
|
| 484 |
+
background: #f9fafb;
|
| 485 |
+
border: 1px solid #e5e7eb;
|
| 486 |
+
border-radius: 8px;
|
| 487 |
+
padding: 1.5rem;
|
| 488 |
+
margin-top: 2rem;
|
| 489 |
+
}
|
| 490 |
+
.takeaways-header {
|
| 491 |
+
display: flex;
|
| 492 |
+
align-items: center;
|
| 493 |
+
gap: 0.5rem;
|
| 494 |
+
font-size: 1.125rem;
|
| 495 |
+
font-weight: 600;
|
| 496 |
+
color: #1f2937;
|
| 497 |
+
margin-bottom: 1rem;
|
| 498 |
+
}
|
| 499 |
+
.takeaway-item {
|
| 500 |
+
display: flex;
|
| 501 |
+
align-items: flex-start;
|
| 502 |
+
gap: 0.75rem;
|
| 503 |
+
margin-bottom: 0.75rem;
|
| 504 |
+
font-size: 0.95rem;
|
| 505 |
+
color: #374151;
|
| 506 |
+
}
|
| 507 |
+
.takeaway-check {
|
| 508 |
+
color: #10b981;
|
| 509 |
+
font-size: 1.1rem;
|
| 510 |
+
margin-top: 0.1rem;
|
| 511 |
+
}
|
| 512 |
+
.sidebar-card {
|
| 513 |
+
background: white;
|
| 514 |
+
border: 1px solid #e5e7eb;
|
| 515 |
+
border-radius: 12px;
|
| 516 |
+
padding: 1.5rem;
|
| 517 |
+
margin-bottom: 1rem;
|
| 518 |
+
}
|
| 519 |
+
.progress-section h4 {
|
| 520 |
+
font-size: 1.1rem;
|
| 521 |
+
font-weight: 600;
|
| 522 |
+
color: #1f2937;
|
| 523 |
+
margin-bottom: 1rem;
|
| 524 |
+
}
|
| 525 |
+
.unit-item {
|
| 526 |
+
display: flex;
|
| 527 |
+
align-items: center;
|
| 528 |
+
gap: 0.75rem;
|
| 529 |
+
padding: 0.5rem 0;
|
| 530 |
+
font-size: 0.9rem;
|
| 531 |
+
}
|
| 532 |
+
.unit-active {
|
| 533 |
+
background: #10b981;
|
| 534 |
+
color: white;
|
| 535 |
+
padding: 0.25rem 0.75rem;
|
| 536 |
+
border-radius: 20px;
|
| 537 |
+
font-weight: 500;
|
| 538 |
+
}
|
| 539 |
+
.unit-inactive {
|
| 540 |
+
color: #6b7280;
|
| 541 |
+
}
|
| 542 |
+
.nav-buttons {
|
| 543 |
+
display: flex;
|
| 544 |
+
justify-content: space-between;
|
| 545 |
+
margin-top: 2rem;
|
| 546 |
+
gap: 1rem;
|
| 547 |
+
}
|
| 548 |
+
.btn-secondary {
|
| 549 |
+
background: #f3f4f6;
|
| 550 |
+
color: #374151;
|
| 551 |
+
border: 1px solid #d1d5db;
|
| 552 |
+
padding: 0.75rem 1.5rem;
|
| 553 |
+
border-radius: 8px;
|
| 554 |
+
font-weight: 500;
|
| 555 |
+
text-decoration: none;
|
| 556 |
+
}
|
| 557 |
+
.btn-primary {
|
| 558 |
+
background: #10b981;
|
| 559 |
+
color: white;
|
| 560 |
+
border: none;
|
| 561 |
+
padding: 0.75rem 1.5rem;
|
| 562 |
+
border-radius: 8px;
|
| 563 |
+
font-weight: 500;
|
| 564 |
+
}
|
| 565 |
+
</style>
|
| 566 |
+
""", unsafe_allow_html=True)
|
| 567 |
+
|
| 568 |
+
st.markdown(f'<div class="lesson-header">{mod["title"]}</div>', unsafe_allow_html=True)
|
| 569 |
|
| 570 |
topics = _get_topics(level, module_id)
|
| 571 |
|
|
|
|
| 574 |
topics = [(title, _fallback_text(title, module_id, i + 1)) for i, (title, _) in enumerate(plan)]
|
| 575 |
st.session_state.topics_cache[(level, module_id)] = topics
|
| 576 |
|
| 577 |
+
col_main, col_sidebar = st.columns([2, 1])
|
| 578 |
+
|
| 579 |
+
with col_main:
|
| 580 |
+
t_title, t_text = topics[st.session_state.topic_idx]
|
| 581 |
+
|
| 582 |
+
# Special Quiz placeholder
|
| 583 |
+
if t_title.strip().lower() == "quiz":
|
| 584 |
+
with st.spinner("Generating quiz…"):
|
| 585 |
+
ok = start_quiz(level, module_id, mod["title"])
|
| 586 |
+
if ok:
|
| 587 |
+
st.rerun()
|
| 588 |
+
else:
|
| 589 |
+
st.error("Quiz could not be generated. Please try again or skip.")
|
| 590 |
+
return
|
| 591 |
+
|
| 592 |
+
st.markdown(f"""
|
| 593 |
+
<div class="lesson-card">
|
| 594 |
+
<div class="unit-header">
|
| 595 |
+
<span class="unit-info">Unit {st.session_state.topic_idx + 1} of {len(topics)}</span>
|
| 596 |
+
<div class="read-time">
|
| 597 |
+
<span>🕐</span>
|
| 598 |
+
<span>5-8 min read</span>
|
| 599 |
+
</div>
|
| 600 |
+
</div>
|
| 601 |
+
<div class="lesson-content">
|
| 602 |
+
""", unsafe_allow_html=True)
|
| 603 |
+
|
| 604 |
+
if t_text:
|
| 605 |
+
cleaned = t_text.replace(FALLBACK_TAG, "")
|
| 606 |
+
st.markdown(cleaned, unsafe_allow_html=True)
|
| 607 |
else:
|
| 608 |
+
st.info("Content coming soon.")
|
| 609 |
+
|
| 610 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 611 |
+
|
| 612 |
+
if t_text:
|
| 613 |
+
takeaways = _extract_takeaways(cleaned)
|
| 614 |
+
if takeaways:
|
| 615 |
+
st.markdown("""
|
| 616 |
+
<div class="takeaways-section">
|
| 617 |
+
<div class="takeaways-header">
|
| 618 |
+
<span style="color: #10b981;">●</span>
|
| 619 |
+
<span>Key Takeaways</span>
|
| 620 |
+
</div>
|
| 621 |
+
""", unsafe_allow_html=True)
|
| 622 |
+
|
| 623 |
+
for takeaway in takeaways:
|
| 624 |
+
st.markdown(f"""
|
| 625 |
+
<div class="takeaway-item">
|
| 626 |
+
<span class="takeaway-check">✓</span>
|
| 627 |
+
<span>{takeaway}</span>
|
| 628 |
+
</div>
|
| 629 |
+
""", unsafe_allow_html=True)
|
| 630 |
+
|
| 631 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 632 |
|
| 633 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
|
| 635 |
+
st.markdown('<div class="nav-buttons">', unsafe_allow_html=True)
|
| 636 |
+
|
| 637 |
+
col1, col2, col3 = st.columns([1, 1, 1])
|
| 638 |
+
with col1:
|
| 639 |
+
if st.button("← Previous", disabled=st.session_state.topic_idx == 0, key="prev_btn"):
|
| 640 |
+
st.session_state.topic_idx -= 1
|
| 641 |
+
st.rerun()
|
| 642 |
+
|
| 643 |
+
with col3:
|
| 644 |
+
is_last = st.session_state.topic_idx >= len(topics) - 1
|
| 645 |
+
if is_last:
|
| 646 |
+
if not st.session_state.get("_auto_quiz_started", False):
|
| 647 |
+
st.session_state["_auto_quiz_started"] = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
with st.spinner("Generating quiz…"):
|
| 649 |
ok = start_quiz(level, module_id, mod["title"])
|
| 650 |
if ok:
|
| 651 |
st.rerun()
|
| 652 |
else:
|
| 653 |
st.error("Quiz could not be generated. Please try again.")
|
| 654 |
+
else:
|
| 655 |
+
if st.button("Take Lesson Quiz →", key="quiz_btn"):
|
| 656 |
+
with st.spinner("Generating quiz…"):
|
| 657 |
+
ok = start_quiz(level, module_id, mod["title"])
|
| 658 |
+
if ok:
|
| 659 |
+
st.rerun()
|
| 660 |
+
else:
|
| 661 |
+
st.error("Quiz could not be generated. Please try again.")
|
| 662 |
+
else:
|
| 663 |
+
if st.button("Next Unit →", key="next_btn"):
|
| 664 |
+
st.session_state.topic_idx += 1
|
| 665 |
+
st.rerun()
|
| 666 |
+
|
| 667 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 668 |
+
|
| 669 |
+
with col_sidebar:
|
| 670 |
+
# Module Progress Card
|
| 671 |
+
st.markdown("""
|
| 672 |
+
<div class="sidebar-card">
|
| 673 |
+
<h4>Module Progress</h4>
|
| 674 |
+
""", unsafe_allow_html=True)
|
| 675 |
+
|
| 676 |
+
progress = (st.session_state.topic_idx + 1) / max(1, len(topics))
|
| 677 |
+
st.progress(progress)
|
| 678 |
+
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)
|
| 679 |
+
|
| 680 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 681 |
+
|
| 682 |
+
# Module Units Card
|
| 683 |
+
st.markdown("""
|
| 684 |
+
<div class="sidebar-card">
|
| 685 |
+
<h4>Module Units</h4>
|
| 686 |
+
""", unsafe_allow_html=True)
|
| 687 |
+
|
| 688 |
for i, (tt, _) in enumerate(topics):
|
| 689 |
+
is_current = i == st.session_state.topic_idx
|
| 690 |
+
is_completed = i < st.session_state.topic_idx
|
| 691 |
+
|
| 692 |
+
if is_current:
|
| 693 |
+
st.markdown(f"""
|
| 694 |
+
<div class="unit-item">
|
| 695 |
+
<span style="background: #10b981; color: white; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem;">●</span>
|
| 696 |
+
<span class="unit-active">{tt}</span>
|
| 697 |
+
</div>
|
| 698 |
+
""", unsafe_allow_html=True)
|
| 699 |
+
elif is_completed:
|
| 700 |
+
st.markdown(f"""
|
| 701 |
+
<div class="unit-item">
|
| 702 |
+
<span style="color: #10b981; font-size: 1.1rem;">✓</span>
|
| 703 |
+
<span style="color: #374151;">{tt}</span>
|
| 704 |
+
</div>
|
| 705 |
+
""", unsafe_allow_html=True)
|
| 706 |
+
else:
|
| 707 |
+
st.markdown(f"""
|
| 708 |
+
<div class="unit-item">
|
| 709 |
+
<span style="background: #e5e7eb; color: #9ca3af; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem;">○</span>
|
| 710 |
+
<span class="unit-inactive">{tt}</span>
|
| 711 |
+
</div>
|
| 712 |
+
""", unsafe_allow_html=True)
|
| 713 |
+
|
| 714 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 715 |
|
| 716 |
+
# Back to modules button
|
| 717 |
+
if st.button("← Back to Modules", key="back_modules"):
|
| 718 |
+
st.session_state.mode = "catalog"
|
| 719 |
+
st.session_state.module_id = None
|
| 720 |
+
st.rerun()
|
| 721 |
|
| 722 |
|
| 723 |
def _render_results():
|