Add study right mode panel implementation plan

This commit is contained in:
TTlaji committed 2026-06-08 19:08:22 +08:00
1 parent 584fb3e5f1
commit cbf62236cf
1 file changed
+461
@@ -0,0 +1,461 @@
# Speaking Lab Study Right Mode Panel Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Move the learning mode bar and focused practice UI into the right panel, while display modes show the transcript list and input modes hide it.
**Architecture:** Reuse the existing practice helpers and mode state. Move existing markup from the left video panel into the right panel, then make `app.js` toggle between transcript-list view and focused-practice view based on `subtitleMode`.
**Tech Stack:** Vanilla HTML, CSS, JavaScript, Node `assert` tests, FastAPI static app for browser verification.
---
## File Structure
- `F:\ooo\speaking-practice-local\study.html`: move existing practice mode/prompt markup from below the video controls into the right panel.
- `F:\ooo\speaking-practice-local\app.js`: toggle right-panel views by mode and keep practice reset/checking behavior.
- `F:\ooo\speaking-practice-local\styles.css`: remove the extra left-panel row and restyle the right panel for transcript vs focused practice modes.
- `F:\ooo\speaking-practice-local\tests\practice-helpers.test.mjs`: no changes expected; existing helper coverage should continue to pass.
## Task 1: Move Practice Markup Into Right Panel
**Files:**
- Modify: `F:\ooo\speaking-practice-local\study.html`
- [ ] **Step 1: Move the practice panel out of the video panel**
In `study.html`, remove this entire block from inside `.video-panel`, currently between `.tool-row` and `.recording-line`:
```html
<section class="practice-panel" aria-label="当前句练习">
<div class="practice-mode-bar tabs" aria-label="学习模式">
<button class="tab active" type="button" data-mode="bilingual">双语</button>
<button class="tab" type="button" data-mode="english">英文</button>
<button class="tab" type="button" data-mode="chinese">中文</button>
<button class="tab" type="button" data-mode="dictation">听写</button>
<button class="tab" type="button" data-mode="translation">中译英</button>
</div>
<div class="practice-body">
<div class="practice-prompt">
<span id="practiceModeLabel" class="practice-label">双语</span>
<p id="practicePromptText" class="practice-primary"></p>
<p id="practiceReferenceText" class="practice-secondary"></p>
</div>
<div id="practiceAnswerRow" class="practice-answer-row" hidden>
<textarea id="practiceAnswerInput" rows="2" placeholder="输入你的英文答案"></textarea>
<button id="checkPracticeBtn" type="button">核对</button>
</div>
<p id="practiceFeedback" class="practice-feedback" aria-live="polite"></p>
</div>
</section>
```
- [ ] **Step 2: Add the mode bar to the right panel toolbar**
Replace the current right panel toolbar:
```html
<div class="transcript-toolbar">
<div class="transcript-title">
<strong>字幕列表</strong>
<span id="subtitleMeta"></span>
</div>
</div>
```
with:
```html
<div class="transcript-toolbar">
<div class="practice-mode-bar tabs" aria-label="学习模式">
<button class="tab active" type="button" data-mode="bilingual">双语</button>
<button class="tab" type="button" data-mode="english">英文</button>
<button class="tab" type="button" data-mode="chinese">中文</button>
<button class="tab" type="button" data-mode="dictation">听写</button>
<button class="tab" type="button" data-mode="translation">中译英</button>
</div>
<div class="transcript-title">
<strong id="rightPanelTitle">字幕列表</strong>
<span id="subtitleMeta"></span>
</div>
</div>
```
- [ ] **Step 3: Add focused practice view inside the right panel**
Insert this block after the closing `</div>` for `.transcript-toolbar` and before `<div id="transcriptList"`:
```html
<section id="rightPracticeView" class="right-practice-view" aria-label="当前句练习" hidden>
<div class="practice-body">
<div class="practice-prompt">
<span id="practiceModeLabel" class="practice-label">双语</span>
<p id="practicePromptText" class="practice-primary"></p>
<p id="practiceReferenceText" class="practice-secondary"></p>
</div>
<div id="practiceAnswerRow" class="practice-answer-row" hidden>
<textarea id="practiceAnswerInput" rows="4" placeholder="输入你的英文答案"></textarea>
<button id="checkPracticeBtn" type="button">核对</button>
</div>
<p id="practiceFeedback" class="practice-feedback" aria-live="polite"></p>
</div>
</section>
```
- [ ] **Step 4: Verify there is no left practice panel**
Run:
```powershell
Select-String -Path study.html -Pattern 'practice-panel|rightPracticeView|practice-mode-bar|rightPanelTitle'
```
Expected:
- No `practice-panel` result.
- One `rightPracticeView` result.
- One `practice-mode-bar` result in the right panel.
- One `rightPanelTitle` result.
- [ ] **Step 5: Commit markup movement**
```powershell
git add study.html
git commit -m "refactor: move study practice markup to right panel"
```
## Task 2: Toggle Right Panel Views By Mode
**Files:**
- Modify: `F:\ooo\speaking-practice-local\app.js`
- [ ] **Step 1: Add right-panel DOM references**
In the `els` object near the existing transcript/practice refs, add:
```javascript
rightPanelTitle: IS_BROWSER ? document.querySelector("#rightPanelTitle") : null,
rightPracticeView: IS_BROWSER ? document.querySelector("#rightPracticeView") : null,
```
- [ ] **Step 2: Add view mode helper**
Add this helper after `renderSubtitleModeTabs()`:
```javascript
function isInputPracticeMode(mode = subtitleMode) {
return mode === "dictation" || mode === "translation";
}
```
- [ ] **Step 3: Update `renderPracticePanel()` to toggle panel visibility**
Replace the current `renderPracticePanel()` function with:
```javascript
function renderPracticePanel() {
const isPracticeMode = isInputPracticeMode();
if (els.rightPracticeView) els.rightPracticeView.hidden = !isPracticeMode;
if (els.transcriptList) els.transcriptList.hidden = isPracticeMode;
if (els.rightPanelTitle) {
els.rightPanelTitle.textContent = isPracticeMode ? practiceModeLabels[subtitleMode] : "字幕列表";
}
if (!els.practiceModeLabel || !els.practicePromptText || !els.practiceReferenceText) return;
const viewState = getPracticeViewState(subtitleMode, getActiveCuePair());
els.practiceModeLabel.textContent = viewState.label;
els.practicePromptText.textContent = viewState.promptText;
els.practiceReferenceText.textContent = isPracticeMode ? viewState.referenceText : "";
if (els.practiceAnswerRow) els.practiceAnswerRow.hidden = !viewState.inputVisible;
if (els.checkPracticeBtn) els.checkPracticeBtn.disabled = viewState.inputVisible && !viewState.canCheck;
if (viewState.feedbackHint && els.practiceFeedback && !els.practiceFeedback.textContent) {
els.practiceFeedback.textContent = viewState.feedbackHint;
els.practiceFeedback.className = "practice-feedback is-muted";
}
}
```
- [ ] **Step 4: Update subtitle meta for focused modes**
In `renderTranscript()`, replace:
```javascript
if (els.subtitleMeta) els.subtitleMeta.textContent = modeConfig.message || `${primary.length} 句 · 点击文字稿跳转到对应片段`;
```
with:
```javascript
if (els.subtitleMeta) {
els.subtitleMeta.textContent = isInputPracticeMode()
? "专注练习当前句"
: modeConfig.message || `${primary.length} 句 · 点击文字稿跳转到对应片段`;
}
```
Do not return early. The transcript list can still be rebuilt while hidden so sentence status and active line state remain intact.
- [ ] **Step 5: Run syntax and helper tests**
Run:
```powershell
node --check app.js
node tests\practice-helpers.test.mjs
node tests\progress-helpers.test.mjs
```
Expected: all commands pass with no output.
- [ ] **Step 6: Commit view toggling**
```powershell
git add app.js
git commit -m "feat: toggle right panel practice views"
```
## Task 3: Restyle Right Panel And Restore Video Panel Rows
**Files:**
- Modify: `F:\ooo\speaking-practice-local\styles.css`
- [ ] **Step 1: Restore video panel row count**
Replace:
```css
.video-panel {
min-width: 0;
min-height: 0;
overflow: hidden;
display: grid;
grid-template-rows: minmax(500px, 1fr) auto auto auto;
}
```
with:
```css
.video-panel {
min-width: 0;
min-height: 0;
overflow: hidden;
display: grid;
grid-template-rows: minmax(520px, 1fr) auto auto;
}
```
- [ ] **Step 2: Update transcript toolbar layout**
Replace the existing `.transcript-toolbar` block with:
```css
.transcript-toolbar {
display: grid;
gap: 10px;
padding: 12px 14px;
border-bottom: 1px solid var(--line);
}
```
- [ ] **Step 3: Replace left practice panel styling with right practice view styling**
Replace:
```css
.practice-panel {
display: grid;
gap: 12px;
padding: 13px 16px 14px;
border-top: 1px solid var(--line);
background: #fbfdfd;
}
```
with:
```css
.right-practice-view {
min-height: 0;
overflow: auto;
padding: 14px;
background: #fbfdfd;
}
```
- [ ] **Step 4: Tune focused practice spacing**
After the `.practice-body` block, add:
```css
.right-practice-view .practice-body {
min-height: 100%;
align-content: start;
gap: 12px;
}
```
Replace the `.practice-prompt` block with:
```css
.practice-prompt {
min-height: 118px;
display: grid;
align-content: center;
gap: 7px;
padding: 16px;
border: 1px solid #dde7ef;
border-radius: 8px;
background: #ffffff;
}
```
- [ ] **Step 5: Remove mobile rules for the removed left practice panel**
In the `@media (max-width: 560px)` block, replace:
```css
.video-panel {
grid-template-rows: minmax(340px, 1fr) auto auto auto;
}
```
with:
```css
.video-panel {
grid-template-rows: minmax(360px, 1fr) auto auto;
}
```
Remove this block:
```css
.practice-panel {
padding: 12px;
}
```
Keep the `.practice-answer-row` one-column and button-width rules, because they still apply to the right focused practice view on mobile.
- [ ] **Step 6: Run selector scan**
Run:
```powershell
Select-String -Path styles.css -Pattern 'practice-panel|right-practice-view|practice-mode-bar|transcript-toolbar|grid-template-rows: minmax'
```
Expected:
- No `.practice-panel` selector remains.
- `.right-practice-view` appears.
- `.practice-mode-bar` appears.
- `.transcript-toolbar` appears.
- Desktop video rows are `minmax(520px, 1fr) auto auto`.
- Mobile video rows are `minmax(360px, 1fr) auto auto`.
- [ ] **Step 7: Commit styles**
```powershell
git add styles.css
git commit -m "style: focus practice modes in right panel"
```
## Task 4: Verification
**Files:**
- Verify: `F:\ooo\speaking-practice-local\study.html`
- Verify: `F:\ooo\speaking-practice-local\app.js`
- Verify: `F:\ooo\speaking-practice-local\styles.css`
- [ ] **Step 1: Run automated checks**
```powershell
node --check app.js
node --check home.js
node --check admin.js
node tests\practice-helpers.test.mjs
node tests\progress-helpers.test.mjs
node tests\admin-file-input.test.mjs
python -m py_compile backend\main.py backend\db.py
```
Expected: all commands pass with no output.
- [ ] **Step 2: Start or reuse local server**
Run:
```powershell
python -m uvicorn backend.main:app --host 127.0.0.1 --port 8000
```
Expected: server is available at `http://127.0.0.1:8000`.
- [ ] **Step 3: Browser check desktop layout**
Open:
```text
http://127.0.0.1:8000/study.html
```
Confirm:
- The left video area has no mode bar and no practice input.
- The left video panel rows are video, toolbar, recording line only.
- The right panel mode bar shows exactly `双语`, `英文`, `中文`, `听写`, `中译英`.
- `挖空` does not appear.
- In `双语`, `英文`, and `中文`, the transcript list is visible.
- In `听写`, the transcript list is hidden and only dictation UI is visible.
- In `中译英`, the transcript list is hidden and only translation UI is visible.
- Correct and incorrect answer checking still works.
- Switching modes clears input and feedback.
- Moving to next sentence clears input and feedback.
- [ ] **Step 4: Browser check preserved controls**
Confirm:
- Previous, replay, and next still move between cues.
- Loop checkbox remains visible and clickable.
- Favorite remains visible and clickable.
- Recording buttons remain in the left toolbar.
- `已练` and `难句` still appear and work in transcript display modes.
- [ ] **Step 5: Browser check narrow viewport**
Resize to about 390px wide.
Confirm:
- Right panel stacks below the video as before.
- Mode buttons wrap without horizontal overflow.
- `听写` and `中译英` focused views do not show the transcript list.
- Input and check button stack cleanly.
- No text overlaps or spills outside buttons.
- [ ] **Step 6: Final status check**
Run:
```powershell
git status --short
```
Expected: implementation files are committed. Existing unrelated local edits may remain and must not be reverted.
## Self-Review Notes
- Spec coverage: tasks cover keeping the two-column structure, moving learning controls out of the left video area, placing the mode bar in the right panel, showing transcript only for display modes, hiding transcript for `听写` and `中译英`, preserving existing controls, and excluding `挖空`.
- Placeholder scan: no `TBD`, `TODO`, or unspecified implementation steps are present.
- Type consistency: mode ids remain `bilingual`, `english`, `chinese`, `dictation`, and `translation`.