Advanced Typescript
This extra is a real-world React + Vite app where you will apply everything from the Advanced TypeScript workshop. The app runs with placeholder logic, and you will implement the utilities that make it fully functional.
🐨 Open
src/utils.ts
and implement every type and function marked with 🐨.
🐨 Then open
src/app.tsx
and use your utilities where marked with 🐨.

Observable behavior to aim for

formatDuration(ms)

Return zero-padded mm:ss for a duration in milliseconds:
Input (ms)Output
000:00
6500001:05
150000025:00

getNextPhase(current, completedFocusSessions, settings)

completedFocusSessions is the number of focus sessions completed so far, including the focus session you just finished when leaving 'focus'.
After a focus session, take a long break when that completed count reaches a multiple of settings.longBreakInterval; otherwise take a short break. After either break, return to focus.
Transition table (longBreakInterval: 4):
Current phasecompletedFocusSessionsNext phase
focus1shortBreak
focus2shortBreak
focus3shortBreak
focus4longBreak
focus8longBreak
shortBreak(any)focus
longBreak(any)focus
The UI should pass that completed-focus count into getNextPhase (see the handleComplete note in app.tsx).

getSessionStreak(sessions)

Count how many consecutive sessions at the start of the array (newest first) have phase: 'focus'.
Example: [{ phase: 'focus' }, { phase: 'focus' }, { phase: 'shortBreak' }] β†’ streak 2.

groupSessionsByPhase(sessions)

Return { focus: [...], shortBreak: [...], longBreak: [...] } containing every session under its phase key.

Running the app

npm run dev
The app should load without changes. As you implement the utilities, the UI will become more accurate and interactive.

Please set the playground first

Loading "Focus Timer"
Login to get access to the exclusive discord channel.
Loading Discord Posts