work on stats and records

release
Laurent 3 years ago
parent 2dfa0c9e9b
commit 55138d429f
  1. 7
      LeCountdown/Model/Model+Extensions.swift
  2. 41
      LeCountdown/Views/Stats/ActivitiesView.swift
  3. 2
      LeCountdown/Views/Stats/RecordsView.swift
  4. 14
      LeCountdown/Views/Stats/StatsView.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())"

@ -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)
}
}
}

@ -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)

@ -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))

Loading…
Cancel
Save