1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Home/QueueView.swift

71 lines
1.9 KiB
Swift
Raw Normal View History

2022-12-19 04:40:05 +05:30
import SwiftUI
struct QueueView: View {
@State private var expanded = false
@ObservedObject private var player = PlayerModel.shared
var body: some View {
LazyVStack {
if !items.isEmpty {
2022-12-19 06:07:09 +05:30
Button {
withAnimation {
expanded.toggle()
}
} label: {
HStack(spacing: 12) {
2022-12-19 06:07:09 +05:30
sectionLabel(label)
Spacer()
ClearQueueButton()
if items.count > 1 {
Label("Show more", systemImage: expanded ? "chevron.up" : "chevron.down")
.animation(nil, value: expanded)
.foregroundColor(.accentColor)
.imageScale(.large)
.labelStyle(.iconOnly)
}
2022-12-19 04:40:05 +05:30
}
}
2022-12-21 05:01:00 +05:30
.buttonStyle(.plain)
2022-12-19 06:07:09 +05:30
2023-05-25 17:58:29 +05:30
ListView(items: items, limit: limit)
.environment(\.inQueueListing, true)
2022-12-19 04:40:05 +05:30
}
}
2022-12-19 06:07:09 +05:30
.padding(.vertical, items.isEmpty ? 0 : 15)
}
var label: String {
if items.count < 2 {
2023-05-21 22:40:28 +05:30
return "Next in Queue".localized()
2022-12-19 06:07:09 +05:30
}
2023-05-21 22:40:28 +05:30
return "Next in Queue".localized() + " (\(items.count))"
2022-12-19 04:40:05 +05:30
}
2023-05-25 17:58:29 +05:30
var items: [ContentItem] {
player.queue.map(\.contentItem)
2022-12-19 04:40:05 +05:30
}
var limit: Int? {
if !expanded {
return 1
}
return nil
}
func sectionLabel(_ label: String) -> some View {
Text(label.localized())
.font(.title3.bold())
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.secondary)
}
}
struct QueueView_Previews: PreviewProvider {
static var previews: some View {
QueueView()
}
}