Skip to content

Commit 399d962

Browse files
committed
feat: add /l to get to last exercise
1 parent de64ded commit 399d962

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getExercises } from '@epic-web/workshop-utils/apps.server'
2+
import { redirect, type LoaderFunctionArgs } from '@remix-run/node'
3+
4+
export async function loader({ request }: LoaderFunctionArgs) {
5+
const exercises = await getExercises({ request })
6+
if (!exercises.length) {
7+
throw new Response('No exercises found', { status: 404 })
8+
}
9+
const lastExercise = exercises[exercises.length - 1]
10+
if (!lastExercise || !lastExercise.steps || !lastExercise.steps.length) {
11+
throw new Response('No steps found in last exercise', { status: 404 })
12+
}
13+
const lastStep = lastExercise.steps[lastExercise.steps.length - 1]
14+
if (!lastStep || !lastStep.solution) {
15+
throw new Response('No solution found for last step', { status: 404 })
16+
}
17+
const exerciseNumber = lastExercise.exerciseNumber.toString().padStart(2, '0')
18+
const stepNumber = lastStep.stepNumber.toString().padStart(2, '0')
19+
return redirect(`/exercise/${exerciseNumber}/${stepNumber}/solution`)
20+
}
21+
22+
export default function LastExerciseRedirect() {
23+
return null
24+
}

packages/workshop-app/bin/epicshop.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ async function killChild(child) {
310310
}
311311

312312
function printSupportedKeys() {
313-
console.log(chalk.bold.cyan('\nSupported keys:'))
314-
console.log(` ${chalk.blue('o')} - open browser`)
315-
console.log(` ${chalk.green('u')} - update repo`)
316-
console.log(` ${chalk.magenta('r')} - restart`)
317-
console.log(` ${chalk.cyan('k')} - Kody kudos 🐨`)
318-
console.log(` ${chalk.gray('q')} (or ${chalk.gray('Ctrl+C')}) - exit`)
313+
console.log(`
314+
${chalk.bold.cyan('Supported keys:')}
315+
${chalk.blue('o')} - open browser
316+
${chalk.green('u')} - update repo
317+
${chalk.magenta('r')} - restart
318+
${chalk.cyan('k')} - Kody kudos 🐨
319+
${chalk.gray('q')} (or ${chalk.gray('Ctrl+C')}) - exit
320+
`)
319321
}

0 commit comments

Comments
 (0)