mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-20 09:11:33 +01:00
* Fixes for TestingSyncUpForm * Typo, heirarchy -> hierarchy * Typo: recursive -> recursively * Typo: comes -> combines * Further fixes for TestingSyncUpForm * Typo: is -> to be * Typo: add -> we added * Typo: 3 -> 2 * Adding a note to avoid confusion * Add more detail to step * Remove stray whitespace causing a diff to incorrectly display * Removed step documentation for unused code * Typo: apart -> a part * Fix App.Path Equatable conformance * App -> AppReducer to avoid conflict with SwiftUI.App * Fix code file link * Typo: reducer -> reducers * Add missing mock * AppReducer -> AppFeature * Standardize tutorial on `@Shared(.syncUps)` * Fix mainactor placement * Fix transcript param not compiling * Add durationPerAttendee to be usable * Add a minimal dismiss override to fit with the docs * Fix commenting out of Tagged discussion * Fix commenting out of TestingSyncUpDetail discussion * Undo a whitespace change * Partial revert of TestingSyncUpForm-02-code-0004.swift * Undo unintentionally committed code * Revert "Add missing mock" This reverts commit9672ecbd20. * Revert "Fixes for TestingSyncUpForm" This reverts commit5bece14c2a. * wip --------- Co-authored-by: Stephen Celis <stephen@stephencelis.com>
63 lines
1.5 KiB
Swift
63 lines
1.5 KiB
Swift
import ComposableArchitecture
|
|
import SwiftUI
|
|
|
|
@Reducer
|
|
struct SyncUpsList {
|
|
@ObservableState
|
|
struct State: Equatable {
|
|
@Presents var addSyncUp: SyncUpForm.State?
|
|
@Shared(.syncUps) var syncUps
|
|
}
|
|
enum Action {
|
|
case addSyncUpButtonTapped
|
|
case addSyncUp(PresentationAction<SyncUpForm.Action>)
|
|
case confirmAddButtonTapped
|
|
case discardButtonTapped
|
|
case onDelete(IndexSet)
|
|
case syncUpTapped(id: SyncUp.ID)
|
|
}
|
|
var body: some ReducerOf<Self> {
|
|
Reduce { state, action in
|
|
switch action {
|
|
case .addSyncUpButtonTapped:
|
|
state.addSyncUp = SyncUpForm.State(syncUp: SyncUp(id: SyncUp.ID()))
|
|
return .none
|
|
|
|
case .addSyncUp:
|
|
return .none
|
|
|
|
case .confirmAddButtonTapped:
|
|
guard let newSyncUp = state.addSyncUp?.syncUp
|
|
else { return .none }
|
|
state.addSyncUp = nil
|
|
state.syncUps.append(newSyncUp)
|
|
return .none
|
|
|
|
case .discardButtonTapped:
|
|
state.addSyncUp = nil
|
|
return .none
|
|
|
|
case let .onDelete(indexSet):
|
|
state.syncUps.remove(atOffsets: indexSet)
|
|
return .none
|
|
|
|
case .syncUpTapped:
|
|
return .none
|
|
}
|
|
}
|
|
.ifLet(\.$addSyncUp, action: \.addSyncUp) {
|
|
SyncUpForm()
|
|
}
|
|
}
|
|
}
|
|
|
|
extension PersistenceReaderKey
|
|
where Self == PersistenceKeyDefault<FileStorageKey<IdentifiedArrayOf<SyncUp>>> {
|
|
static var syncUps: Self {
|
|
PersistenceKeyDefault(
|
|
.fileStorage(.documentsDirectory.appending(component: "sync-ups.json")),
|
|
[]
|
|
)
|
|
}
|
|
}
|