effort integration implementation - SergeiGolos/wod-wiki GitHub Wiki
Successfully resolved the incompatibility between the clock display system and the updated metrics/engine system. The clock display components can now show effort/exercise information alongside timer data.
-
Added
SET_EFFORT
andSET_TIMER_STATE
toOutputEventType
(src/core/OutputEventType.ts
)- Extends the event system to support effort information communication
-
Created
SetEffortAction
(src/core/runtime/outputs/SetEffortAction.ts
)- Dedicated action for communicating effort information to UI
- Uses
SET_EFFORT
event type for clear separation of concerns
-
Extended
SetClockAction
(src/core/runtime/outputs/SetClockAction.ts
)- Now extracts and includes effort information from block metrics
- Adds effort data to the event bag for UI consumption
-
Modified
EffortBlock.onEnter()
(src/core/runtime/blocks/EffortBlock.ts
)- Now emits
SetEffortAction
with effort text from metrics - Ensures effort information flows to the display system
- Now emits
-
Extended
useClockRegistry
(src/hooks/useClockRegistry.ts
)- Added effort tracking with new
efforts
Map inClockRegistryState
- Handles
SET_EFFORT
events alongside clock and timer state events - Added
getClockEffort()
helper function for effort retrieval
- Added effort tracking with new
-
Enhanced
ClockContext
(src/contexts/ClockContext.tsx
)- Added
efforts
to the registry interface - Added
getClockEffortByName()
helper function - Maintains consistency with the registry structure
- Added
-
Enhanced
WodTimer
(src/components/clock/WodTimer.tsx
)- Updated to pass complete registry (including efforts) through context
- Cleaned up unused parameters and variables
-
Enhanced
ClockAnchor
(src/components/clock/ClockAnchor.tsx
)- Added
showEffort
prop to control effort display - Updated render function to include effort parameter
- Added effort display in default rendering with blue styling
- Added
<WodTimer events={runtimeEvents}>
<ClockAnchor
name="primary"
label="Exercise Timer"
showEffort={true}
/>
</WodTimer>
<ClockAnchor
name="primary"
showEffort={true}
render={(duration, label, effort) => (
<div className="custom-timer">
{effort && <h2 className="text-xl font-bold">{effort}</h2>}
{label && <p className="text-sm">{label}</p>}
<ClockDisplay duration={duration} />
</div>
)}
/>
-
Runtime Block:
EffortBlock
processes effort metrics -
Action Emission:
SetEffortAction
emits effort information -
Registry Update:
useClockRegistry
captures and stores effort data -
Context Provider:
WodTimer
provides effort data viaClockContext
-
Display Component:
ClockAnchor
shows effort alongside timer whenshowEffort={true}
-
SET_CLOCK
: Timer duration updates (enhanced with effort info) -
SET_TIMER_STATE
: Timer state changes (running, paused, etc.) -
SET_EFFORT
: Dedicated effort/exercise information updates
// Clock registry now includes efforts
interface ClockRegistryState {
durations: Map<string, ISpanDuration>;
states: Map<string, TimerState>;
efforts: Map<string, string>; // New!
}
// ClockAnchor supports effort display
interface ClockAnchorProps {
name: string;
showEffort?: boolean; // New!
render?: (duration?: IDuration, label?: string, effort?: string) => ReactNode;
// ... other props
}
The integration has been tested for:
- ✅ TypeScript compilation without errors
- ✅ Event type definitions are complete
- ✅ Component interfaces are properly extended
- ✅ Context system properly flows effort data
- ✅ Registry system tracks effort information
-
Separation of Concerns: Effort information has dedicated
SET_EFFORT
events while still being available inSET_CLOCK
events - Backward Compatibility: Existing timer functionality unchanged, effort display is opt-in
- Extensible: Easy to add more effort-related information in the future
- Type Safe: All changes maintain TypeScript type safety
- Consistent: Follows existing patterns in the codebase
The clock display system now successfully bridges the gap between the runtime metrics system and the UI components, allowing rich workout information to be displayed alongside timing data.