84 lines
2.8 KiB
Swift
84 lines
2.8 KiB
Swift
//
|
|
// AddMoodHeaderView.swift
|
|
// Feels
|
|
//
|
|
// Created by Trey Tartt on 1/5/22.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct AddMoodHeaderView: View {
|
|
private let savedOnboardingData = UserDefaultsStore.getOnboarding()
|
|
|
|
let addItemHeaderClosure: ((Mood, Date) -> Void)
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Color(UIColor.systemBackground)
|
|
|
|
VStack {
|
|
Text("How is today?")
|
|
.font(.title)
|
|
.foregroundColor(Color(UIColor.label))
|
|
.padding()
|
|
HStack{
|
|
ForEach(Mood.allValues) { mood in
|
|
VStack {
|
|
Button(action: {
|
|
addItem(withMood: mood)
|
|
}, label: {
|
|
mood.icon
|
|
.resizable()
|
|
.frame(width: 50, height: 50, alignment: .center)
|
|
.foregroundColor(mood.color)
|
|
})
|
|
|
|
//Text(mood.strValue)
|
|
}.frame(minWidth: 0, maxWidth: .infinity)
|
|
}
|
|
}
|
|
.padding([.leading, .trailing, .bottom])
|
|
}
|
|
}
|
|
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
|
|
.frame(minHeight: 85, maxHeight: 140)
|
|
.frame(minWidth: 0, maxWidth: .infinity)
|
|
.padding()
|
|
}
|
|
|
|
private func addItem(withMood mood: Mood) {
|
|
switch savedOnboardingData.inputDay {
|
|
case .Today:
|
|
addItemHeaderClosure(mood, Date())
|
|
case .Previous:
|
|
let date = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
|
|
addItemHeaderClosure(mood, date)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct AddMoodHeaderView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
AddMoodHeaderView(addItemHeaderClosure: { (_,_) in
|
|
|
|
}).environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
|
|
AddMoodHeaderView(addItemHeaderClosure: { (_,_) in
|
|
|
|
}).preferredColorScheme(.dark).environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
|
|
AddMoodHeaderView(addItemHeaderClosure: { (_,_) in
|
|
|
|
}).environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
|
|
AddMoodHeaderView(addItemHeaderClosure: { (_,_) in
|
|
|
|
}).preferredColorScheme(.dark).environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
}
|
|
}
|
|
}
|