diff --git a/app.py b/app.py index 22bad2e..cd5f19b 100644 --- a/app.py +++ b/app.py @@ -13,6 +13,7 @@ from services.account_ui import render_account_menu, render_account_page from services.accessibility import render_accessibility_controls from services.page_registry import existing_focus_pages +from services.study_navigation import render_study_context from services.ui_style import BRAND_LOGO, BRAND_PLANE, apply_app_styles from services.tutor_assistant_ui import clear_tutor_browser_state, render_tutor_assistant @@ -145,8 +146,7 @@ render_account_menu(account_page) if selected_course := st.session_state.get("current_course"): - with st.container(key="flight_course_context"): - st.caption(f"{selected_course.course_name} / {navigation.title}") + render_study_context(selected_course, navigation.url_path, navigation.title) render_tutor_assistant() navigation.run() diff --git a/assets/paper_zz_coherence.css b/assets/paper_zz_coherence.css new file mode 100644 index 0000000..d4640a4 --- /dev/null +++ b/assets/paper_zz_coherence.css @@ -0,0 +1,47 @@ +/* Quiet shared affordances across the existing paper pages. */ +[data-testid="stApp"] { + --exam-muted: var(--ep-text-secondary); + --exam-blue: var(--ep-action); + --exam-blue-dark: var(--ep-action-hover); +} +[data-testid="stMain"] :is(button, input, textarea, [role="tab"]):focus-visible, +[data-testid="stSidebarNav"] a:focus-visible { + outline: 2px solid var(--ep-focus); + outline-offset: 3px; +} +.st-key-flight_course_context { + padding: var(--ep-space-2) 0 var(--ep-space-3); + border-bottom: 1px solid var(--ep-border); + margin-bottom: var(--ep-space-4); +} +.st-key-flight_course_context [data-testid="stCaptionContainer"] { margin: 0; } +.st-key-study_return_action button { min-height: var(--ep-control-height); } +.st-key-practice_paused_notice { + border-left: 3px solid var(--ep-rust-700); + background: var(--ep-surface-subtle); + border-radius: var(--ep-radius-control); + padding: var(--ep-space-3) var(--ep-space-4); + margin-block: var(--ep-space-2) var(--ep-space-4); +} +.st-key-practice_paused_notice p { margin: 0; color: var(--ep-text-primary); } +.flight-clock.is-paused { border-color: var(--ep-rust-700); background: var(--ep-surface-subtle); } +.flight-waypoint.is-current { display: grid; place-items: center; background: transparent; } +.flight-waypoint.is-current svg { display: block; width: 26px; height: 22px; } +[data-testid="stMain"] .st-key-study_return_action button { white-space: normal; } +@media (max-width: 640px) { + .st-key-flight_course_context [data-testid="stHorizontalBlock"] { flex-wrap: wrap; gap: var(--ep-space-2); } + .st-key-study_return_action { margin-left: 0; max-width: 100%; } +} +@media (prefers-reduced-motion: reduce) { + .flight-waypoint, .tutor-bubble { animation: none !important; transition: none !important; } +} +/* On phones the open sidebar owns the screen. Do not cover its collapse + control or accessibility menu with fixed account/Pilot controls. */ +@media (max-width: 760px) { + [data-testid="stApp"]:has(section[data-testid="stSidebar"][aria-expanded="true"]) :is(.st-key-account_menu, .st-key-floating_tutor) { + visibility: hidden; + pointer-events: none; + } + [data-testid="stSidebarCollapseButton"] button, + button[data-testid="stExpandSidebarButton"] { min-width: 44px; min-height: 44px; } +} diff --git a/assets/tutor_assistant.css b/assets/tutor_assistant.css index 924b24d..c04ceca 100644 --- a/assets/tutor_assistant.css +++ b/assets/tutor_assistant.css @@ -1,10 +1,10 @@ :host { font-family: "Source Sans 3", "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; } -.exam-tutor { --tutor-blue: #2166db; --tutor-ink: #102044; --tutor-muted: #526581; --tutor-border: #dce6f4; color: var(--tutor-ink); font-size: var(--exam-font-body); line-height: 1.5; } +.exam-tutor { --tutor-blue: var(--ep-action); --tutor-ink: var(--ep-text-primary); --tutor-muted: var(--ep-text-secondary); --tutor-border: var(--ep-border); color: var(--tutor-ink); font-size: var(--exam-font-body); line-height: 1.5; } .exam-tutor *, .exam-tutor *::before, .exam-tutor *::after { box-sizing: border-box; } .exam-tutor [hidden] { display: none !important; } .exam-tutor button, .exam-tutor textarea { font: inherit; } .exam-tutor button { cursor: pointer; -webkit-tap-highlight-color: transparent; } -.exam-tutor button:focus-visible, .exam-tutor textarea:focus-visible, .tutor-messages:focus-visible { outline: 3px solid #83b4ff; outline-offset: 3px; } +.exam-tutor button:focus-visible, .exam-tutor textarea:focus-visible, .tutor-messages:focus-visible { outline: 3px solid var(--ep-focus); outline-offset: 3px; } .exam-tutor button:disabled { cursor: default; opacity: .48; } .tutor-bubble { position: fixed; z-index: 1000001; width: 64px; height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 0; border-radius: 16px; padding: 0; background: transparent; color: var(--tutor-blue); box-shadow: none; touch-action: none; user-select: none; } .tutor-bubble:hover { background: transparent; box-shadow: none; } @@ -12,9 +12,9 @@ .tutor-bubble.is-panel-overlap { visibility: hidden; pointer-events: none; } .tutor-pilot { width: 48px; height: 48px; flex-shrink: 0; display: block; object-fit: contain; transition: transform 150ms ease; pointer-events: none; user-select: none; -webkit-user-drag: none; } .tutor-bubble:hover .tutor-pilot { transform: translateY(-1px); } -.tutor-bubble-label { display: block; width: 64px; height: 16px; border: 0; padding: 0; background: transparent; color: #385779; text-align: center; font-size: var(--exam-font-meta); font-weight: 650; line-height: 16px; pointer-events: none; } -.tutor-panel { position: fixed; z-index: 1000000; width: min(388px, calc(100vw - 24px)); height: min(560px, calc(100dvh - 24px)); display: flex; flex-direction: column; overflow: hidden; border: 1px solid #cfdef3; border-radius: 18px; background: #fff; box-shadow: 0 12px 50px #10204426, 0 2px 6px #10204412; animation: tutor-appear 140ms ease-out; } -.tutor-header { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 8px; min-height: 75px; padding: 12px 12px 12px 17px; background: linear-gradient(115deg, #edf4ff, #f8faff); border-bottom: 1px solid var(--tutor-border); cursor: grab; touch-action: none; user-select: none; } +.tutor-bubble-label { display: block; width: 64px; height: 16px; border: 0; padding: 0; background: transparent; color: var(--ep-text-secondary); text-align: center; font-size: var(--exam-font-meta); font-weight: 650; line-height: 16px; pointer-events: none; } +.tutor-panel { position: fixed; z-index: 1000000; width: min(388px, calc(100vw - 24px)); height: min(560px, calc(100dvh - 24px)); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--ep-border); border-radius: 18px; background: var(--ep-surface-panel); box-shadow: var(--ep-shadow-panel); animation: tutor-appear 140ms ease-out; } +.tutor-header { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 8px; min-height: 75px; padding: 12px 12px 12px 17px; background: var(--ep-surface-subtle); border-bottom: 1px solid var(--tutor-border); cursor: grab; touch-action: none; user-select: none; } .tutor-header.is-dragging { cursor: grabbing; } .tutor-title-group { display: flex; align-items: center; gap: 9px; min-width: 0; pointer-events: none; } .tutor-small-pilot { display: block; flex: 0 0 auto; width: 38px; height: 38px; object-fit: contain; background: transparent; pointer-events: none; user-select: none; -webkit-user-drag: none; } @@ -22,37 +22,37 @@ .tutor-title-group h2 { margin: 0; color: var(--tutor-ink); font-size: var(--exam-font-compact-heading); font-weight: 700; line-height: 1.3; letter-spacing: -.2px; } .tutor-title-group p { margin: 2px 0 0; color: var(--tutor-muted); font-size: var(--exam-font-meta); line-height: 1.4; } .tutor-header-actions { display: flex; gap: 2px; } -.tutor-icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 12px; border: 0; border-radius: 9px; background: transparent; color: #476184; } -.tutor-icon-button:hover:not(:disabled) { background: #dceaff; color: #174faf; } +.tutor-icon-button { display: grid; place-items: center; width: 44px; height: 44px; padding: 12px; border: 0; border-radius: 9px; background: transparent; color: var(--ep-text-secondary); } +.tutor-icon-button:hover:not(:disabled) { background: var(--ep-surface-subtle); color: var(--ep-action-hover); } .tutor-icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; } -.tutor-course { flex: 0 0 auto; padding: 8px 17px; border-bottom: 1px solid #edf1f8; background: #fbfcff; color: #385779; font-size: var(--exam-font-meta); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.tutor-course { flex: 0 0 auto; padding: 8px 17px; border-bottom: 1px solid var(--ep-border); background: var(--ep-surface-subtle); color: var(--ep-text-secondary); font-size: var(--exam-font-meta); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .tutor-messages { flex: 1 1 auto; min-height: 48px; overflow-y: auto; overscroll-behavior: contain; padding: 16px; scrollbar-width: thin; } .tutor-empty { display: flex; min-height: 150px; height: 100%; flex-direction: column; justify-content: center; padding: 15px 9px; text-align: center; color: var(--tutor-muted); } -.tutor-empty strong { color: #24466f; font-size: var(--exam-font-body); font-weight: 650; margin-bottom: 6px; } +.tutor-empty strong { color: var(--ep-text-primary); font-size: var(--exam-font-body); font-weight: 650; margin-bottom: 6px; } .tutor-empty p { margin: 0; font-size: var(--exam-font-body); line-height: 1.6; } .tutor-message { margin: 0 0 14px; } .tutor-message:last-child { margin-bottom: 0; } .tutor-message-label { display: block; margin: 0 0 4px 2px; color: var(--tutor-muted); font-size: var(--exam-font-meta); font-weight: 650; } -.tutor-message-body { padding: 10px 12px; border-radius: 12px; background: #f2f6fc; color: var(--tutor-ink); font-size: var(--exam-font-body); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; user-select: text; } +.tutor-message-body { padding: 10px 12px; border-radius: 12px; background: var(--ep-surface-subtle); color: var(--tutor-ink); font-size: var(--exam-font-body); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; user-select: text; } .tutor-message-user { margin-left: 22px; } .tutor-message-user .tutor-message-label { text-align: right; margin-right: 3px; } -.tutor-message-user .tutor-message-body { background: #2166db; color: #fff; border-bottom-right-radius: 4px; } +.tutor-message-user .tutor-message-body { background: var(--ep-action); color: var(--ep-surface-panel); border-bottom-right-radius: 4px; } .tutor-message-assistant { margin-right: 10px; } -.tutor-message-error .tutor-message-body { border: 1px solid #f4d4c6; background: #fff5ee; color: #824426; } +.tutor-message-error .tutor-message-body { border: 1px solid var(--ep-error-border); background: var(--ep-error-background); color: var(--ep-error-text); } .tutor-message-pending .tutor-message-body { opacity: .7; } -.tutor-status { flex: 0 0 auto; margin: 0 15px 9px; padding: 8px 10px; border-radius: 8px; color: #476184; background: #f1f6ff; font-size: var(--exam-font-meta); line-height: 1.5; overflow-wrap: anywhere; } -.tutor-status.is-error { color: #824426; background: #fff5ee; } -.tutor-status.is-pending::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 7px; vertical-align: -1px; border: 2px solid #adc8f2; border-top-color: #2166db; border-radius: 50%; animation: tutor-spin 700ms linear infinite; } -.tutor-form { flex: 0 0 auto; margin: 0; padding: 12px 14px 10px; border-top: 1px solid var(--tutor-border); background: #fff; } -.tutor-question { display: block; width: 100%; height: 76px; min-height: 60px; margin: 0; padding: 9px 11px; resize: none; border: 1px solid #cbd9ed; border-radius: 10px; background: #fff; color: var(--tutor-ink); font-size: var(--exam-font-body); line-height: 1.5; } -.tutor-question::placeholder { color: #7a8da8; } -.tutor-question:disabled { background: #f6f8fb; } +.tutor-status { flex: 0 0 auto; margin: 0 15px 9px; padding: 8px 10px; border-radius: 8px; color: var(--ep-text-secondary); background: var(--ep-surface-subtle); font-size: var(--exam-font-meta); line-height: 1.5; overflow-wrap: anywhere; } +.tutor-status.is-error { color: var(--ep-error-text); background: var(--ep-error-background); } +.tutor-status.is-pending::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 7px; vertical-align: -1px; border: 2px solid var(--ep-focus-subtle); border-top-color: var(--ep-action); border-radius: 50%; animation: tutor-spin 700ms linear infinite; } +.tutor-form { flex: 0 0 auto; margin: 0; padding: 12px 14px 10px; border-top: 1px solid var(--tutor-border); background: var(--ep-surface-panel); } +.tutor-question { display: block; width: 100%; height: 76px; min-height: 60px; margin: 0; padding: 9px 11px; resize: none; border: 1px solid var(--ep-border); border-radius: 10px; background: var(--ep-surface-panel); color: var(--tutor-ink); font-size: var(--exam-font-body); line-height: 1.5; } +.tutor-question::placeholder { color: var(--ep-text-secondary); } +.tutor-question:disabled { background: var(--ep-disabled-surface); } .tutor-form-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; } -.tutor-input-help { color: #63758f; font-size: var(--exam-font-meta); line-height: 1.5; } +.tutor-input-help { color: var(--ep-text-secondary); font-size: var(--exam-font-meta); line-height: 1.5; } .tutor-send { display: inline-flex; align-items: center; justify-content: center; gap: 10px; flex: 0 0 auto; min-height: 44px; padding: 7px 14px; border: 1px solid var(--tutor-blue); border-radius: 9px; background: var(--tutor-blue); color: white; font-size: var(--exam-font-body); font-weight: 650; } -.tutor-send:hover:not(:disabled) { background: #184fae; border-color: #184fae; } +.tutor-send:hover:not(:disabled) { background: var(--ep-action-hover); border-color: var(--ep-action-hover); } .tutor-send span { font-size: 18px; line-height: 1; } -.tutor-form-note { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; color: #71819a; font-size: var(--exam-font-meta); line-height: 1.5; } +.tutor-form-note { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; color: var(--ep-text-secondary); font-size: var(--exam-font-meta); line-height: 1.5; } .tutor-counter { flex: 0 0 auto; } .tutor-panel.is-compact .tutor-header { min-height: 66px; padding-top: 8px; padding-bottom: 8px; } .tutor-panel.is-compact .tutor-course { padding-top: 6px; padding-bottom: 6px; } @@ -72,3 +72,15 @@ @keyframes tutor-spin { to { transform: rotate(360deg); } } @media (max-width: 480px) { .tutor-panel { border-radius: 15px; } .tutor-header { padding-left: 13px; } .tutor-messages { padding: 13px; } .tutor-form { padding: 10px 12px 8px; } .tutor-input-help { max-width: 172px; } } @media (prefers-reduced-motion: reduce) { .tutor-panel, .tutor-status.is-pending::before { animation: none; } .tutor-pilot { transition: none; } } + +/* Same stationery identity and control scale as the study pages. */ +.tutor-bubble { border: 1px solid var(--ep-border); background: var(--ep-surface-panel); border-radius: var(--ep-radius-panel); box-shadow: var(--ep-shadow-entry); } +.tutor-bubble:hover { background: var(--ep-surface-subtle); box-shadow: var(--ep-shadow-entry-hover); } +.tutor-pilot { width: 36px; height: 32px; } +.tutor-small-pilot { width: 32px; height: 32px; } +.tutor-panel { border-radius: var(--ep-radius-panel); } +.tutor-question { border-color: var(--ep-control-border); } +.tutor-header { background: var(--ep-surface-subtle); } +.tutor-form, .tutor-course { background: var(--ep-surface-panel); } + +.tutor-title-group h2 { font-family: var(--ep-font-heading); } diff --git a/assets/tutor_assistant.js b/assets/tutor_assistant.js index ccb83b9..2e04fb9 100644 --- a/assets/tutor_assistant.js +++ b/assets/tutor_assistant.js @@ -72,6 +72,22 @@ export default function(component) { left: visual ? visual.offsetLeft : 0, top: visual ? visual.offsetTop : 0 }; }; const clamp = (value, min, max) => Math.min(Math.max(value, min), Math.max(min, max)); + const avoidFocusedControl = () => { + if (state.open) return; + const active = document.activeElement; + if (!active || active === document.body || active === bubble || active.contains(root)) return; + const focusTarget = active.matches('input[type="radio"], input[type="checkbox"]') ? active.closest("label") || active : active; + const target = focusTarget.getBoundingClientRect(); + const entry = bubble.getBoundingClientRect(); + if (!target.width || !target.height || target.bottom <= entry.top || target.top >= entry.bottom + || target.right <= entry.left || target.left >= entry.right) return; + const view = viewport(); + const headerBottom = document.querySelector('[data-testid="stHeader"]')?.getBoundingClientRect().bottom || view.top; + const above = target.top - entry.height - 12; + const below = target.bottom + 12; + const y = above >= Math.max(view.top + 12, headerBottom + 12) ? above : below; + bubble.style.top = `${clamp(y, Math.max(view.top + 12, headerBottom + 12), view.top + view.height - entry.height - 12)}px`; + }; const position = () => { const view = viewport(); const margin = 12; @@ -127,6 +143,7 @@ export default function(component) { bubble.classList.toggle('is-panel-overlap', state.open && overlap); bubble.tabIndex = state.open && overlap ? -1 : 0; bubble.setAttribute('aria-hidden', String(state.open && overlap)); + avoidFocusedControl(); }; const updateInput = () => { const busy = Boolean(state.pending); @@ -191,13 +208,13 @@ export default function(component) { if (!destroyed && !question.disabled) question.focus({ preventScroll: true }); }); }; - const closePanel = () => { + const closePanel = (restoreFocus = true) => { state.open = false; panel.hidden = true; bubble.setAttribute('aria-expanded', 'false'); bubble.setAttribute('aria-label', text('Open Pilot, your AI study assistant', '打开 Pilot AI 学习助手')); position(); - bubble.focus({ preventScroll: true }); + if (restoreFocus) bubble.focus({ preventScroll: true }); }; const submit = (event) => { if (event) event.preventDefault(); @@ -320,6 +337,11 @@ export default function(component) { state.validation = ''; setTriggerValue('clear', { request_id: crypto.randomUUID(), session_id: data.session_id, course_id: courseId }); }); + // A non-modal helper must not conceal keyboard focus in the study page. + on(document, 'focusin', event => { + if (state.open && !event.composedPath().includes(root)) closePanel(false); + avoidFocusedControl(); + }); on(window, 'resize', position); if (window.visualViewport) { on(window.visualViewport, 'resize', position); diff --git a/assets/ui_tokens.css b/assets/ui_tokens.css new file mode 100644 index 0000000..92221f0 --- /dev/null +++ b/assets/ui_tokens.css @@ -0,0 +1,43 @@ +/* Shared primitives -> semantic roles -> component aliases. Also loaded in Pilot's shadow root. */ +:root, :host { + --ep-cream-50: #FEF7EF; + --ep-cream-100: #FAF3E9; + --ep-cream-white: #FFFCF7; + --ep-navy-900: #13224F; + --ep-slate-700: #586475; + --ep-blue-700: #4A6C8A; + --ep-blue-800: #3F607C; + --ep-rust-700: #9A5426; + --ep-line-200: #DED6CA; + --ep-space-1: 4px; + --ep-space-2: 8px; + --ep-space-3: 12px; + --ep-space-4: 16px; + --ep-space-6: 24px; + --ep-space-8: 32px; + --ep-radius-control: 10px; + --ep-radius-panel: 16px; + --ep-font-heading: Georgia, "Times New Roman", serif; + --ep-motion-fast: 140ms; + --ep-surface-page: var(--ep-cream-50); + --ep-surface-panel: var(--ep-cream-white); + --ep-surface-subtle: var(--ep-cream-100); + --ep-text-primary: var(--ep-navy-900); + --ep-text-secondary: var(--ep-slate-700); + --ep-action: var(--ep-blue-700); + --ep-action-hover: var(--ep-blue-800); + --ep-focus: var(--ep-blue-700); + --ep-border: var(--ep-line-200); + --ep-error-text: #824426; + --ep-error-background: #FFF5EE; + --ep-error-border: #F4D4C6; + --ep-control-border: #948A7D; + --ep-focus-subtle: #ADC8F2; + --ep-disabled-surface: #F6F8FB; + --ep-shadow-entry: 0 3px 12px rgb(19 34 79 / 8%); + --ep-shadow-entry-hover: 0 4px 16px rgb(19 34 79 / 12%); + --ep-shadow-panel: 0 12px 36px rgb(19 34 79 / 12%); + --ep-control-height: 44px; + --ep-button-background: var(--ep-action); + --ep-panel-background: var(--ep-surface-panel); +} diff --git a/design-system/exampilot/MASTER.md b/design-system/exampilot/MASTER.md new file mode 100644 index 0000000..f4abb48 --- /dev/null +++ b/design-system/exampilot/MASTER.md @@ -0,0 +1,31 @@ +# ExamPilot — shared study interface + +Stack: Streamlit 1.55, Python, Altair, existing custom browser components. Keep the focused-page structure and current paper stationery identity. Do not introduce a new frontend framework or font/network dependency. + +## Heuristic review + +| Severity | Location | Finding | Change | +| --- | --- | --- | --- | +| 3 | Cross-page learning | An unfinished question lacks a consistent return action outside Practice. | Course context offers return to the same session/question on primary learning pages. | +| 2 | Pause | The small timer/button alone does not explain the paused state or reassure about answers. | Inline status beneath progress; paused clock gets a distinct border. No reset or hidden answers. | +| 3 | Mobile navigation | Fixed avatar can overlap the sidebar collapse control. | Hide competing floating controls while the mobile navigation is open; keep 44px navigation targets. | +| 2 | Pilot | Bright blue robot, gradients and chat surfaces differ from the paper app and plane identity. | Shared stationery palette, same plane asset, consistent 44px controls and focus treatment. | +| 2 | Practice progress | Platform emoji plane differs from sidebar branding. | Use the existing vector brand plane. | + +Review scope: Home → Study Plan → Practice → Progress/Map/Lab/Flashcards, focused return pages, and floating Pilot. Review is one expert pass, not a claim of user-study validation. + +## Tokens + +`assets/ui_tokens.css` is the shared token entry point, loaded by both the app stylesheet and Pilot's isolated shadow root. Primitive cream/navy/slate/blue values feed semantic surface/text/action/border roles and component aliases. Existing page tokens remain supported. Use 4/8px spacing, 44px minimum controls, 10px control and 16px panel radii, restrained motion and visible focus. + +Preserve functional colors in graphs and scoring; color must not be the only signal. White text on the primary action and muted text on paper must meet 4.5:1. Borders of form controls need 3:1. Reduced-motion disables decorative movement. Mobile actions wrap rather than push content horizontally. + +## Source fit and evidence + +UI/UX Pro Max searches: `education learning dashboard` suggested a child-oriented clay style; the single retry `university analytics dashboard` suggested enterprise marketing structure. Neither is accepted as a product-level template. Visual direction therefore uses the existing paper identity plus the skill's general accessibility/interaction defaults. Verified focused UX matches: predictable back navigation, fixed navigation offsets, and focus-not-obscured guidance. No Streamlit-specific database guidance was available; implementation follows this repository's existing components. + +Design Token provides primitive → semantic → component architecture. Heuristic Evaluation provides task walkthroughs and severity prioritization. The changes apply to all users; grades, drafts and personal conversations remain account-scoped. + +## Verification + +Full Python 3.12 suite after integrating main: 1560 passed, 20 skipped. Browser walkthroughs cover desktop, 375px portrait and 812px landscape, including pause/return, retained answers, retained Pilot draft, mobile navigation, panel bounds and focused controls. Reduced-motion rules were inspected in source; OS preference switching was not emulated. No live AI request or production account data was used. diff --git a/pages/2_Practice_Center.py b/pages/2_Practice_Center.py index c114677..e296679 100644 --- a/pages/2_Practice_Center.py +++ b/pages/2_Practice_Center.py @@ -1,5 +1,6 @@ from services.i18n import tr from html import escape +from services.ui_style import BRAND_PLANE import time import streamlit as st @@ -451,7 +452,7 @@ def render_question_screen(course, active, topic_names): stops = min(len(questions), 12) current_stop = index * (stops - 1) // max(1, len(questions) - 1) markers = "".join( - '✈' if step == current_stop + '' + BRAND_PLANE.read_text(encoding='utf-8') + '' if step == current_stop else '' for step in range(stops) ) @@ -465,6 +466,10 @@ def render_question_screen(course, active, topic_names): ): start_focus_controls(active) + if active.get("focus_timer", {}).get("since") is None: + with st.container(key="practice_paused_notice"): + st.markdown('
' + escape(tr("Timer paused. Your answers are kept. Resume above when you are ready.")) + '
', unsafe_allow_html=True) + if active.get("warning") and index == 0: st.caption(tr(active["warning"])) diff --git a/services/i18n.py b/services/i18n.py index f6a2933..02cc582 100644 --- a/services/i18n.py +++ b/services/i18n.py @@ -615,6 +615,11 @@ def remember_language() -> None: "Hide original wording": "收起原始表述", }) +_TRANSLATIONS.update({ + "Return to practice": "回到当前练习", + "Timer paused. Your answers are kept. Resume above when you are ready.": "计时已暂停,当前答案会保留。准备好后,点击上方“继续”即可。", +}) + _DYNAMIC = [ (r"^(\d+) questions could benefit from another look\.$", r"有 \1 道题值得再看一遍。"), (r"^Different questions: (\d+)$", r"不同题目数:\1"), diff --git a/services/study_navigation.py b/services/study_navigation.py new file mode 100644 index 0000000..225e6b8 --- /dev/null +++ b/services/study_navigation.py @@ -0,0 +1,24 @@ +"""Shared course context and a non-destructive return to unfinished practice.""" +import streamlit as st +from services.i18n import tr +from services.practice_pages_ui import drop_pending_requests + +STUDY_PATHS = {'Study_Hub', 'Performance', 'Knowledge_Graph', 'Learning_Radar', 'Concept_Lab', 'Export_Anki', 'Flashcards'} + + +def render_study_context(course, page_path, title): + with st.container(key='flight_course_context', horizontal=True, + horizontal_alignment='distribute', vertical_alignment='center'): + st.caption(f'{course.course_name} / {title}') + active = st.session_state.get(f'active_practice_{course.course_id}') + if page_path not in STUDY_PATHS or not active or 'result' in active: + return + questions = active.get('questions', []) + if not questions: + return + number = max(1, min(active.get('worksheet_index', 0)+1, len(questions))) + with st.container(key='study_return_action', width='content'): + if st.button(tr('Return to practice') + f' · {number}/{len(questions)}', + icon=':material/arrow_forward:', key=f'study_return_{course.course_id}'): + drop_pending_requests(st.session_state, course.course_id) + st.switch_page('pages/2_Practice_Center.py') diff --git a/services/tutor_assistant_ui.py b/services/tutor_assistant_ui.py index ce90788..b40bca7 100644 --- a/services/tutor_assistant_ui.py +++ b/services/tutor_assistant_ui.py @@ -21,14 +21,15 @@ @lru_cache(maxsize=1) def _component(): - icon = base64.b64encode((ASSETS / "pilot-robot.svg").read_bytes()).decode("ascii") + icon = base64.b64encode((ASSETS / "brand-plane.svg").read_bytes()).decode("ascii") html = (ASSETS / "tutor_assistant.html").read_text(encoding="utf-8").replace( "__PILOT_MASCOT_DATA_URI__", f"data:image/svg+xml;base64,{icon}", ) return components.component( "exampilot_floating_tutor", html=html, - css=(ASSETS / "ui_typography.css").read_text(encoding="utf-8") + css=(ASSETS / "ui_tokens.css").read_text(encoding="utf-8") + + "\n" + (ASSETS / "ui_typography.css").read_text(encoding="utf-8") + "\n" + (ASSETS / "tutor_assistant.css").read_text(encoding="utf-8"), js=(ASSETS / "tutor_assistant.js").read_text(encoding="utf-8"), diff --git a/services/ui_style.py b/services/ui_style.py index 59540df..6123f9a 100644 --- a/services/ui_style.py +++ b/services/ui_style.py @@ -58,7 +58,7 @@ def apply_app_styles() -> None: # Later sheets win: the paper theme layers over the earlier academic styles. paper = "\n".join(_stylesheet(path) for path in paper_stylesheets()) st.markdown( - "