Fix updating of page commands

This commit is contained in:
Christoph Hagen
2025-01-27 22:30:27 +01:00
parent e02bfd17d2
commit 89062f153c
7 changed files with 201 additions and 67 deletions

View File

@@ -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
}