Test alert uses real data: actual cheapest station within radius
The first Settings test button no longer sends a hardcoded placeholder — it runs the same criteria as a live alert (monitored fuel, alert radius, current location) against the loaded stations and sends the REAL station name, brand and price. Result line shown under the button; graceful message when no stations or no sellers within radius.
This commit is contained in:
@@ -3,14 +3,21 @@ import StoreKit
|
||||
import UserNotifications
|
||||
import WidgetKit
|
||||
|
||||
/// Settings tab — distance units, onboarding replay, a tip jar, and a
|
||||
/// test-alert button that previews what a real price notification looks like.
|
||||
/// Settings tab — distance units, onboarding replay, a tip jar, and
|
||||
/// test-alert buttons. The first test button uses REAL data (the actual
|
||||
/// cheapest station for the monitored fuel within the radius, exactly like a
|
||||
/// live alert) via `onTestAlert`; the second fires with no criteria at all.
|
||||
struct SettingsView: View {
|
||||
@Binding var distanceUnit: DistanceUnit
|
||||
/// The fuel + radius currently configured for alerts (mirrors the Alerts
|
||||
/// tab) so the test notification matches what real alerts will say.
|
||||
var alertsFuel: FuelType = .e10
|
||||
var alertsRadiusKM: Double = 3.0
|
||||
/// Result line from the last real-data test alert (what it picked).
|
||||
var testAlertResult: String?
|
||||
/// Drives the real-data test — ContentView routes this to the live
|
||||
/// ProximityMonitor so the test uses its actual stations/fuel/radius.
|
||||
var onTestAlert: () -> Void = {}
|
||||
var onShowOnboarding: () -> Void = {}
|
||||
|
||||
@StateObject private var tipStore = TipStore()
|
||||
@@ -52,13 +59,18 @@ struct SettingsView: View {
|
||||
Button {
|
||||
sendTestAlert()
|
||||
} label: {
|
||||
Label("Test alert notification", systemImage: "bell.badge.fill")
|
||||
Label("Test alert notification (real data)", systemImage: "bell.badge.fill")
|
||||
}
|
||||
if let testAlertMessage {
|
||||
Text(testAlertMessage)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if let testAlertResult {
|
||||
Label(testAlertResult, systemImage: "checkmark.circle.fill")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.green)
|
||||
}
|
||||
Button {
|
||||
ProximityMonitor.sendPlainTestNotification()
|
||||
} label: {
|
||||
@@ -67,7 +79,7 @@ struct SettingsView: View {
|
||||
} header: {
|
||||
Text("Alerts")
|
||||
} footer: {
|
||||
Text("The first button sends a notification shaped like a real price alert for \(alertsFuel.displayName.lowercased()) within \(distanceUnit.format(alertsRadiusKM)). The second fires with no criteria at all — no geofence, no cheapest check — just to verify a notification appears and tapping it opens FuelBoard.")
|
||||
Text("The first button applies the real criteria — cheapest \(alertsFuel.displayName.lowercased()) station within \(distanceUnit.format(alertsRadiusKM)) of you — and sends the actual station's name and price. The second fires with no criteria at all, just to verify a notification appears and tapping it opens FuelBoard.")
|
||||
}
|
||||
|
||||
Section {
|
||||
@@ -110,8 +122,7 @@ struct SettingsView: View {
|
||||
Task { @MainActor in
|
||||
switch settings.authorizationStatus {
|
||||
case .authorized, .provisional, .ephemeral:
|
||||
ProximityMonitor.sendTestNotification(fuel: alertsFuel, radiusKM: alertsRadiusKM)
|
||||
testAlertMessage = "Test alert sent — check your notification centre."
|
||||
onTestAlert()
|
||||
case .denied:
|
||||
testAlertMessage = "Notifications are turned off for FuelBoard. Enable them in Settings → Notifications → FuelBoard, then try again."
|
||||
default:
|
||||
@@ -119,8 +130,7 @@ struct SettingsView: View {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ in
|
||||
Task { @MainActor in
|
||||
if granted {
|
||||
ProximityMonitor.sendTestNotification(fuel: alertsFuel, radiusKM: alertsRadiusKM)
|
||||
testAlertMessage = "Test alert sent — check your notification centre."
|
||||
onTestAlert()
|
||||
} else {
|
||||
testAlertMessage = "Notifications weren't allowed, so no test alert was sent."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user