Fix updating of page commands
This commit is contained in:
@@ -1,18 +1,7 @@
|
||||
import SwiftUI
|
||||
import SFSafeSymbols
|
||||
|
||||
protocol InsertableCommand: View {
|
||||
|
||||
static var title: String { get }
|
||||
|
||||
static var sheetTitle: String { get }
|
||||
|
||||
static var icon: SFSymbol { get }
|
||||
|
||||
init(command: Binding<String?>)
|
||||
}
|
||||
|
||||
struct InsertableCommandSheet<Presented>: View where Presented: InsertableCommand {
|
||||
struct InsertableCommandSheet<Command>: View where Command: InsertableCommandView {
|
||||
|
||||
@Environment(\.dismiss)
|
||||
var dismiss
|
||||
@@ -21,15 +10,19 @@ struct InsertableCommandSheet<Presented>: View where Presented: InsertableComman
|
||||
private var error: String? = nil
|
||||
|
||||
@State
|
||||
private var command: String?
|
||||
private var isReady = false
|
||||
|
||||
init() { }
|
||||
let model: Command.Model
|
||||
|
||||
init() {
|
||||
model = .init()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(Presented.sheetTitle)
|
||||
Text(Command.sheetTitle)
|
||||
.font(.title)
|
||||
Presented(command: $command)
|
||||
Command(model: model)
|
||||
if let error {
|
||||
Text(error)
|
||||
.foregroundStyle(.red)
|
||||
@@ -37,6 +30,7 @@ struct InsertableCommandSheet<Presented>: View where Presented: InsertableComman
|
||||
HStack {
|
||||
Button("Copy to clipboard", action: copyToClipboard)
|
||||
.padding()
|
||||
.disabled(!model.isReady)
|
||||
Button("Cancel") {
|
||||
dismiss()
|
||||
}.padding()
|
||||
@@ -46,7 +40,7 @@ struct InsertableCommandSheet<Presented>: View where Presented: InsertableComman
|
||||
}
|
||||
|
||||
func copyToClipboard() {
|
||||
guard let command else {
|
||||
guard let command = model.command else {
|
||||
error = "Not all fields set"
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user