everything changed

This commit is contained in:
Trey t
2022-02-20 14:33:58 -06:00
parent 1cf38cb854
commit 0035f61204
50 changed files with 2155 additions and 875 deletions

View File

@@ -13,8 +13,9 @@ enum PercViewType {
}
struct HeaderPercView: View {
typealias model = (mood: Mood, total: Int, percent: Float)
var entries = [model]()
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
var entries = [MoodMetrics]()
let backDays: Int
let type: PercViewType
@@ -32,44 +33,34 @@ struct HeaderPercView: View {
moodEntries = PersistenceController.shared.getData(startDate: daysAgo, endDate: Date(), includedDays: [1,2,3,4,5,6,7])
}
let totalEntryCount = moodEntries?.count ?? 0
if let moodEntries = moodEntries {
for (_, mood) in Mood.allValues.enumerated() {
let moodEntries = moodEntries.filter({
Int($0.moodValue) == mood.rawValue
})
let total = moodEntries.count
let perc = (Float(total) / Float(totalEntryCount)) * 100
entries.append((mood, total, perc))
}
entries = Random.createTotalPerc(fromEntries: moodEntries)
entries = entries.sorted(by: {
$0.mood.rawValue > $1.mood.rawValue
})
}
entries = entries.sorted(by: {
$0.0.rawValue > $1.0.rawValue
})
}
private var textViews: some View {
VStack {
Spacer()
HStack {
ForEach(entries.prefix(3), id: \.0) { model in
ForEach(entries.prefix(3), id: \.id) { model in
Text("\(model.percent, specifier: "%.0f")%")
.font(.title)
.fontWeight(.bold)
.foregroundColor(model.mood.color)
.foregroundColor(moodTint.color(forMood: model.mood))
.frame(maxWidth: .infinity)
}
}
Spacer()
HStack {
ForEach(entries.suffix(2), id: \.0) { model in
ForEach(entries.suffix(2), id: \.id) { model in
Text("\(model.percent, specifier: "%.0f")%")
.font(.title)
.fontWeight(.bold)
.foregroundColor(model.mood.color)
.foregroundColor(moodTint.color(forMood: model.mood))
.frame(maxWidth: .infinity)
}
}
@@ -81,27 +72,27 @@ struct HeaderPercView: View {
VStack {
Spacer()
HStack {
ForEach(entries.prefix(3), id: \.0) { model in
ForEach(entries.prefix(3), id: \.id) { model in
Text("\(model.percent, specifier: "%.0f")%")
.font(.title2)
.fontWeight(.bold)
.multilineTextAlignment(.center)
.padding()
.frame(maxWidth: .infinity)
.background(Circle().fill(model.mood.color))
.background(Circle().fill(moodTint.color(forMood: model.mood)))
.foregroundColor(Color(UIColor.white))
}
}
Spacer()
HStack {
ForEach(entries.suffix(2), id: \.0) { model in
ForEach(entries.suffix(2), id: \.id) { model in
Text("\(model.percent, specifier: "%.0f")%")
.font(.title2)
.fontWeight(.bold)
.multilineTextAlignment(.center)
.padding()
.frame(maxWidth: .infinity)
.background(Circle().fill(model.mood.color))
.background(Circle().fill(moodTint.color(forMood: model.mood)))
.foregroundColor(Color(UIColor.white))
}
}