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
100 lines
2.3 KiB
Swift
100 lines
2.3 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 alert(PresentationAction<Alert>)
|
|
case cancelEditButtonTapped
|
|
case deleteButtonTapped
|
|
case destination(PresentationAction<Destination.Action>)
|
|
case doneEditingButtonTapped
|
|
case editButtonTapped
|
|
// case editSyncUp(PresentationAction<SyncUpForm.Action>)
|
|
// enum Alert {
|
|
// case confirmButtonTapped
|
|
// }
|
|
}
|
|
|
|
@Dependency(\.dismiss) var dismiss
|
|
|
|
var body: some ReducerOf<Self> {
|
|
Reduce { state, action in
|
|
switch action {
|
|
case .alert(.presented(.confirmButtonTapped)):
|
|
@Shared(.fileStorage(.syncUps)) var syncUps: IdentifiedArrayOf<SyncUp> = []
|
|
syncUps.remove(id: state.syncUp.id)
|
|
return .run { _ in await dismiss() }
|
|
|
|
case .alert(.dismiss):
|
|
return .none
|
|
|
|
case .cancelEditButtonTapped:
|
|
state.editSyncUp = nil
|
|
return .none
|
|
|
|
case .delegate:
|
|
return .none
|
|
|
|
case .deleteButtonTapped:
|
|
state.alert = .deleteSyncUp
|
|
return .none
|
|
|
|
case .doneEditingButtonTapped:
|
|
guard let editedSyncUp = state.editSyncUp?.syncUp
|
|
else { return .none }
|
|
state.syncUp = editedSyncUp
|
|
state.editSyncUp = nil
|
|
return .none
|
|
|
|
case .editButtonTapped:
|
|
state.editSyncUp = SyncUpForm.State(syncUp: state.syncUp)
|
|
return .none
|
|
|
|
case .editSyncUp:
|
|
return .none
|
|
}
|
|
}
|
|
.ifLet(\.$editSyncUp, action: \.editSyncUp) {
|
|
SyncUpForm()
|
|
}
|
|
.ifLet(\.$alert, action: \.alert)
|
|
}
|
|
}
|
|
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 {
|
|
// ...
|
|
}
|