Share Library controls and use native navigation
This commit is contained in:
1 parent
89e81f0eb0
commit
de617ad1d2
4 files changed
+183
-215
No files matched your search
@@ -84,7 +84,6 @@ final class LibraryAlbumsViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
struct LibraryAlbumsView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@EnvironmentObject private var player: PlayerManager
|
||||
@StateObject private var model: LibraryAlbumsViewModel
|
||||
|
||||
@@ -97,15 +96,13 @@ struct LibraryAlbumsView: View {
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
topBar
|
||||
|
||||
Text("Albums")
|
||||
.font(.system(size: 34, weight: .bold))
|
||||
.padding(.top, 22)
|
||||
.padding(.bottom, 18)
|
||||
|
||||
if !model.albums.isEmpty {
|
||||
playbackActions
|
||||
LibraryPlaybackButtons(isLoading: model.isPreparingPlayback) {
|
||||
playSavedAlbums(shuffled: false)
|
||||
} onShuffle: {
|
||||
playSavedAlbums(shuffled: true)
|
||||
}
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
|
||||
@@ -117,7 +114,9 @@ struct LibraryAlbumsView: View {
|
||||
.scrollIndicators(.hidden)
|
||||
.background(Color.black.ignoresSafeArea())
|
||||
.foregroundStyle(.white)
|
||||
.toolbar(.hidden, for: .navigationBar)
|
||||
.navigationTitle("Albums")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.toolbar(.visible, for: .navigationBar)
|
||||
.refreshable { await model.load(forceRefresh: true) }
|
||||
.task { await model.load() }
|
||||
.alert("Couldn't Start Playback", isPresented: Binding(
|
||||
@@ -130,57 +129,6 @@ struct LibraryAlbumsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var topBar: some View {
|
||||
HStack {
|
||||
Button(action: { dismiss() }) {
|
||||
Image(systemName: "chevron.left")
|
||||
.font(.system(size: 20, weight: .medium))
|
||||
.frame(width: 48, height: 48)
|
||||
.background(.ultraThinMaterial, in: Circle())
|
||||
.overlay(Circle().stroke(.white.opacity(0.12), lineWidth: 1))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel("Back to Library")
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 4)
|
||||
}
|
||||
|
||||
private var playbackActions: some View {
|
||||
HStack(spacing: 14) {
|
||||
playbackButton("Play", symbol: "play.fill") {
|
||||
playSavedAlbums(shuffled: false)
|
||||
}
|
||||
playbackButton("Shuffle", symbol: "shuffle") {
|
||||
playSavedAlbums(shuffled: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func playbackButton(
|
||||
_ title: String,
|
||||
symbol: String,
|
||||
action: @escaping () -> Void
|
||||
) -> some View {
|
||||
Button(action: action) {
|
||||
Group {
|
||||
if model.isPreparingPlayback {
|
||||
ProgressView()
|
||||
.tint(.red)
|
||||
} else {
|
||||
Label(title, systemImage: symbol)
|
||||
.font(.system(size: 18, weight: .semibold))
|
||||
.foregroundStyle(.red)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 56)
|
||||
.background(.white.opacity(0.10), in: Capsule())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(model.isPreparingPlayback)
|
||||
}
|
||||
|
||||
private func playSavedAlbums(shuffled: Bool) {
|
||||
Task {
|
||||
do {
|
||||
@@ -198,31 +146,17 @@ struct LibraryAlbumsView: View {
|
||||
|
||||
@ViewBuilder
|
||||
private var content: some View {
|
||||
if model.isLoading && model.albums.isEmpty {
|
||||
ProgressView("Loading your albums…")
|
||||
.tint(.red)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.top, 44)
|
||||
} else if let errorMessage = model.errorMessage, model.albums.isEmpty {
|
||||
ContentUnavailableView {
|
||||
Label("Couldn't Load Albums", systemImage: "wifi.exclamationmark")
|
||||
} description: {
|
||||
Text(errorMessage)
|
||||
} actions: {
|
||||
Button("Try Again") {
|
||||
Task { await model.load(forceRefresh: true) }
|
||||
}
|
||||
.tint(.red)
|
||||
}
|
||||
.padding(.top, 28)
|
||||
} else if model.albums.isEmpty {
|
||||
ContentUnavailableView(
|
||||
"No Saved Albums",
|
||||
systemImage: "square.stack",
|
||||
description: Text("Albums from songs you add to your Library will appear here.")
|
||||
)
|
||||
.padding(.top, 28)
|
||||
} else {
|
||||
LibraryCollectionContent(
|
||||
isLoading: model.isLoading,
|
||||
isEmpty: model.albums.isEmpty,
|
||||
errorMessage: model.errorMessage,
|
||||
loadingMessage: "Loading your albums…",
|
||||
errorTitle: "Couldn't Load Albums",
|
||||
emptyTitle: "No Saved Albums",
|
||||
emptySymbol: "square.stack",
|
||||
emptyDescription: "Albums from songs you add to your Library will appear here.",
|
||||
onRetry: { Task { await model.load(forceRefresh: true) } }
|
||||
) {
|
||||
LazyVGrid(columns: columns, alignment: .leading, spacing: 20) {
|
||||
ForEach(model.albums) { album in
|
||||
NavigationLink {
|
||||
|
||||
Reference in new issue
Block a user