mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
* Swift 6 updates
- Soft-deprecate `_SynthesizedConformance` now that Xcode 16 has fixed
this bug.
- Update docs accordingly.
- Document Xcode 16 macro gotcha around custom build configuration
names.
* wip
87 lines
2.1 KiB
Swift
87 lines
2.1 KiB
Swift
import ComposableArchitecture
|
|
import SwiftUI
|
|
|
|
@Reducer
|
|
struct SyncUpDetail {
|
|
@Reducer
|
|
enum Destination {
|
|
case alert(AlertState<Alert>)
|
|
case edit(SyncUpForm)
|
|
@CasePathable
|
|
enum Alert {
|
|
case confirmButtonTapped
|
|
}
|
|
}
|
|
|
|
@ObservableState
|
|
struct State: Equatable {
|
|
@Presents var destination: Destination.State?
|
|
@Shared var syncUp: SyncUp
|
|
}
|
|
|
|
enum Action {
|
|
case cancelEditButtonTapped
|
|
case deleteButtonTapped
|
|
case destination(PresentationAction<Destination.Action>)
|
|
case doneEditingButtonTapped
|
|
case editButtonTapped
|
|
}
|
|
|
|
@Dependency(\.dismiss) var dismiss
|
|
|
|
var body: some ReducerOf<Self> {
|
|
Reduce { state, action in
|
|
switch action {
|
|
// case .alert(.presented(.confirmButtonTapped)):
|
|
case .destination(.presented(.alert(.confirmButtonTapped))):
|
|
@Shared(.fileStorage(.syncUps)) var syncUps: IdentifiedArrayOf<SyncUp> = []
|
|
syncUps.remove(id: state.syncUp.id)
|
|
return .run { _ in await dismiss() }
|
|
|
|
case .destination:
|
|
return .none
|
|
|
|
case .cancelEditButtonTapped:
|
|
state.destination = nil
|
|
return .none
|
|
|
|
case .deleteButtonTapped:
|
|
state.destination = .alert(.deleteSyncUp)
|
|
return .none
|
|
|
|
case .doneEditingButtonTapped:
|
|
guard let editedSyncUp = state.destination?.edit?.syncUp
|
|
else { return .none }
|
|
state.syncUp = editedSyncUp
|
|
state.destination = nil
|
|
return .none
|
|
|
|
case .editButtonTapped:
|
|
state.editSyncUp = SyncUpForm.State(syncUp: state.syncUp)
|
|
return .none
|
|
}
|
|
}
|
|
.ifLet(\.$destination, action: \.destination)
|
|
}
|
|
}
|
|
extension SyncUpDetail.Destination.State: Equatable {}
|
|
|
|
extension AlertState where Action == SyncUpDetail.Action.Alert {
|
|
static let deleteSyncUp = Self {
|
|
TextState("Delete?")
|
|
} actions: {
|
|
ButtonState(role: .destructive, action: .confirmButtonTapped) {
|
|
TextState("Yes")
|
|
}
|
|
ButtonState(role: .cancel) {
|
|
TextState("Nevermind")
|
|
}
|
|
} message: {
|
|
TextState("Are you sure you want to delete this meeting?")
|
|
}
|
|
}
|
|
|
|
struct SyncUpDetailView: View {
|
|
// ...
|
|
}
|