You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.5 KiB
83 lines
2.5 KiB
//
|
|
// ContentView.swift
|
|
// LeCountdown
|
|
//
|
|
// Created by Laurent Morvillier on 20/01/2023.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct ContentView: View {
|
|
@Environment(\.managedObjectContext) private var viewContext
|
|
|
|
@FetchRequest(
|
|
sortDescriptors: [NSSortDescriptor(keyPath: \Countdown.order, ascending: true)],
|
|
animation: .default)
|
|
private var countdowns: FetchedResults<Countdown>
|
|
|
|
fileprivate let itemSpacing: CGFloat = 10.0
|
|
|
|
@State private var isShowingNewCountdown = false
|
|
|
|
private var columns: [GridItem] = [
|
|
GridItem(spacing: 10.0),
|
|
GridItem(spacing: 10.0),
|
|
]
|
|
|
|
var body: some View {
|
|
|
|
NavigationStack {
|
|
|
|
LazyVGrid(
|
|
columns: columns,
|
|
spacing: itemSpacing
|
|
) {
|
|
|
|
ForEach(countdowns) { item in
|
|
NavigationLink {
|
|
Text("Item at \(item.order)")
|
|
} label: {
|
|
Text(item.duration.minuteSecond)
|
|
.aspectRatio(contentMode: .fill)
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
|
.aspectRatio(1, contentMode: .fit)
|
|
.background(Color(red: 0.9, green: 0.95, blue: 1.0))
|
|
.cornerRadius(40.0)
|
|
}.onAppear {
|
|
|
|
}
|
|
}
|
|
|
|
}.padding(itemSpacing)
|
|
.navigationTitle("Youpi")
|
|
.sheet(isPresented: self.$isShowingNewCountdown, content: {
|
|
NewCountdownView(isPresented: $isShowingNewCountdown) .environment(\.managedObjectContext, viewContext)
|
|
})
|
|
.toolbar {
|
|
ToolbarItemGroup(placement: .bottomBar) {
|
|
Button {
|
|
self.isShowingNewCountdown = true
|
|
} label: {
|
|
Image(systemName: "plus")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private let itemFormatter: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .short
|
|
formatter.timeStyle = .medium
|
|
return formatter
|
|
}()
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
}
|
|
}
|
|
|