Skip to content

refactor(mobile): introduce container-presenter pattern for track details screen #143

Description

@masch

Description

Currently, TrackDetailScreen resolves track via getTrackById and passes it directly to hook consumers (useOfflineGeofence, useTrackDownload, useFeedbackTrigger). Since React Hooks must be executed unconditionally, all these hooks are typed to accept undefined or null, requiring nullish coalescing checks (e.g., track?.startCoordinates ?? { latitude: 0, longitude: 0 }).

We should refactor this screen using a Container-Presenter pattern:

  1. The container screen (TrackDetailScreen) handles loading, error states, and checks if track is defined. If track is undefined, it renders the NotFound view immediately.
  2. If the track exists, it renders a child presenter component (e.g., TrackDetailContent) passing the guaranteed LocalTrackMetadata as a prop.
  3. The child presenter component calls all track-specific hooks unconditionally without needing undefined null checks.

Benefits

  • Strict Type Safety: Hooks do not need to accept undefined or null track parameter.
  • Cleaner Code: Removes verbose fallback values in hook invocations.
  • Separation of Concerns: Container handles screen routing and resolution; presenter handles UI layout and media playback logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions