Implemented complete TCA architecture for iOS and watchOS targets: - Authentication flow (Sign in with Apple + Yahoo OAuth) - OAuth token management with iCloud Key-Value Storage - Yahoo Fantasy Sports API client with async/await - Watch Connectivity for iPhone ↔ Watch data sync - Complete UI for both iPhone and Watch platforms Core features: - Matchup score display - Category breakdown with win/loss/tie indicators - Roster status tracking - Manual refresh functionality - Persistent data caching on Watch Technical stack: - The Composable Architecture for state management - Swift Concurrency (async/await, actors) - WatchConnectivity framework - Sign in with Apple - OAuth 2.0 authentication flow 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
64 lines
1.8 KiB
Swift
64 lines
1.8 KiB
Swift
//
|
|
// WatchMatchupFeature.swift
|
|
// FantasyWatch Watch App
|
|
//
|
|
// Created by Claude Code
|
|
//
|
|
|
|
import ComposableArchitecture
|
|
import Foundation
|
|
|
|
@Reducer
|
|
struct WatchMatchupFeature {
|
|
@ObservableState
|
|
struct State: Equatable {
|
|
var matchup: Matchup?
|
|
var roster: RosterStatus?
|
|
var lastUpdate: Date?
|
|
var isRefreshing = false
|
|
}
|
|
|
|
enum Action {
|
|
case onAppear
|
|
case receivedMatchupData(Matchup, RosterStatus, Date)
|
|
case refreshTapped
|
|
case refreshComplete
|
|
}
|
|
|
|
@Dependency(\.watchConnectivityClient) var watchConnectivityClient
|
|
|
|
var body: some ReducerOf<Self> {
|
|
Reduce { state, action in
|
|
switch action {
|
|
case .onAppear:
|
|
return .run { send in
|
|
for await (matchup, roster, timestamp) in watchConnectivityClient.matchupUpdates() {
|
|
await send(.receivedMatchupData(matchup, roster, timestamp))
|
|
}
|
|
}
|
|
|
|
case let .receivedMatchupData(matchup, roster, timestamp):
|
|
state.matchup = matchup
|
|
state.roster = roster
|
|
state.lastUpdate = timestamp
|
|
state.isRefreshing = false
|
|
return .none
|
|
|
|
case .refreshTapped:
|
|
state.isRefreshing = true
|
|
return .run { send in
|
|
try await watchConnectivityClient.requestRefresh()
|
|
try await Task.sleep(for: .seconds(2))
|
|
await send(.refreshComplete)
|
|
} catch: { error, send in
|
|
await send(.refreshComplete)
|
|
}
|
|
|
|
case .refreshComplete:
|
|
state.isRefreshing = false
|
|
return .none
|
|
}
|
|
}
|
|
}
|
|
}
|