70 lines
2.4 KiB
Swift
70 lines
2.4 KiB
Swift
//
|
|
// AddMoodHeaderView.swift
|
|
// Feels
|
|
//
|
|
// Created by Trey Tartt on 1/5/22.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct AddMoodHeaderView: View {
|
|
@Environment(\.managedObjectContext) private var viewContext
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Color(UIColor.secondarySystemBackground)
|
|
|
|
VStack {
|
|
Text("How are you feeling today?")
|
|
.font(.title)
|
|
.foregroundColor(Color(UIColor.label))
|
|
.padding()
|
|
HStack{
|
|
ForEach(Mood.allValues.reversed()) { 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) {
|
|
withAnimation {
|
|
PersistenceController.shared.add(mood: mood, forDate: Date())
|
|
}
|
|
}
|
|
}
|
|
|
|
struct AddMoodHeaderView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
AddMoodHeaderView().environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
|
|
AddMoodHeaderView().preferredColorScheme(.dark).environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
|
|
AddMoodHeaderView().environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
|
|
AddMoodHeaderView().preferredColorScheme(.dark).environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
|
|
}
|
|
}
|
|
}
|