Move confirmation dialog

This commit is contained in:
Garth Vander Houwen 2023-03-03 22:54:46 -08:00
parent 221314dbc1
commit de10f159a7

View file

@ -181,7 +181,25 @@ struct Connect: View {
}
}.padding([.bottom, .top])
}
}.textCase(nil)
}
.confirmationDialog("Connecting to a new radio will clear all local app data on the phone.", isPresented: $presentingSwitchPreferredPeripheral, titleVisibility: .visible) {
Button("Connect to new radio?", role: .destructive) {
bleManager.stopScanning()
bleManager.connectedPeripheral = nil
userSettings.preferredPeripheralId = ""
if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected {
bleManager.disconnectPeripheral()
}
clearCoreDataDatabase(context: context)
let radio = bleManager.peripherals.first(where: { $0.peripheral.identifier.uuidString == selectedPeripherialId} )
bleManager.connectTo(peripheral: radio!.peripheral)
presentingSwitchPreferredPeripheral = false
selectedPeripherialId = ""
}
}
.textCase(nil)
}
} else {
@ -190,23 +208,6 @@ struct Connect: View {
.font(.title)
}
}
.confirmationDialog("Connecting to a new radio will clear all local app data on the phone.", isPresented: $presentingSwitchPreferredPeripheral, titleVisibility: .visible) {
Button("Connect to new radio?", role: .destructive) {
bleManager.stopScanning()
bleManager.connectedPeripheral = nil
userSettings.preferredPeripheralId = ""
if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected {
bleManager.disconnectPeripheral()
}
clearCoreDataDatabase(context: context)
let radio = bleManager.peripherals.first(where: { $0.peripheral.identifier.uuidString == selectedPeripherialId} )
bleManager.connectTo(peripheral: radio!.peripheral)
presentingSwitchPreferredPeripheral = false
selectedPeripherialId = ""
}
}
HStack(alignment: .center) {
Spacer()