effort integration implementation - SergeiGolos/wod-wiki GitHub Wiki

Clock Display and Effort Integration - Implementation Summary

Overview

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.

Key Changes Made

1. Enhanced Event System

  • Added SET_EFFORT and SET_TIMER_STATE to OutputEventType (src/core/OutputEventType.ts)
    • Extends the event system to support effort information communication

2. New Action Class

  • 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

3. Enhanced Existing Actions

  • 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

4. Updated Runtime Blocks

  • 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

5. Enhanced Registry System

  • Extended useClockRegistry (src/hooks/useClockRegistry.ts)
    • Added effort tracking with new efforts Map in ClockRegistryState
    • Handles SET_EFFORT events alongside clock and timer state events
    • Added getClockEffort() helper function for effort retrieval

6. Updated Context System

  • Enhanced ClockContext (src/contexts/ClockContext.tsx)
    • Added efforts to the registry interface
    • Added getClockEffortByName() helper function
    • Maintains consistency with the registry structure

7. Updated Components

  • 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

Usage Examples

Basic Timer with Effort Display

<WodTimer events={runtimeEvents}>
  <ClockAnchor 
    name="primary" 
    label="Exercise Timer"
    showEffort={true}
  />
</WodTimer>

Custom Effort Rendering

<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>
  )}
/>

Data Flow

  1. Runtime Block: EffortBlock processes effort metrics
  2. Action Emission: SetEffortAction emits effort information
  3. Registry Update: useClockRegistry captures and stores effort data
  4. Context Provider: WodTimer provides effort data via ClockContext
  5. Display Component: ClockAnchor shows effort alongside timer when showEffort={true}

Event Types Supported

  • 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

Key Interfaces

// 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
}

Testing

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

Architecture Benefits

  1. Separation of Concerns: Effort information has dedicated SET_EFFORT events while still being available in SET_CLOCK events
  2. Backward Compatibility: Existing timer functionality unchanged, effort display is opt-in
  3. Extensible: Easy to add more effort-related information in the future
  4. Type Safe: All changes maintain TypeScript type safety
  5. 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.

⚠️ **GitHub.com Fallback** ⚠️