Skip to content

Commit

Permalink
add associatedRankSectionHeader closure (#802)
Browse files Browse the repository at this point in the history
- this makes ArtistList and VenueList nearly identical.
  • Loading branch information
bolsinga committed Jun 8, 2024
1 parent 5af9a0d commit ff28b32
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Sources/Site/Music/UI/ArchiveCategoryDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct ArchiveCategoryDetail: View {
venueDigests: venueDigests, sectioner: vault.sectioner,
title: String(localized: "Venues", bundle: .module),
associatedRankName: String(localized: "Sort By Artist Count", bundle: .module),
associatedRankSectionHeader: { $0.artistsCountView },
sort: $venueSort
)
.archiveSearchable(
Expand All @@ -57,6 +58,7 @@ struct ArchiveCategoryDetail: View {
artistDigests: artistDigests, sectioner: vault.sectioner,
title: String(localized: "Artists", bundle: .module),
associatedRankName: String(localized: "Sort By Venue Count", bundle: .module),
associatedRankSectionHeader: { $0.venuesCountView },
sort: $artistSort
)
.archiveSearchable(
Expand Down
8 changes: 5 additions & 3 deletions Sources/Site/Music/UI/ArtistList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import SwiftUI

struct ArtistList: View {
struct ArtistList<SectionHeaderContent: View>: View {
let artistDigests: [ArtistDigest]
let sectioner: LibrarySectioner
let title: String
let associatedRankName: String
@ViewBuilder let associatedRankSectionHeader: (Ranking) -> SectionHeaderContent

@Binding var sort: RankingSort

Expand Down Expand Up @@ -45,7 +46,7 @@ struct ArtistList: View {
sectionHeaderView: {
switch sort {
case .associatedRank:
$0.venuesCountView
associatedRankSectionHeader($0)
default:
$0.sectionHeader(for: sort)
}
Expand All @@ -71,7 +72,8 @@ struct ArtistList: View {
NavigationStack {
ArtistList(
artistDigests: vaultPreviewData.artistDigests, sectioner: vaultPreviewData.sectioner,
title: "Artists", associatedRankName: "Sort By Venue Count", sort: .constant(.alphabetical)
title: "Artists", associatedRankName: "Sort By Venue Count",
associatedRankSectionHeader: { $0.venuesCountView }, sort: .constant(.alphabetical)
)
.musicDestinations(vaultPreviewData)
}
Expand Down
8 changes: 5 additions & 3 deletions Sources/Site/Music/UI/VenueList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import SwiftUI

struct VenueList: View {
struct VenueList<SectionHeaderContent: View>: View {
let venueDigests: [VenueDigest]
let sectioner: LibrarySectioner
let title: String
let associatedRankName: String
@ViewBuilder let associatedRankSectionHeader: (Ranking) -> SectionHeaderContent

@Binding var sort: RankingSort

Expand Down Expand Up @@ -41,7 +42,7 @@ struct VenueList: View {
sectionHeaderView: {
switch sort {
case .associatedRank:
$0.artistsCountView
associatedRankSectionHeader($0)
default:
$0.sectionHeader(for: sort)
}
Expand All @@ -67,7 +68,8 @@ struct VenueList: View {
NavigationStack {
VenueList(
venueDigests: vaultPreviewData.venueDigests, sectioner: vaultPreviewData.sectioner,
title: "Venues", associatedRankName: "Sort By Artist Count", sort: .constant(.alphabetical)
title: "Venues", associatedRankName: "Sort By Artist Count",
associatedRankSectionHeader: { $0.artistsCountView }, sort: .constant(.alphabetical)
)
.musicDestinations(vaultPreviewData)
}
Expand Down

0 comments on commit ff28b32

Please sign in to comment.