Skip to content

Commit

Permalink
Make all GitHubURLs into an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelacaron committed Nov 23, 2023
1 parent e6aa92f commit a8f5572
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Foundation
@Observable
final class SettingsViewModel {
let authenticationViewModel: AuthenticationViewModel
let privacyURL = URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance-Privacy")

var contributors: [Contributor]?

Expand All @@ -39,20 +38,10 @@ final class SettingsViewModel {
self.authenticationViewModel = authenticationViewModel
}

let urls: [String: URL] = [
"mikaelacaronProfile": URL(string: "https://github.com/mikaelacaron")!,
"Basic-Car-MaintenanceRepo": URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance")!,
"bugReport": URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance/issues")!
]

// swiftlint:disable:next line_length
/// Fetches the list of contributors for the GitHub repository [Basic-Car-Maintenance](https://github.com/mikaelacaron/Basic-Car-Maintenance).
func getContributors() async {
guard let url =
URL(string: "https://api.github.com/repos/mikaelacaron/Basic-Car-Maintenance/contributors")
else {
return
}
let url = GitHubURL.apiContributors

do {
let (data, _) = try await URLSession.shared.data(from: url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct ContributorsListView: View {
ForEach(viewModel.sortedContributors) { contributor in
Link(
destination: URL(string: contributor.htmlURL) ??
viewModel.urls["Basic-Car-Maintenance"]!) {
GitHubURL.repo) {
ContributorsProfileView(name: contributor.login, url: contributor.avatarURL)
}
}
Expand Down
15 changes: 6 additions & 9 deletions Basic-Car-Maintenance/Shared/Settings/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct SettingsView: View {
// swiftlint:disable:next line_length
Text("Thanks for using this app! It's open source and anyone can contribute to it.", comment: "Thanks a user for using the app and tells the user they can contribute to the codebase")

Link(destination: URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance")!) {
Link(destination: GitHubURL.repo) {
Label {
Text("GitHub Repo", comment: "Link to the Basic Car Maintenance GitHub repo.")
} icon: {
Expand All @@ -48,12 +48,11 @@ struct SettingsView: View {
}
.popoverTip(ContributionTip(), arrowEdge: .bottom)

Link(destination: URL(string: "https://github.com/mikaelacaron")!) {
Link(destination: GitHubURL.mikaelaCaronProfile) {
Text("🦄 Mikaela Caron - Maintainer", comment: "Link to maintainer Github account.")
}

// swiftlint:disable:next line_length
Link(destination: URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance/issues/new?assignees=&labels=feature+request&projects=&template=feature-request.md&title=FEATURE+-")!) {
Link(destination: GitHubURL.featureRequest) {
Label {
Text("Request a New Feature", comment: "Link to request a new feature.")
} icon: {
Expand All @@ -62,8 +61,8 @@ struct SettingsView: View {
.frame(width: iconDimension, height: iconDimension)
}
}
// swiftlint:disable:next line_length
Link(destination: URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance/issues/new?assignees=&labels=bug&projects=&template=bug-report.md&title=BUG+-")!) {

Link(destination: GitHubURL.bugReport) {
Label {
Text("Report a Bug", comment: "Link to report a bug")
} icon: {
Expand Down Expand Up @@ -156,9 +155,7 @@ struct SettingsView: View {
}
}

if let privacyURL = viewModel.privacyURL, !privacyURL.absoluteString.isEmpty {
Link("Privacy Policy", destination: privacyURL)
}
Link("Privacy Policy", destination: GitHubURL.privacy)

Text(LocalizedStringKey(appVersion),
comment: "Label to display version and build number.")
Expand Down
20 changes: 19 additions & 1 deletion Basic-Car-Maintenance/Shared/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import Foundation

// swiftlint:disable line_length

enum FirestorePath {

/// `vehicles/{ vehicleDocumentID }/maintenance_events/{ maintenceEventDocumentID }`
Expand All @@ -15,7 +17,7 @@ enum FirestorePath {
var path: String {
switch self {
case let .maintenanceEvents(vehicleID):
return "\(FirestoreCollection.vehicles)/" + "\(vehicleID)/" + FirestoreCollection.maintenanceEvents // swiftlint:disable:this line_length
return "\(FirestoreCollection.vehicles)/" + "\(vehicleID)/" + FirestoreCollection.maintenanceEvents
}
}
}
Expand All @@ -33,6 +35,20 @@ enum FirestoreField {
static let id = "_id"
}

enum GitHubURL {
static let mikaelaCaronProfile = URL(string: "https://github.com/mikaelacaron")!

static let repo = URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance")!

static let apiContributors = URL(string: "https://api.github.com/repos/mikaelacaron/Basic-Car-Maintenance/contributors")!

static let featureRequest = URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance/issues/new?assignees=&labels=feature+request&projects=&template=feature-request.md&title=FEATURE+-")!

static let bugReport = URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance/issues/new?assignees=&labels=bug&projects=&template=bug-report.md&title=BUG+-")!

static let privacy = URL(string: "https://github.com/mikaelacaron/Basic-Car-Maintenance-Privacy")!
}

enum SFSymbol {
// MainTabView
static let dashboard = "list.dash.header.rectangle"
Expand Down Expand Up @@ -63,3 +79,5 @@ enum SFSymbol {
static let personCircle = "person.circle.fill"

}

// swiftlint:enable line_length

0 comments on commit a8f5572

Please sign in to comment.