Slide 10
Slide 10 text
ཤྺػೳɿཤྺը໘
public struct TextHistoryView: View {
@Environment(\.histories) var histories: [History]?
@Environment(\.deleteHistory) var deleteHistory: DeleteHistoryAction
public var body: some View {
if let histories {
contents(of: histories)
} else {
Text("Loading...")
}
}
@ViewBuilder
private func contents(of histories: [History]) -> some View {
if histories.isEmpty {
Text("No history available.")
} else {
NavigationSplitView {
List {
historyList(of: histories)
}
.navigationBarTitle("History")
.animation(.default, value: histories)
} detail: {
Text("Select a history.")
}
}
}
private func historyList(of histories: [History]) -> some View {
ForEach(histories, id: \.self) { text in
NavigationLink(text) {
QRCodeImageView(
content: text,
shouldAddContentToHistory: false
)
}
.swipeActions(edge: .trailing) {
Button(role: .destructive) {
Task {
await deleteHistory(of: text)
}
} label: {
Label("Delete", systemImage: "trash")
}
}
}
}
}