-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
EditingAndDeletingSyncUp-02-code-0003.swift
59 lines (51 loc) · 1.29 KB
/
EditingAndDeletingSyncUp-02-code-0003.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import ComposableArchitecture
import SwiftUI
@Reducer
struct SyncUpDetail {
@ObservableState
struct State: Equatable {
@Presents var alert: AlertState<Action.Alert>?
@Presents var editSyncUp: SyncUpForm.State?
@Shared var syncUp: SyncUp
}
enum Action {
case alert(PresentationAction<Alert>)
case cancelEditButtonTapped
case deleteButtonTapped
case doneEditingButtonTapped
case editButtonTapped
case editSyncUp(PresentationAction<SyncUpForm.Action>)
@CasePathable
enum Alert {
case confirmButtonTapped
}
}
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .cancelEditButtonTapped:
state.editSyncUp = nil
return .none
case .deleteButtonTapped:
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()
}
}
}
struct SyncUpDetailView: View {
// ...
}