diff --git a/AppleNugs/App/AppModel.swift b/AppleNugs/App/AppModel.swift index 44d9f43..6a92478 100644 --- a/AppleNugs/App/AppModel.swift +++ b/AppleNugs/App/AppModel.swift @@ -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.. some View { @@ -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 { diff --git a/AppleNugs/Views/HomeView.swift b/AppleNugs/Views/HomeView.swift index b1311a1..fcb15ee 100644 --- a/AppleNugs/Views/HomeView.swift +++ b/AppleNugs/Views/HomeView.swift @@ -225,11 +225,6 @@ 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) } @@ -237,35 +232,11 @@ struct HomeView: View { } #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) } @@ -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