Skip to content

Commit

Permalink
Use new navigation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
yalishanda42 committed Aug 28, 2023
1 parent db97884 commit bcb817b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ public struct SearchStationReducer: Reducer {
public var query: String
public var locationStatus: LocationStatus

// Child screen
public var stationState: StationReducer.State?
@PresentationState
public var stationDetailsState: StationReducer.State?

public init(
filteredStations: [BGStation] = BGStation.allCases,
favoriteStations: [BGStation] = [],
query: String = "",
locationStatus: LocationStatus = .unableToUseLocation,
selectedStation: StationReducer.State? = nil
stationDetailsState: StationReducer.State? = nil
) {
self.filteredStations = filteredStations
self.favoriteStations = favoriteStations
self.query = query
self.locationStatus = locationStatus
self.stationState = selectedStation
self.stationDetailsState = stationDetailsState
}

public var isSearching: Bool {
Expand Down Expand Up @@ -75,7 +75,7 @@ public struct SearchStationReducer: Reducer {
case task

/// Child screen action
case stationAction(StationReducer.Action)
case stationAction(PresentationAction<StationReducer.Action>)
}

@Dependency(\.locationService) var locationService
Expand Down Expand Up @@ -123,16 +123,16 @@ public struct SearchStationReducer: Reducer {

case .selectStation(let station):
guard let new = station else {
return .send(.stationAction(.finalize))
return .send(.stationAction(.presented(.finalize)))
}

guard new != state.stationState?.station else {
guard new != state.stationDetailsState?.station else {
// the station is already selected
return .none
}

state.stationState = .init(station: new)
return .send(.stationAction(.refresh))
state.stationDetailsState = .init(station: new)
return .send(.stationAction(.presented(.refresh)))

case .loadSavedStations(let statons):
state.favoriteStations = statons
Expand Down Expand Up @@ -183,13 +183,13 @@ public struct SearchStationReducer: Reducer {

case .stationAction(let childAction):
// Child screen
if case .finalize = childAction {
state.stationState = nil
if case .presented(.finalize) = childAction {
state.stationDetailsState = nil
}

return .none
}
}.ifLet(\.stationState, action: /Action.stationAction) {
}.ifLet(\.$stationDetailsState, action: /Action.stationAction) {
StationReducer()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public struct SearchStationView: View {
NavigationSplitView {
MasterView(vs: vs)
} detail: {
if let selected = vs.stationState {
if let selected = vs.stationDetailsState {
StationView(store: store.scope(
state: { _ in selected },
action: SearchStationReducer.Action.stationAction
action: { .stationAction(.presented($0)) }
))
} else {
Text("Изберете гара, за която да се покаже информация за спиращите и тръгващите влакове в следващите 6 часа.")
Expand All @@ -53,7 +53,7 @@ private struct MasterView: View {

var body: some View {
List(selection: Binding<BGStation?>(
get: { vs.stationState?.station },
get: { vs.stationDetailsState?.station },
set: { vs.send(.selectStation($0)) }
)) {
if vs.locationStatus != .unableToUseLocation
Expand Down

0 comments on commit bcb817b

Please sign in to comment.