Skip to content

Commit

Permalink
use default value for SharedKey.Default extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mltbnz committed Jan 22, 2025
1 parent 3e89715 commit 1874d80
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 36 deletions.
9 changes: 3 additions & 6 deletions CriticalMapsKit/Sources/AppFeature/AppFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ public struct AppFeature {

public var chatMessageBadgeCount: UInt = 0

@Shared(.userSettings)
var userSettings = UserSettings()
@Shared(.rideEventSettings)
var rideEventSettings = RideEventSettings()
@Shared(.appearanceSettings)
var appearanceSettings = AppearanceSettings()
@Shared(.userSettings) var userSettings
@Shared(.rideEventSettings) var rideEventSettings
@Shared(.appearanceSettings) var appearanceSettings

public init(
locationsAndChatMessages: TaskResult<[Rider]>? = nil,
Expand Down
5 changes: 2 additions & 3 deletions CriticalMapsKit/Sources/AppFeature/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SwiftUI
public struct AppView: View {
@State private var showsInfoExpanded = false
@State private var store: StoreOf<AppFeature>
@State private var showOfflineBanner = false

@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
Expand Down Expand Up @@ -56,8 +55,8 @@ public struct AppView: View {
if store.hasOfflineError {
offlineBanner()
.clipShape(Circle())
.opacity(showOfflineBanner ? 1 : 0)
.accessibleAnimation(.easeInOut(duration: 0.2), value: showOfflineBanner)
.opacity(store.hasOfflineError ? 1 : 0)
.accessibleAnimation(.easeInOut(duration: 0.2), value: store.hasOfflineError)
}
}
.padding(.top, .grid(1))
Expand Down
5 changes: 2 additions & 3 deletions CriticalMapsKit/Sources/MapFeature/MapFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public struct MapFeature {
public var isNextRideBannerVisible = false
public var isNextRideBannerExpanded = false

@Shared(.userSettings)
var userSettings = UserSettings()
@Shared(.userSettings) var userSettings

public init(
alert: AlertState<Action>? = nil,
Expand Down Expand Up @@ -186,7 +185,7 @@ public struct MapFeature {
await send(.setAlert(.goToSettingsAlert))

case .authorizedAlways, .authorizedWhenInUse:
@Shared(.userSettings) var userSettings = UserSettings()
@Shared(.userSettings) var userSettings
guard !userSettings.isObservationModeEnabled else {
return
}
Expand Down
6 changes: 2 additions & 4 deletions CriticalMapsKit/Sources/NextRideFeature/NextRideFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public struct NextRideFeature {
public var nextRide: Ride?
public var rideEvents: [Ride] = []

@Shared(.userSettings)
public var userSettings = UserSettings()
@Shared(.rideEventSettings)
var rideEventSettings = RideEventSettings()
@Shared(.userSettings) var userSettings
@Shared(.rideEventSettings) var rideEventSettings

public var userLocation: Coordinate?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public struct AppearanceSettingsFeature {

@ObservableState
public struct State: Equatable {
@Shared(.appearanceSettings)
var settings = AppearanceSettings()
@Shared(.appearanceSettings) var settings

public var appIcon: AppIcon
public var colorScheme: AppearanceSettings.ColorScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public struct RideEventsSettingsFeature {

@ObservableState
public struct State: Equatable {
@Shared(.rideEventSettings)
var settings = RideEventSettings()
@Shared(.rideEventSettings) var settings

public var isEnabled: Bool
public var eventSearchRadius: EventDistance
Expand Down
9 changes: 3 additions & 6 deletions CriticalMapsKit/Sources/SettingsFeature/SettingsFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ public struct SettingsFeature {

@ObservableState
public struct State: Equatable {
@Shared(.userSettings)
public var userSettings = UserSettings()
@Shared(.rideEventSettings)
public var rideEventSettings = RideEventSettings()
@Shared(.appearanceSettings)
public var appearanceSettings = AppearanceSettings()
@Shared(.userSettings) public var userSettings
@Shared(.rideEventSettings) public var rideEventSettings
@Shared(.appearanceSettings) public var appearanceSettings

@Presents
var destination: Destination.State?
Expand Down
6 changes: 2 additions & 4 deletions CriticalMapsKit/Sources/SharedModels/AppearanceSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ private extension URL {
}
}

public extension SharedKey
where Self == Sharing.FileStorageKey<AppearanceSettings>
{
public extension SharedKey where Self == FileStorageKey<AppearanceSettings>.Default {
static var appearanceSettings: Self {
fileStorage(.appearanceSettingsURL)
Self[.fileStorage(.appearanceSettingsURL), default: AppearanceSettings()]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ private extension URL {
}
}

public extension SharedKey where Self == Sharing.FileStorageKey<RideEventSettings> {
public extension SharedKey where Self == Sharing.FileStorageKey<RideEventSettings>.Default {
static var rideEventSettings: Self {
fileStorage(.rideEventSettingsURL)
Self[.fileStorage(.rideEventSettingsURL), default: RideEventSettings()]
}
}
6 changes: 2 additions & 4 deletions CriticalMapsKit/Sources/SharedModels/UserSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ private extension URL {
}
}

public extension SharedKey
where Self == Sharing.FileStorageKey<UserSettings>
{
public extension SharedKey where Self == FileStorageKey<UserSettings>.Default {
static var userSettings: Self {
fileStorage(.userSettingsURL)
Self[.fileStorage(.userSettingsURL), default: UserSettings()]
}
}

0 comments on commit 1874d80

Please sign in to comment.