crossmate

A collaborative crossword app for iOS
Log | Files | Refs | LICENSE

EngagementHostEnvironment.swift (685B)


      1 import SwiftUI
      2 
      3 @MainActor
      4 @Observable
      5 final class EngagementStatus {
      6     private(set) var liveGameIDs: Set<UUID> = []
      7 
      8     func isLive(gameID: UUID) -> Bool {
      9         liveGameIDs.contains(gameID)
     10     }
     11 
     12     func setLive(_ isLive: Bool, gameID: UUID) {
     13         if isLive {
     14             liveGameIDs.insert(gameID)
     15         } else {
     16             liveGameIDs.remove(gameID)
     17         }
     18     }
     19 }
     20 
     21 private struct EngagementStatusKey: EnvironmentKey {
     22     static let defaultValue: EngagementStatus? = nil
     23 }
     24 
     25 extension EnvironmentValues {
     26     var engagementStatus: EngagementStatus? {
     27         get { self[EngagementStatusKey.self] }
     28         set { self[EngagementStatusKey.self] = newValue }
     29     }
     30 }