From 55138d429f3a08c652620c3304095471b2ec113a Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 20 Feb 2023 11:18:14 +0100 Subject: [PATCH] work on stats and records --- LeCountdown/Model/Model+Extensions.swift | 7 ++++ LeCountdown/Views/Stats/ActivitiesView.swift | 41 ++++++++++++-------- LeCountdown/Views/Stats/RecordsView.swift | 2 +- LeCountdown/Views/Stats/StatsView.swift | 14 +++++-- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/LeCountdown/Model/Model+Extensions.swift b/LeCountdown/Model/Model+Extensions.swift index b144f17..8749fb5 100644 --- a/LeCountdown/Model/Model+Extensions.swift +++ b/LeCountdown/Model/Model+Extensions.swift @@ -84,6 +84,13 @@ extension Record { } } + var formattedDay: String { + if let start { + return start.formatted(date: .abbreviated, time: .omitted) + } + return "" + } + var details: String { if let start, let end { return "\(start.formatted()) - \(end.formatted())" diff --git a/LeCountdown/Views/Stats/ActivitiesView.swift b/LeCountdown/Views/Stats/ActivitiesView.swift index a526c8e..126deb3 100644 --- a/LeCountdown/Views/Stats/ActivitiesView.swift +++ b/LeCountdown/Views/Stats/ActivitiesView.swift @@ -25,25 +25,32 @@ struct ActivitiesView: View { if self.records.isEmpty { Text("You don't have any recorded activity yet") } else { - List { - ForEach(self.activities) { activity in - NavigationLink { - HStack { - StatsView(activity: activity).frame(width: 300) - .background(.red) - RecordsView(activity: activity) - .frame(maxWidth: .infinity) - .background(.green) - } - - } label: { - HStack { - Text(activity.name ?? "no activity") - Spacer() - Text(activity.recordCount) + ScrollView { + + LazyVStack { + ForEach(self.activities) { activity in + NavigationLink { + HStack { + StatsView(activity: activity).frame(width: 200) + .background(.red) + .foregroundColor(.white) + RecordsView(activity: activity) + .frame(maxWidth: .infinity) + .background(.green) + } + + } label: { + HStack { + Text(activity.name ?? "no activity") + .foregroundColor(.black).font(.title) + Spacer() + Text(activity.recordCount).font(.system(.title, weight: .bold)) + Image(systemName: "chevron.right").font(.body).foregroundColor(.gray) + } } } - } + Spacer() + }.padding(.horizontal) } } } diff --git a/LeCountdown/Views/Stats/RecordsView.swift b/LeCountdown/Views/Stats/RecordsView.swift index 7440912..6764874 100644 --- a/LeCountdown/Views/Stats/RecordsView.swift +++ b/LeCountdown/Views/Stats/RecordsView.swift @@ -21,7 +21,7 @@ struct RecordsView: View { ForEach(array) { record in HStack { - Text(record.details) + Text(record.formattedDay) Spacer() if let duration = record.duration { Text(duration.minuteSecond) diff --git a/LeCountdown/Views/Stats/StatsView.swift b/LeCountdown/Views/Stats/StatsView.swift index df852e7..ce3786e 100644 --- a/LeCountdown/Views/Stats/StatsView.swift +++ b/LeCountdown/Views/Stats/StatsView.swift @@ -125,9 +125,9 @@ struct StatsView: View { ProgressView() .progressViewStyle(CircularProgressViewStyle()) } else { - HStack { + VStack(alignment: .leading) { ForEach(self.model.statValues) { statValue in - StatView(name: statValue.stat.localizedName, value: statValue.formattedValue) + StatView(name: statValue.stat.localizedName, value: statValue.formattedValue).padding(.vertical) } } } @@ -148,13 +148,19 @@ struct StatView: View { var body: some View { VStack(alignment: .leading) { - Text(self.name.uppercased()).font(.caption) - Text(self.value).font(.title) + Text(self.name.uppercased()).font(.footnote) + Text(self.value).font(.system(.title, weight: .bold)) } } } +struct StatView_Previews: PreviewProvider { + static var previews: some View { + StatView(name: "Duration", value: "3") + } +} + struct StatsView_Previews: PreviewProvider { static var previews: some View { StatsView(activity: Activity.fake(context: PersistenceController.preview.container.viewContext))