Files
lichtkasten/Sources/Lichtkasten/Views/UploadWindow.swift
T

72 lines
3.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import SwiftUI
import LichtkastenCore
/// ⌘U – PM "Upload Photos" dialog for the selected images.
struct UploadWindow: View {
@EnvironmentObject var state: AppState
@Environment(\.dismissWindow) private var dismissWindow
@AppStorage("lastUploadTarget") private var target = ""
private var destination: FTPDestination? { state.settings.ftpDestinations.first { $0.id.uuidString == target } }
private var variant: UploadVariant {
target == "immich" ? state.settings.immich.variant : destination?.variant ?? .jpeg
}
private var files: [URL] { state.selectedItems.flatMap { state.uploadFiles(for: $0, variant: variant) } }
var body: some View {
VStack(alignment: .leading, spacing: 14) {
Text("Bilder hochladen").font(.title3.bold())
Form {
Picker("Ziel", selection: $target) {
Text("– bitte wählen –").tag("")
ForEach(state.settings.ftpDestinations) { d in Text(d.name).tag(d.id.uuidString) }
if state.settings.immich.enabled { Text("Immich").tag("immich") }
}
if let d = destination {
LabeledContent("Server", value: "\(d.proto.rawValue) · \(d.host):\(d.port)")
if let i = state.settings.ftpDestinations.firstIndex(where: { $0.id == d.id }) {
TextField("Zielordner", text: $state.settings.ftpDestinations[i].remoteDirectory)
TextField("Umbenennen (leer = Originalname)", text: $state.settings.ftpDestinations[i].renamePattern)
Picker("Dateien", selection: $state.settings.ftpDestinations[i].variant) {
ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}
}
if d.username.isEmpty || Keychain.get(d.keychainAccount) == nil {
Label("Benutzer/Passwort fehlen – Einstellungen → FTP", systemImage: "exclamationmark.triangle.fill")
.foregroundStyle(.orange)
}
} else if target == "immich" {
LabeledContent("Server", value: state.settings.immich.serverURL)
LabeledContent("Album", value: state.settings.immich.albumName.isEmpty ? "–" : state.settings.immich.albumName)
}
LabeledContent("Auswahl", value: "\(state.selectedItems.count) Bild(er) → \(files.count) Datei(en)")
if files.count < state.selectedItems.count {
Text("Einige Bilder haben kein JPEG – zuerst in Lightroom exportieren (⌘⌥L).")
.font(.caption).foregroundStyle(.orange)
}
}
.formStyle(.grouped)
HStack {
SettingsLink { Text("Server verwalten …") }
Spacer()
Button("Abbrechen") { dismissWindow(id: "upload") }.keyboardShortcut(.cancelAction)
Button("Hochladen") {
state.upload(to: target)
state.openWindow("tasks")
dismissWindow(id: "upload")
}
.keyboardShortcut(.defaultAction)
.buttonStyle(.borderedProminent)
.disabled(target.isEmpty || files.isEmpty)
}
}
.padding(18)
.frame(width: 560)
.onAppear {
if target.isEmpty, let first = state.settings.ftpDestinations.first { target = first.id.uuidString }
}
}
}