Persistent Profile and Dynamic Menu
Integrating Persistent Profile and a Dynamic Menu
In the previous lesson, you built a simple persistence layer and wired it into the app so the player profile can be saved and restored. In this lesson, you will put that to work by:
- Updating the reducer to record lifetime stats (
totalRevenue,totalCustomersServed,bestRevenue,totalGamesPlayed,winStreak, and more). - Reading those stats in the main menu and rendering them live.
- Adding a light polish pass to the menu styles.
By the end, the menu will show real-time stats that survive page reloads, creating a sense of progress.
Update the Reducer to Track and Persist Profile Stats
You will connect profile updates into the core game loop. The reducer will increment totals after each game, update best revenue, and maintain a win streak. Because you restored the profile in the previous lesson, these updates will be written back to storage automatically.
src/reducer/gameReducer.js
Explanation:
- Only
getInitialState,START_GAME, and the relevantTICKlogic are shown. - These are the parts that update and persist the profile stats as described in the lesson (such as total revenue, customers served, best revenue, games played, and win streak).
Render Live Stats in the Menu
The menu reads the profile from the global state and displays a quick snapshot. Buttons let the player start a game or navigate to settings.
src/components/MenuScreen.jsx
Explanation:
useGameContextgives youstateanddispatch. You readstate.profilefor the stats.- The
stat-pillelements show best revenue, total games, and the current win streak. - Buttons dispatch reducer actions, so the menu reacts instantly.
Polish the Menu UI
These styles add structure, subtle animation, and clear call-to-action buttons.
src/components/MenuScreen.css
Explanation:
- The container uses a blurred, translucent panel for focus.
stat-pillstyles create compact badges for key metrics.large-btnprovides strong visual affordance with hover/focus feedback.
Summary and Next Steps
You connected the saved profile to gameplay and surfaced it in the UI:
- The reducer now updates lifetime stats after each game (including best revenue, win streak, total revenue, customers served, and games played).
- The menu displays those stats in real time and looks polished.
This makes progress visible and motivating. Ready to lock it in? Head to the practice section — let’s make these changes feel second nature.
