93 lines
2.9 KiB
Swift
93 lines
2.9 KiB
Swift
//
|
|
// Swiftfin is subject to the terms of the Mozilla Public
|
|
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
//
|
|
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors
|
|
//
|
|
|
|
import Factory
|
|
import JellyfinAPI
|
|
import SwiftUI
|
|
|
|
// TODO: change URL picker from menu to list with network-url mapping
|
|
|
|
/// - Note: Set the environment `isEditing` to `true` to
|
|
/// allow server deletion
|
|
struct EditServerView: View {
|
|
|
|
@Router
|
|
private var router
|
|
|
|
@Environment(\.isEditing)
|
|
private var isEditing
|
|
|
|
@State
|
|
private var currentServerURL: URL
|
|
@State
|
|
private var isPresentingConfirmDeletion: Bool = false
|
|
|
|
@StateObject
|
|
private var viewModel: ServerConnectionViewModel
|
|
|
|
init(server: ServerState) {
|
|
self._viewModel = StateObject(wrappedValue: ServerConnectionViewModel(server: server))
|
|
self._currentServerURL = State(initialValue: server.currentURL)
|
|
}
|
|
|
|
var body: some View {
|
|
List {
|
|
Section {
|
|
|
|
LabeledContent(
|
|
L10n.name,
|
|
value: viewModel.server.name
|
|
)
|
|
|
|
if let serverVerion = StoredValues[.Server.publicInfo(id: viewModel.server.id)].version {
|
|
LabeledContent(
|
|
L10n.version,
|
|
value: serverVerion
|
|
)
|
|
}
|
|
|
|
Picker(L10n.url, selection: $currentServerURL) {
|
|
ForEach(viewModel.server.urls.sorted(using: \.absoluteString), id: \.self) { url in
|
|
Text(url.absoluteString)
|
|
.tag(url)
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
} footer: {
|
|
if !viewModel.server.isVersionCompatible {
|
|
Label(
|
|
L10n.serverVersionWarning(JellyfinClient.sdkVersion.majorMinor.description),
|
|
systemImage: "exclamationmark.circle.fill"
|
|
)
|
|
.labelStyle(.sectionFooterWithImage(imageStyle: .orange))
|
|
}
|
|
}
|
|
|
|
if isEditing {
|
|
ListRowButton(L10n.delete) {
|
|
isPresentingConfirmDeletion = true
|
|
}
|
|
.foregroundStyle(.red, .red.opacity(0.2))
|
|
}
|
|
}
|
|
.navigationTitle(L10n.server)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.onChange(of: currentServerURL) { newValue in
|
|
viewModel.setCurrentURL(to: newValue)
|
|
}
|
|
.alert(L10n.deleteServer, isPresented: $isPresentingConfirmDeletion) {
|
|
Button(L10n.delete, role: .destructive) {
|
|
viewModel.delete()
|
|
router.dismiss()
|
|
}
|
|
} message: {
|
|
Text(L10n.confirmDeleteServerAndUsers(viewModel.server.name))
|
|
}
|
|
}
|
|
}
|