jellyflood/Swiftfin/Views/ItemEditorView/EditItemElementView/Components/EditItemElementRow.swift
Joe Kribs 548d35b19e
[tvOS] Media Item Menu - Refresh / Delete Items (#1348)
* Mirror tvOS to iOS

* Fix router dismiss. Remove redundent viewModel.refresh from itemView

* reset dev team info

* View Modifier and ViewModel cleanup

* Remove testing comments / events

* Cleanup `.errorMessage($error)`

* Cleanup all viewModel.states for item editing, add errorViews if the data fails to load, and add errorMessage on failed events.

MARK sections: Var/Func always unless only Body and Var/Lets only if there are several of varying types / functions.
2024-12-10 13:37:22 -07:00

114 lines
3.2 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) 2024 Jellyfin & Jellyfin Contributors
//
import Defaults
import JellyfinAPI
import SwiftUI
extension EditItemElementView {
struct EditItemElementRow: View {
// MARK: - Enviroment Variables
@Environment(\.isEditing)
var isEditing
@Environment(\.isSelected)
var isSelected
// MARK: - Metadata Variables
let item: Element
let type: ItemArrayElements
// MARK: - Row Actions
let onSelect: () -> Void
let onDelete: () -> Void
// MARK: - Body
var body: some View {
ListRow {
if type == .people {
personImage
}
} content: {
rowContent
}
.onSelect(perform: onSelect)
.isSeparatorVisible(false)
.swipeActions {
Button(L10n.delete, systemImage: "trash", action: onDelete)
.tint(.red)
}
}
// MARK: - Row Content
@ViewBuilder
private var rowContent: some View {
HStack {
VStack(alignment: .leading) {
Text(type.getName(for: item))
.foregroundStyle(
isEditing ? (isSelected ? .primary : .secondary) : .primary
)
.font(.headline)
.lineLimit(1)
if type == .people {
let person = (item as! BaseItemPerson)
TextPairView(
leading: person.type ?? .emptyDash,
trailing: person.role ?? .emptyDash
)
.foregroundStyle(
isEditing ? (isSelected ? .primary : .secondary) : .primary,
.secondary
)
.font(.subheadline)
.lineLimit(1)
}
}
if isEditing {
Spacer()
Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(width: 24, height: 24)
.foregroundStyle(isSelected ? Color.accentColor : .secondary)
}
}
}
// MARK: - Person Image
@ViewBuilder
private var personImage: some View {
let person = (item as! BaseItemPerson)
ZStack {
Color.clear
ImageView(person.portraitImageSources(maxWidth: 30))
.failure {
SystemImageContentView(systemName: "person.fill")
}
}
.posterStyle(.portrait)
.posterShadow()
.frame(width: 30, height: 90)
.padding(.horizontal)
}
}
}