-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: All views should use OCKAnyEvent instead of fetched values (#28)
- Loading branch information
Showing
25 changed files
with
551 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Sources/CareKitEssentials/Cards/Shared/Extensions/InstructionsTaskView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// InstructionsTaskView.swift | ||
// CareKitEssentials | ||
// | ||
// Created by Corey Baker on 5/20/23. | ||
// | ||
|
||
import CareKit | ||
import CareKitStore | ||
import CareKitUI | ||
import Foundation | ||
import SwiftUI | ||
|
||
public extension InstructionsTaskView where Header == InformationHeaderView { | ||
|
||
/// Create a view using data from an event. | ||
/// | ||
/// This view displays task instructions and a button to toggle completion for | ||
/// the event. | ||
/// | ||
/// - Parameters: | ||
/// - event: The data displayed in the view. | ||
/// - store: The Care Store changes to this event should be made to. | ||
/// - onError: A closure that the struct calls if an error occurs while toggling completion for the event. | ||
init( | ||
event: OCKAnyEvent, | ||
store: OCKAnyStoreProtocol, | ||
onError: @escaping (OCKStoreError) -> Void = { _ in } | ||
) { | ||
|
||
let progress = event.computeProgress(by: .checkingOutcomeExists) | ||
|
||
self.init( | ||
instructions: event.instructionsText, | ||
isComplete: progress.isCompleted, | ||
action: { | ||
Task { | ||
do { | ||
_ = try await event.toggleBooleanOutcome(store: store) | ||
} catch let error as OCKStoreError { | ||
onError(error) | ||
} | ||
} | ||
}, | ||
header: { | ||
InformationHeaderView( | ||
title: Text(event.title), | ||
information: event.detailText, | ||
event: event | ||
) | ||
|
||
} | ||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Sources/CareKitEssentials/Cards/Shared/Extensions/SimpleTaskView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// SimpleTaskView.swift | ||
// CareKitEssentials | ||
// | ||
// Created by Corey Baker on 5/20/23. | ||
// | ||
|
||
import CareKit | ||
import CareKitStore | ||
import CareKitUI | ||
import Foundation | ||
import SwiftUI | ||
|
||
public extension SimpleTaskView where Header == InformationHeaderView { | ||
|
||
/// Create a view using data from an event. | ||
/// | ||
/// This view displays a button to toggle completion for the event. | ||
/// | ||
/// - Parameters: | ||
/// - event: The data be displayed in the view. | ||
/// - store: The Care Store changes to this event should be made to. | ||
/// - onError: A closure that the struct calls if an error occurs while toggling completion for the event. | ||
init( | ||
event: OCKAnyEvent, | ||
store: OCKAnyStoreProtocol, | ||
onError: @escaping (OCKStoreError) -> Void = { _ in } | ||
) { | ||
let progress = event.computeProgress(by: .checkingOutcomeExists) | ||
|
||
self.init( | ||
isComplete: progress.isCompleted, | ||
action: { | ||
Task { | ||
do { | ||
_ = try await event.toggleBooleanOutcome(store: store) | ||
} catch let error as OCKStoreError { | ||
onError(error) | ||
} | ||
} | ||
}, | ||
header: { | ||
InformationHeaderView( | ||
title: Text(event.title), | ||
information: event.detailText, | ||
event: event | ||
) | ||
} | ||
) | ||
} | ||
} |
Oops, something went wrong.