Skip to content

Commit

Permalink
Add Contributors Number to ContributorsListView (#366)
Browse files Browse the repository at this point in the history
* Add contributions count UI

* Improve preview

* Fix formatting

* Passed Contributor object as opposed to 3 parameters and fix formatting

And removed a Task inside a task

* Add comment to Text

* Change button style to plain

To make the button not blue

* Change foregroundstyle to make the link not blue

---------

Co-authored-by: Mikaela Caron <mikaelacaron@gmail.com>
  • Loading branch information
DandyLyons and mikaelacaron authored Oct 29, 2024
1 parent c560f22 commit d364003
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Basic-Car-Maintenance/Shared/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
}
}
},
"^[%lld contributions](inflect: true)" : {
"comment" : "the number of contributions by a contributor"
},
"🦄 Mikaela Caron - Maintainer" : {
"comment" : "Link to maintainer Github account.",
"localizations" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,26 @@ struct ContributorsListView: View {
List {
if !viewModel.sortedContributors.isEmpty {
ForEach(viewModel.sortedContributors) { contributor in
Link(
destination: URL(string: contributor.htmlURL) ??
GitHubURL.repo) {
ContributorsProfileView(name: contributor.login, url: contributor.avatarURL)
}
Link(destination: URL(string: contributor.htmlURL) ?? GitHubURL.repo) {
ContributorsProfileView(contributor: contributor)
}
.foregroundStyle(.primary)
}
} else {
ProgressView()
}
}
.analyticsView("\(Self.self)")
.task {
Task {
await viewModel.getContributors()
}
await viewModel.getContributors()
}
.navigationTitle("Contributors")
}
}

#Preview {
let viewModel = SettingsViewModel(authenticationViewModel: AuthenticationViewModel())
return ContributorsListView(viewModel: viewModel)
return NavigationStack {
ContributorsListView(viewModel: viewModel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import SwiftUI

struct ContributorsProfileView: View {

let name: String
let imgUrl: String
@ScaledMetric(relativeTo: .largeTitle) var imageSize: CGFloat = 50

init(name: String, url: String) {
self.name = name
self.imgUrl = url
}
let contributor: Contributor

@ScaledMetric(relativeTo: .largeTitle) private var imageSize: CGFloat = 50

var body: some View {
HStack {
AsyncImage(url: URL(string: imgUrl)!) { phase in
AsyncImage(url: URL(string: contributor.avatarURL)!) { phase in
switch phase {
case .empty:
ProgressView()
Expand Down Expand Up @@ -50,11 +45,30 @@ struct ContributorsProfileView: View {
}
}

Text(name)
VStack(alignment: .leading) {
Text(contributor.login)
.bold()

Text(
"^[\(contributor.contributions) contributions](inflect: true)",
comment: "the number of contributions by a contributor"
)
.foregroundStyle(.secondary)
}
}
}
}

#Preview {
ContributorsProfileView(name: "mikaela", url: "https://avatars.githubusercontent.com/u/22946902?v=4")
ContributorsProfileView(
contributor: Contributor(
login: "",
id: 1,
nodeID: "",
avatarURL: "https://avatars.githubusercontent.com/u/22946902?v=4",
url: "",
htmlURL: "",
contributions: 100
)
)
}

0 comments on commit d364003

Please sign in to comment.