Meshtastic-Apple/Meshtastic/Views/Settings/Config/SaveConfigButton.swift
2024-02-21 00:07:17 -07:00

36 lines
915 B
Swift

import SwiftUI
struct SaveConfigButton: View {
@EnvironmentObject var bleManager: BLEManager
@State private var isPresentingSaveConfirm = false
let node: NodeInfoEntity?
@Binding var hasChanges: Bool
let onConfirmation: () -> Void
var body: some View {
Button {
isPresentingSaveConfirm = true
} label: {
Label("save", systemImage: "square.and.arrow.down")
}
.disabled(bleManager.connectedPeripheral == nil || !hasChanges)
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.large)
.padding()
.confirmationDialog(
"are.you.sure",
isPresented: $isPresentingSaveConfirm,
titleVisibility: .visible
) {
let nodeName = node?.user?.longName ?? "unknown".localized
let buttonText = String.localizedStringWithFormat("save.config %@".localized, nodeName)
Button(buttonText) {
onConfirmation()
}
} message: {
Text("config.save.confirm")
}
}
}