6.4 KiB
Speaking Lab Learning Progress v1 Design
Goal
Add a local-first learning progress layer so a learner can leave a video, come back later, and immediately know where to continue and which subtitle lines still need practice.
Current Context
Speaking Lab already has:
- A study page that loads videos from
/api/videos. - Subtitle parsing and clickable transcript lines.
- Playback controls for previous, replay, next, and loop.
- Local login stored in
localStorageunderspeaking-lab-state-v1. - Per-user favorites and watch-later lists stored locally.
- An admin page for adding and deleting materials.
This feature keeps the same local-first model. It does not add backend users, cloud sync, or production authentication.
Scope
Learning Progress v1 includes:
- Save the last playback time for each user and video.
- Save the last active subtitle line for each user and video.
- Add a
继续学习action when a video has saved progress. - Restore progress when the learner opens a video.
- Add per-line practice status controls:
已练难句
- Show practice status on transcript lines.
- Show progress in the left material list, for example
35%. - Store all progress in browser
localStorage.
Learning Progress v1 excludes:
- Backend progress persistence.
- Multi-device sync.
- Learning calendars, streaks, charts, or dashboards.
- Persistent recording history.
- AI pronunciation scoring.
- Real authentication or role enforcement.
User Experience
Continue Learning
When a logged-in learner opens a video with saved progress:
- The video restores to the last saved playback time.
- The transcript restores the previously active line when possible.
- A
继续学习button appears in the existing video action area. - Clicking
继续学习jumps to the saved time and plays from there.
If there is no saved progress for the current video:
- The
继续学习button is hidden or disabled. - The existing learning controls behave as they do today.
Transcript Line Status
Each transcript line gets two compact controls:
已练: marks the line as practiced.难句: marks the line as difficult.
The two states are independent:
- A line can be only practiced.
- A line can be only difficult.
- A line can be both practiced and difficult.
- Clicking an active state again removes that state.
Visual behavior:
- Practiced lines use a calm success state.
- Difficult lines use a warm warning state.
- Status controls stay compact and do not push transcript text into awkward wrapping.
Material List Progress
Each video item in the left material list shows a compact progress label:
- With subtitles:
已练 3/10 · 30% - Without subtitles but with playback progress:
看到 02:14 - With no progress: no extra progress label, keeping the list quiet.
Progress percentage is calculated from practiced subtitle lines:
practiced line count / primary subtitle line count
If the current primary subtitle language changes, the denominator follows the currently loaded primary cues for that video. If a video has no subtitle cues, v1 falls back to displaying saved playback time only.
Data Model
Progress is stored inside each local user object in speaking-lab-state-v1.
Existing user shape:
{
id: "user-...",
email: "learner@example.com",
password: "...",
role: "user",
favorites: [],
watchLater: []
}
New user shape:
{
id: "user-...",
email: "learner@example.com",
password: "...",
role: "user",
favorites: [],
watchLater: [],
progress: {
"video-id": {
currentTime: 124.5,
activeLineIndex: 6,
practicedLineIndexes: [0, 1, 2],
difficultLineIndexes: [4, 6],
updatedAt: "2026-06-01T12:00:00.000Z"
}
}
}
Compatibility:
- Existing users without
progressgetprogress: {}when loaded or updated. - Existing saved localStorage data must continue to work.
- Video IDs are stored as strings because API video IDs are normalized to strings in the frontend.
Save Rules
Playback progress saves:
- On video
timeupdate, savecurrentTime. - Throttle saves to avoid writing localStorage too frequently.
- Save immediately when selecting a different video.
- Save immediately when the page is about to unload.
Line progress saves:
- When active transcript line changes, save
activeLineIndex. - When the user toggles
已练or难句, save the updated arrays immediately.
Privacy and locality:
- All progress remains in the browser.
- Clearing browser storage clears progress.
Error Handling
If localStorage read fails:
- Fall back to an empty state, matching existing behavior.
If localStorage write fails:
- Keep the UI usable for the current session.
- Avoid showing noisy errors for every time update.
If a saved line index is out of range after subtitles are replaced:
- Keep saved playback time.
- Ignore the invalid line index and use the first available line.
If a video is deleted:
- Old progress entries may remain in localStorage.
- They are harmless because deleted videos will not render.
- Cleanup can be handled later when backend user sync exists.
UI Placement
Study page changes only:
- Add
继续学习beside existing收藏and稍后再看. - Add status controls inside each transcript line.
- Add progress text to each material item under speaker/tags.
Admin page does not change for this feature.
Testing
Manual verification:
- Log in as a normal user.
- Open a video with subtitles.
- Jump to a subtitle line and play briefly.
- Mark one line as
已练. - Mark another line as
难句. - Refresh the page.
- Confirm the same video restores progress.
- Confirm transcript line statuses remain visible.
- Confirm the left material list shows progress.
- Log out and log in as another user.
- Confirm the second user does not inherit the first user's progress.
Automated checks:
- Add small Node tests for pure progress helpers:
- default progress creation
- practiced percentage calculation
- line status toggle behavior
- progress summary formatting
- Keep existing syntax checks:
node --check app.jsnode --check admin.js
Future Extensions
After v1 works locally, good next steps are:
- Backend progress persistence.
- A small
我的学习page. - Review mode that filters only difficult lines.
- Recording history attached to specific subtitle lines.
- Export/import local progress before account sync exists.