Skip to content

Commit efe378a

Browse files
fuzzie360claude
andcommitted
feat: Prev task button in the task toolbar
Steps back through tasks, crossing module and track boundaries to the previous module's last task; disabled only on the course's very first task. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RJujXBsBhXBbQ72tS7E7GV
1 parent c457bfb commit efe378a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/Learn/scss/_task.scss‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@
160160
color: var(--ink);
161161
}
162162

163+
// Prev on the course's first task is disabled-by-position, not busy
164+
.tb-right .tb-btn[disabled] {
165+
opacity: .35;
166+
cursor: not-allowed;
167+
}
168+
163169
.bench-chip {
164170
display: flex;
165171
align-items: center;

‎src/Learn/task/TaskPage.jsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,21 @@ function TaskWorkspace({ module, task, taskNum, taskIndex, taskId, total }) {
394394
}, [module]);
395395
const lastInTrack = !nextModule || nextModule.track !== module.track;
396396

397+
// previous module in the global sorted order; null on the course's first
398+
const prevModule = useMemo(() => {
399+
const idx = modules.findIndex(m => m.id === module.id);
400+
return idx > 0 ? modules[idx - 1] : null;
401+
}, [module]);
402+
const prevEnabled = taskNum > 1 || Boolean(prevModule);
403+
404+
const handlePrev = useCallback(() => {
405+
if (taskNum > 1) {
406+
navigate(`/learn/${module.id}/${taskNum - 1}`);
407+
return;
408+
}
409+
if (prevModule) navigate(`/learn/${prevModule.id}/${prevModule.tasks.length}`);
410+
}, [navigate, module, taskNum, prevModule]);
411+
397412
const handleNext = useCallback(() => {
398413
if (taskNum < total) {
399414
navigate(`/learn/${module.id}/${taskNum + 1}`);
@@ -522,6 +537,14 @@ function TaskWorkspace({ module, task, taskNum, taskIndex, taskId, total }) {
522537
<button type="button" className="tb-btn" onClick={handleReset}>
523538
Reset code
524539
</button>
540+
<button
541+
type="button"
542+
className="tb-btn"
543+
onClick={handlePrev}
544+
disabled={!prevEnabled}
545+
>
546+
← Prev task
547+
</button>
525548
<button
526549
type="button"
527550
className="tb-next"

0 commit comments

Comments
 (0)