Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Modules/Sources/JetpackStats/Screens/ArchiveStatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct ArchiveStatsView: View {
Spacer()

if let totalViews = archiveSection.metrics.views {
StandaloneMetricView(metric: .views, value: totalViews)
StandaloneMetricView(metric: .views, value: totalViews, dateInterval: dateRange.dateInterval)
}
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ struct ArchiveStatsView: View {
}

private var itemsChartData: TopListData {
return TopListData(
TopListData(
item: .archive,
metric: .views,
items: archiveSection.items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ struct ExternalLinkStatsView: View {
@ViewBuilder
var linkIcon: some View {
if let url = URL(string: externalLink.url),
let host = url.host,
let iconURL = URL(string: "https://www.google.com/s2/favicons?domain=\(host)&sz=128") {
let host = url.host,
let iconURL = URL(string: "https://www.google.com/s2/favicons?domain=\(host)&sz=128")
{
CachedAsyncImage(url: iconURL) { image in
image
.resizable()
Expand Down Expand Up @@ -100,7 +101,7 @@ struct ExternalLinkStatsView: View {
@ViewBuilder
var viewsCount: some View {
if let views = externalLink.metrics.views {
StandaloneMetricView(metric: .views, value: views)
StandaloneMetricView(metric: .views, value: views, dateInterval: dateRange.dateInterval)
}
}

Expand Down Expand Up @@ -131,7 +132,7 @@ struct ExternalLinkStatsView: View {
}

private var childrenChartData: TopListData {
return TopListData(
TopListData(
item: .externalLinks,
metric: .views,
items: externalLink.children
Expand Down
14 changes: 8 additions & 6 deletions Modules/Sources/JetpackStats/Screens/ReferrerStatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct ReferrerStatsView: View {
.navigationTitle(Strings.ReferrerDetails.title)
.navigationBarTitleDisplayMode(.inline)
.alert(Strings.ReferrerDetails.errorAlertTitle, isPresented: $showErrorAlert) {
Button(Strings.Buttons.ok, role: .cancel) { }
Button(Strings.Buttons.ok, role: .cancel) {}
} message: {
Text(errorMessage)
}
Expand All @@ -66,7 +66,7 @@ struct ReferrerStatsView: View {
await markAsSpam()
}
}
Button(Strings.Buttons.cancel, role: .cancel) { }
Button(Strings.Buttons.cancel, role: .cancel) {}
} message: {
Text(Strings.ReferrerDetails.confirmAsSpamMessage(domain: referrer.domain ?? ""))
}
Expand Down Expand Up @@ -122,7 +122,7 @@ struct ReferrerStatsView: View {
@ViewBuilder
var viewsCount: some View {
if let views = referrer.metrics.views {
StandaloneMetricView(metric: .views, value: views)
StandaloneMetricView(metric: .views, value: views, dateInterval: dateRange.dateInterval)
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ struct ReferrerStatsView: View {
}

private var childrenChartData: TopListData {
return TopListData(
TopListData(
item: .referrers,
metric: .views,
items: referrer.children
Expand All @@ -187,7 +187,9 @@ struct ReferrerStatsView: View {
// Update local state to reflect the change
isMarkedAsSpam = true
} catch {
errorMessage = error.localizedDescription.isEmpty ? Strings.ReferrerDetails.markAsSpamError : error.localizedDescription
errorMessage =
error.localizedDescription.isEmpty
? Strings.ReferrerDetails.markAsSpamError : error.localizedDescription
showErrorAlert = true
}

Expand All @@ -201,7 +203,7 @@ struct ReferrerStatsView: View {
NavigationView {
ReferrerStatsView(
referrer: .mock,
dateRange: Calendar.demo.makeDateRange(for: .thisYear)
dateRange: Calendar.demo.makeDateRange(for: .last7Days)
)
}
.navigationViewStyle(.stack)
Expand Down
19 changes: 17 additions & 2 deletions Modules/Sources/JetpackStats/Views/StandaloneMetricView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import DesignSystem
struct StandaloneMetricView: View {
let metric: SiteMetric
let value: Int
var dateInterval: DateInterval?

@Environment(\.context) private var context

var body: some View {
VStack(alignment: .trailing, spacing: 0) {
Expand All @@ -15,11 +18,23 @@ struct StandaloneMetricView: View {
.font(Constants.Typography.smallDisplayFont)
.foregroundColor(.primary)
.contentTransition(.numericText())
if let dateInterval {
Text(context.formatters.dateRange.string(from: dateInterval))
.font(.footnote)
.foregroundColor(.secondary)
}
}
}
}

#Preview {
StandaloneMetricView(metric: .views, value: 12345)
.padding()
VStack(spacing: 32) {
StandaloneMetricView(metric: .views, value: 12345)
StandaloneMetricView(
metric: .views,
value: 12345,
dateInterval: Calendar.demo.makeDateRange(for: .last7Days).dateInterval
)
}
.padding()
}