Skip to content

Commit

Permalink
Move favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
yalishanda42 committed May 14, 2023
1 parent 27a94b2 commit 7642035
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public struct SearchStationReducer: ReducerProtocol {

case loadSavedStations([BGStation])
case toggleSaveStation(BGStation)
case moveFavorite(from: IndexSet, to: Int)

case locationStatusUpdate(LocationStatus)
case askForLocationPersmission
Expand Down Expand Up @@ -141,8 +142,19 @@ public struct SearchStationReducer: ReducerProtocol {
} else {
state.favoriteStations.append(station)
}
return .fireAndForget { [favorites = state.favoriteStations] in
try? await favoritesService.saveFavorites(favorites)

return .run { [favorites = state.favoriteStations] _ in
try await favoritesService.saveFavorites(favorites)
} catch: { [favorites = state.favoriteStations] error, _ in
print(".toggleSaveStation: Coud not save favorites=\(favorites), error=\(error)")
}

case let .moveFavorite(from: from, to: to):
state.favoriteStations.move(fromOffsets: from, toOffset: to)
return .run { [favorites = state.favoriteStations] _ in
try await favoritesService.saveFavorites(favorites)
} catch: { [favorites = state.favoriteStations] error, _ in
print(".moveFavorite: Could not save favorites=\(favorites), error=\(error)")
}

case .askForLocationPersmission:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private struct MasterView: View {
Text(station.name)
.favoritable(station: station, vs: vs)
}
}.onMove { from, to in
vs.send(.moveFavorite(from: from, to: to))
}
} header: {
Text("Запазени")
Expand Down

0 comments on commit 7642035

Please sign in to comment.