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
17 changes: 16 additions & 1 deletion AppleNugs/App/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ final class AppModel {
/// Every artist's photo, by id — the Artists list's, fetched once per
/// session (8 pages). Cleared with `cachedArtists`.
private var cachedArtistAvatars: [String: URL]?
/// Photos fetched a few at a time (Home's crate, artist pages) before the
/// full walk, so going back and forth between artists asks once each.
private var knownArtistAvatars: [String: URL] = [:]

/// Fully loaded artist catalogs (shows/releases, and videos), reused for
/// `ArtistCatalogPaging.cacheTTL` so revisiting an artist page makes no
Expand Down Expand Up @@ -169,6 +172,7 @@ final class AppModel {
discardOfflineLibrary()
cachedArtists = nil
cachedArtistAvatars = nil
knownArtistAvatars.removeAll()
artistShowsCache.removeAll()
artistVideosCache.removeAll()
sessionState = .loggedOut
Expand Down Expand Up @@ -219,7 +223,18 @@ final class AppModel {
if let cachedArtistAvatars {
return cachedArtistAvatars.filter { ids.contains($0.key) }
}
return try await client.artistAvatars(ids: ids)
let missing = ids.filter { knownArtistAvatars[$0] == nil }
if !missing.isEmpty {
let fetched = try await client.artistAvatars(ids: missing)
knownArtistAvatars.merge(fetched) { _, new in new }
}
return knownArtistAvatars.filter { ids.contains($0.key) }
}

/// One artist's photo (the artist page's header), or nil — never throws:
/// a missing photo is the monogram, not an error.
func artistAvatar(id: String) async -> URL? {
(try? await artistAvatars(ids: [id]))?[id]
}

/// Every artist's photo, by id, cached for the session. Empty on a
Expand Down
53 changes: 37 additions & 16 deletions AppleNugs/Views/ArtistLibrary/CrateHeader.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import SwiftUI

/// The artist page header: the artist's name as a large title, the counts under
/// it as plain type, and Follow as a frost-outlined button. No LCD pill and no
/// The artist page header: the artist's photo in a circle (as in the Artists
/// list and Home's crate), and beside it the name as a large title, the counts
/// as plain type, and Follow as a frost-outlined button. No LCD pill and no
/// bars (the stage-c row-sticker table: this site gets nothing).
struct CrateHeader: View {
let artist: ArtistEntry
Expand All @@ -12,23 +13,43 @@ struct CrateHeader: View {
@Environment(AppModel.self) private var app
@Environment(\.theme) private var theme

/// The surfaces sheet's artist page: `.large-title`, then `.crate-head`
/// (counts left, Follow right). The counts row is as tall as the 30pt
/// button whether or not any counts have arrived, so paging in the
/// catalog never moves the list below it.
/// The artist's photo, once its lookup lands (the monogram until then,
/// and for good on a miss).
@State private var portraitURL: URL?

/// Big enough to read as the page's subject; the column beside it keeps
/// the name, counts and Follow, so the header stands about this tall.
private static let portraitSide: CGFloat = 88

/// The photo, then a column: the surfaces sheet's `.large-title`, the
/// counts, and Follow under them (beside a photo there's no room on a phone
/// for the sheet's counts-left / Follow-right row). The counts line always
/// holds one line's height whether or not any counts have arrived, so
/// paging in the catalog never moves the list below it.
var body: some View {
VStack(alignment: .leading, spacing: 4) {
Text(artist.name)
.font(theme.type.hero(34))
.foregroundStyle(theme.palette.textPrimary)
.lineLimit(2)
.minimumScaleFactor(0.7)
.accessibilityAddTraits(.isHeader)
HStack(spacing: 12) {
countsLine
.frame(maxWidth: .infinity, alignment: .leading)
HStack(alignment: .center, spacing: 16) {
ArtistPortrait(url: portraitURL, name: artist.name)
.frame(width: Self.portraitSide, height: Self.portraitSide)
VStack(alignment: .leading, spacing: 4) {
Text(artist.name)
.font(theme.type.hero(34))
.foregroundStyle(theme.palette.textPrimary)
.lineLimit(2)
.minimumScaleFactor(0.7)
.accessibilityAddTraits(.isHeader)
ZStack(alignment: .leading) {
// Holds the line's height before any counts arrive.
Text(verbatim: " ").font(theme.type.body(14)).hidden()
countsLine
}
followButton
.padding(.top, 4)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.task(id: artist.id) {
portraitURL = nil
portraitURL = await app.artistAvatar(id: artist.id)
}
}

Expand Down
Loading