Skip to content

Commit

Permalink
Add and use Ranking+RankingSort (#801)
Browse files Browse the repository at this point in the history
- reuse more code
  • Loading branch information
bolsinga committed Jun 8, 2024
1 parent 6d323b9 commit 5af9a0d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
22 changes: 8 additions & 14 deletions Sources/Site/Music/UI/ArtistList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ struct ArtistList: View {
Text("\(artistDigest.showRank.value) Show(s)", bundle: .module)
}

@ViewBuilder private func sectionHeader(for ranking: Ranking) -> some View {
switch sort {
case .alphabetical, .firstSeen:
EmptyView()
case .showCount:
ranking.showsCountView
case .showYearRange:
ranking.yearsCountView
case .associatedRank:
ranking.venuesCountView
}
}

@ViewBuilder private var listElement: some View {
if sort.isAlphabetical {
RankingList(
Expand All @@ -55,7 +42,14 @@ struct ArtistList: View {
showCount(for: $0)
}
},
sectionHeaderView: { sectionHeader(for: $0) })
sectionHeaderView: {
switch sort {
case .associatedRank:
$0.venuesCountView
default:
$0.sectionHeader(for: sort)
}
})
}
}

Expand Down
21 changes: 21 additions & 0 deletions Sources/Site/Music/UI/Ranking+RankingSort.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Ranking+RankingSort.swift
//
//
// Created by Greg Bolsinga on 6/7/24.
//

import SwiftUI

extension Ranking {
@ViewBuilder func sectionHeader(for sort: RankingSort) -> some View {
switch sort {
case .alphabetical, .firstSeen, .associatedRank:
EmptyView()
case .showCount:
showsCountView
case .showYearRange:
yearsCountView
}
}
}
22 changes: 8 additions & 14 deletions Sources/Site/Music/UI/VenueList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ struct VenueList: View {
Text("\(venueDigest.showRank.value) Show(s)", bundle: .module)
}

@ViewBuilder private func sectionHeader(for ranking: Ranking) -> some View {
switch sort {
case .alphabetical, .firstSeen:
EmptyView()
case .showCount:
ranking.showsCountView
case .showYearRange:
ranking.yearsCountView
case .associatedRank:
ranking.artistsCountView
}
}

@ViewBuilder private var listElement: some View {
if sort.isAlphabetical {
RankingList(
Expand All @@ -51,7 +38,14 @@ struct VenueList: View {
items: venueDigests,
rankingMapBuilder: { $0.ranked(by: sort) },
itemContentView: { if sort.isShowYearRange { showCount(for: $0) } },
sectionHeaderView: { sectionHeader(for: $0) })
sectionHeaderView: {
switch sort {
case .associatedRank:
$0.artistsCountView
default:
$0.sectionHeader(for: sort)
}
})
}
}

Expand Down

0 comments on commit 5af9a0d

Please sign in to comment.