Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AppleNugs/App/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ final class AppModel {
return cachedArtistAvatars.filter { ids.contains($0.key) }
}
let missing = ids.filter { knownArtistAvatars[$0] == nil }
if !missing.isEmpty {
let fetched = try await client.artistAvatars(ids: missing)
// `?ids=` answers at most a page (100); a long follow list goes in batches.
for start in stride(from: 0, to: missing.count, by: Catalog.artistPageSize) {
let batch = Array(missing[start..<min(start + Catalog.artistPageSize, missing.count)])
let fetched = try await client.artistAvatars(ids: batch)
knownArtistAvatars.merge(fetched) { _, new in new }
}
return knownArtistAvatars.filter { ids.contains($0.key) }
Expand Down
44 changes: 44 additions & 0 deletions AppleNugs/Theme/Components/ArtistTile.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import SwiftUI

/// An artist as a tile: the photo in a circle (Apple Music's shape for an
/// artist, so it reads apart from square show covers), the name centered below,
/// on a raised shelf. Home's crate (iOS) and the Favorites page use it.
///
/// Names are never cut off for ~98% of the catalog: up to three lines,
/// shrinking to 85% before truncating (median name 14 characters, 1 in 10 past
/// 27, the longest 62). Two lines are always reserved, and the tile stretches
/// to its row, so a row of short and long names lines up.
struct ArtistTile: View {
@Environment(\.theme) private var theme

let name: String
/// The photo (`Catalog.artistAvatars`); nil shows the monogram.
let photo: URL?

/// Grid columns that seat these tiles: three across a portrait phone,
/// five across the flat Duo's Home column.
static let column = GridItem.Size.adaptive(minimum: 92, maximum: 132)
static let spacing: CGFloat = 10

var body: some View {
let shape = RoundedRectangle(cornerRadius: 10, style: .continuous)
VStack(spacing: 8) {
ArtistPortrait(url: photo, name: name)
ZStack(alignment: .top) {
// Holds two lines' height at the current Dynamic Type size.
Text(" ").lineLimit(2, reservesSpace: true).hidden()
Text(name)
.foregroundStyle(theme.palette.textPrimary)
.multilineTextAlignment(.center)
.lineLimit(3)
.minimumScaleFactor(0.85)
}
.font(theme.type.body(13))
}
.padding(.horizontal, 8)
.padding(.vertical, 10)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.background { shape.fill(theme.palette.raised) }
.contentShape(shape)
}
}
40 changes: 17 additions & 23 deletions AppleNugs/Views/FavoritesView.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import SwiftUI

/// The Favorites destination: followed artists as text chips, then saved shows
/// as a cover-art grid (newest saved first). Stacked sections, fully themed.
/// The Favorites destination: followed artists as photo tiles (`ArtistTile`, as
/// on Home's crate), then saved shows as a cover-art grid (newest saved first).
/// Stacked sections, fully themed.
struct FavoritesView: View {
@Environment(AppModel.self) private var app
@Environment(\.theme) private var theme

private var favorites: FavoritesStore { app.favorites }

/// Followed artists' photos, by id. Empty until the lookup lands (and for
/// good if it fails) — tiles show the monogram meanwhile.
@State private var avatars: [String: URL] = [:]

var body: some View {
ScrollView {
if favorites.isEmpty {
Expand All @@ -25,6 +30,13 @@ struct FavoritesView: View {
}
.background(theme.palette.base)
.navigationTitle("Favorites")
// Re-asks only when the followed set changes; known photos are
// remembered on AppModel, so a follow adds one lookup, not a refetch.
.task(id: favorites.artists.map(\.id)) {
let ids = favorites.artists.map(\.id)
guard !ids.isEmpty else { return }
avatars = (try? await app.artistAvatars(ids: ids)) ?? avatars
}
}

private func sectionTitle(_ text: String) -> some View {
Expand All @@ -36,29 +48,11 @@ struct FavoritesView: View {
private var artistsSection: some View {
VStack(alignment: .leading, spacing: 12) {
sectionTitle("Artists")
LazyVGrid(columns: [GridItem(.adaptive(minimum: 150, maximum: 240), spacing: 10)],
alignment: .leading, spacing: 10) {
LazyVGrid(columns: [GridItem(ArtistTile.column, spacing: ArtistTile.spacing)],
alignment: .leading, spacing: ArtistTile.spacing) {
ForEach(favorites.artists) { fav in
NavigationLink(value: Route.artist(ArtistEntry(id: fav.id, name: fav.name))) {
HStack {
Text(fav.name)
.font(theme.type.body(13))
.foregroundStyle(theme.palette.textPrimary)
.lineLimit(1)
Spacer(minLength: 0)
}
.padding(.horizontal, 12)
.padding(.vertical, 9)
.background {
RoundedRectangle(cornerRadius: 9, style: .continuous)
.fill(theme.palette.raised)
}
// Chips on the shelf with a frost keyline, as on Home.
.overlay {
RoundedRectangle(cornerRadius: 9, style: .continuous)
.strokeBorder(theme.palette.hairline, lineWidth: 1)
}
.contentShape(RoundedRectangle(cornerRadius: 9, style: .continuous))
ArtistTile(name: fav.name, photo: avatars[fav.id])
}
.buttonStyle(.plain)
.contextMenu {
Expand Down
42 changes: 9 additions & 33 deletions AppleNugs/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,47 +225,18 @@ struct HomeView: View {
ForEach(sample) { artist in
NavigationLink(value: Route.artist(artist)) {
crateCell(artist)
.background {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(theme.palette.raised)
}
.contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
}
.buttonStyle(.plain)
}
}
}

#if os(iOS)
private var crateColumn: GridItem.Size { .adaptive(minimum: 92, maximum: 132) }
private var crateSpacing: CGFloat { 10 }

/// The artist's photo in a circle (Apple Music's shape for an artist, so it
/// reads apart from the square show covers in Favorites above), the name
/// centered below.
///
/// Names are never cut off for ~98% of the catalog: up to three lines,
/// shrinking to 85% before truncating (median name 14 characters, 1 in 10
/// past 27, the longest 62). Two lines are always reserved, and the tile
/// stretches to its row, so a row of short and long names lines up.
private var crateColumn: GridItem.Size { ArtistTile.column }
private var crateSpacing: CGFloat { ArtistTile.spacing }

private func crateCell(_ artist: ArtistEntry) -> some View {
VStack(spacing: 8) {
ArtistPortrait(url: avatars[artist.id], name: artist.name)
ZStack(alignment: .top) {
// Holds two lines' height at the current Dynamic Type size.
Text(" ").lineLimit(2, reservesSpace: true).hidden()
Text(artist.name)
.foregroundStyle(theme.palette.textPrimary)
.multilineTextAlignment(.center)
.lineLimit(3)
.minimumScaleFactor(0.85)
}
.font(theme.type.body(13))
}
.padding(.horizontal, 8)
.padding(.top, 10)
.padding(.bottom, 10)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
ArtistTile(name: artist.name, photo: avatars[artist.id])
}
#else
private var crateColumn: GridItem.Size { .adaptive(minimum: 200, maximum: 280) }
Expand All @@ -283,6 +254,11 @@ struct HomeView: View {
Spacer(minLength: 0)
}
.padding(8)
.background {
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(theme.palette.raised)
}
.contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
}
#endif

Expand Down
Loading