Skip to content

Commit 4c911d1

Browse files
committed
refactor(app): settings urls
1 parent 1b77771 commit 4c911d1

File tree

7 files changed

+80
-25
lines changed

7 files changed

+80
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// metro-now
2+
// https://github.com/krystxf/metro-now
3+
4+
let GITHUB_URL = "https://github.com/krystxf/metro-now"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// metro-now
2+
// https://github.com/krystxf/metro-now
3+
4+
import Foundation
5+
6+
let REVIEW_URL = URL(
7+
string: "https://itunes.apple.com/us/app/metro-now/id6504659402?mt=8&action=write-review"
8+
)

apps/mobile/metro-now/metro-now.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"components/route-label-view/get-color-by-route-name.utils.swift",
5858
"components/route-label-view/route-type.enum.swift",
5959
const/endpoint.const.swift,
60+
const/github.const.swift,
61+
"const/review-url.const.swift",
6062
"types/api-types.swift",
6163
utils/array.utils.swift,
6264
"utils/get-platform-label.swift",
@@ -73,6 +75,8 @@
7375
"components/route-label-view/route-name.view.swift",
7476
"components/route-label-view/route-type.enum.swift",
7577
const/endpoint.const.swift,
78+
const/github.const.swift,
79+
"const/review-url.const.swift",
7680
"types/api-types.swift",
7781
utils/array.utils.swift,
7882
"utils/find-closest-stop.swift",

apps/mobile/metro-now/metro-now/pages/settings/components/settings-page-about-section.view.swift

+12-19
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,13 @@
33

44
import SwiftUI
55

6-
private let reportBugUrl = URL(
7-
string: "https://github.com/krystxf/metro-now/issues/new?assignees=&labels=&projects=&template=bug_report.md&title="
8-
)
9-
10-
private let requestFeatureUrl = URL(
11-
string: "https://github.com/krystxf/metro-now/issues/new?assignees=&labels=&projects=&template=feature_request.md&title="
12-
)
13-
146
private let appStoreUrl = URL(
157
string: "https://apps.apple.com/cz/app/metro-now/id6504659402?platform=iphone"
168
)
179

18-
private let appStoreReviewUrl = URL(
19-
string: "https://itunes.apple.com/us/app/metro-now/id6504659402?mt=8&action=write-review"
20-
)
21-
2210
struct SettingsPageAboutSectionView: View {
11+
let version = getFormattedVersionNumber()
12+
2313
var body: some View {
2414
Section(
2515
header: Label("About", systemImage: "info.circle")
@@ -33,10 +23,8 @@ struct SettingsPageAboutSectionView: View {
3323
}
3424
}
3525

36-
if let appStoreReviewUrl {
37-
Link(
38-
destination: appStoreReviewUrl
39-
) {
26+
if let REVIEW_URL {
27+
Link(destination: REVIEW_URL) {
4028
Label(
4129
"Give us a rating",
4230
systemImage: "star"
@@ -45,7 +33,10 @@ struct SettingsPageAboutSectionView: View {
4533
.accessibilityHint("Opens app rating in app store")
4634
}
4735

48-
if let reportBugUrl {
36+
if let reportBugUrl = getGithubIssueUrl(
37+
template: .bug_report,
38+
title: "Bug in version \(version)"
39+
) {
4940
Link(destination: reportBugUrl) {
5041
Label(
5142
"Report bug",
@@ -55,8 +46,10 @@ struct SettingsPageAboutSectionView: View {
5546
.accessibilityHint("Opens Github issue form")
5647
}
5748

58-
if let requestFeatureUrl {
59-
Link(destination: requestFeatureUrl) {
49+
if let featureRequestUrl = getGithubIssueUrl(
50+
template: .feature_request
51+
) {
52+
Link(destination: featureRequestUrl) {
6053
Label(
6154
"Feature request",
6255
systemImage: "star.bubble"

apps/mobile/metro-now/metro-now/pages/settings/components/settings-page-footer.view.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ import SwiftUI
66
struct SettingsPageFooterView: View {
77
var body: some View {
88
VStack {
9-
let versionNumber = Bundle.main.versionNumber ?? ""
10-
let buildNumber = Bundle.main.buildNumber ?? ""
11-
let formattedVersion = "\(versionNumber)(\(buildNumber))"
12-
139
Text("metro-now")
1410

1511
Text("version: ")
16-
+ Text(formattedVersion).fontDesign(.monospaced)
12+
+ Text(getFormattedVersionNumber()).fontDesign(.monospaced)
1713

1814
Text(
19-
"[source code](https://github.com/krystxf/metro-now)"
15+
"[source code](\(GITHUB_URL))"
2016
)
2117
}
2218
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// metro-now
2+
// https://github.com/krystxf/metro-now
3+
4+
import Foundation
5+
6+
func getFormattedVersionNumber() -> String {
7+
let version = Bundle.main.versionNumber
8+
let build = Bundle.main.buildNumber
9+
10+
guard let version else {
11+
if let build {
12+
return "(\(build))"
13+
} else {
14+
return "uknknown version"
15+
}
16+
}
17+
18+
if let build {
19+
return "\(version)(\(build))"
20+
}
21+
22+
return version
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// metro-now
2+
// https://github.com/krystxf/metro-now
3+
4+
import Foundation
5+
6+
enum GithubIssueTemplate: String {
7+
case bug_report
8+
case feature_request
9+
}
10+
11+
func getGithubIssueUrl(template: GithubIssueTemplate, title: String = "") -> URL? {
12+
let url = URL(string: "\(GITHUB_URL)/issues/new")
13+
14+
guard let url else {
15+
return nil
16+
}
17+
18+
let urlWithQueryParams = url.appending(queryItems: [
19+
URLQueryItem(name: "assignees", value: nil),
20+
URLQueryItem(name: "labels", value: nil),
21+
URLQueryItem(name: "projects", value: nil),
22+
URLQueryItem(name: "template", value: "\(template.rawValue).md"),
23+
URLQueryItem(name: "title", value: title),
24+
])
25+
26+
return urlWithQueryParams
27+
}

0 commit comments

Comments
 (0)