Skip to content

Commit

Permalink
changed filter from popup to sheet (bug in macOS 14.1 does not allow …
Browse files Browse the repository at this point in the history
…popups in toolbars anymore)
  • Loading branch information
Andre committed Dec 14, 2023
1 parent 25f0e7a commit 8d0db2d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NIU-Tracks/Models/MainViewSheets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ enum MainViewSheets: Identifiable {
case login
/// Presents a sheet which shows the vehicle picker view
case vehiclePicker
/// Presents a sheet which shows the filter to filter on tracks
case filter

var id: Self { self }
}
3 changes: 2 additions & 1 deletion NIU-Tracks/NIU_TracksApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ struct NIU_TracksApp: App {
Divider()

Button("Filter") {
scooterCoordinator.presentFilter = true
// scooterCoordinator.presentFilter = true
scooterCoordinator.presentedSheet = .filter
}
.keyboardShortcut("F", modifiers: .command)

Expand Down
12 changes: 6 additions & 6 deletions NIU-Tracks/ViewModels/ScooterCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ final class ScooterCoordinator: ObservableObject {
let filterViewModel = FilterViewModel()

/// Indicator, if the filter is currently presented or not
@Published var presentFilter: Bool = false {
didSet {
guard !presentFilter else { return }
readTracksFromDatabase()
}
}
// @Published var presentFilter: Bool = false {
// didSet {
// guard !presentFilter else { return }
// readTracksFromDatabase()
// }
// }

/// The current presented sheet, if there is any
@Published var presentedSheet: MainViewSheets? = (UserDefaults.standard.accessToken?.isEmpty ?? true) ? .login : nil
Expand Down
12 changes: 12 additions & 0 deletions NIU-Tracks/Views/FilterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct FilterView: View {
/// Reference to the view model which drives the view
@ObservedObject var filterViewModel: FilterViewModel

@Environment(\.dismiss) private var dismiss

/// The body
var body: some View {
Form {
Expand Down Expand Up @@ -66,6 +68,16 @@ struct FilterView: View {
Toggle("Maximum riding time", isOn: $filterViewModel.isMaximumRidingTimeActive)
})
}

HStack {
Spacer()
Button(action: {
dismiss()
}, label: {
Text("Ok")
.frame(minWidth: 50)
})
}
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions NIU-Tracks/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@ struct MainView: View {

/// Show filter
Button(action: {
scooterCoordinator.presentFilter = true
scooterCoordinator.presentedSheet = .filter
// scooterCoordinator.presentFilter = true
}, label: {
Label("Filter", systemImage: "slider.horizontal.3")
.foregroundColor(.orange)
.help("Filter")
})
.popover(isPresented: $scooterCoordinator.presentFilter,
attachmentAnchor: .point(.bottom),
arrowEdge: .top) {

FilterView(filterViewModel: scooterCoordinator.filterViewModel)
.padding()
}
// .popover(isPresented: $scooterCoordinator.presentFilter,
// attachmentAnchor: .point(.bottom),
// arrowEdge: .top) {
//
// FilterView(filterViewModel: scooterCoordinator.filterViewModel)
// .padding()
// }

Divider()

Expand Down Expand Up @@ -151,6 +152,13 @@ struct MainView: View {
case .vehiclePicker:
VehiclePickerView()
.frame(minWidth: 600, idealWidth: 600, maxWidth: 600, minHeight: 300, idealHeight: 300, maxHeight: 400, alignment: .center)

case .filter:
FilterView(filterViewModel: scooterCoordinator.filterViewModel)
.padding()
.onDisappear {
scooterCoordinator.readTracksFromDatabase()
}
}
})

Expand Down

0 comments on commit 8d0db2d

Please sign in to comment.