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.
106 lines
3.3 KiB
106 lines
3.3 KiB
//
|
|
// HomeView.swift
|
|
// LeCountdown
|
|
//
|
|
// Created by Laurent Morvillier on 15/02/2023.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct CompactHomeView: View {
|
|
|
|
@Environment(\.managedObjectContext) private var viewContext
|
|
|
|
@FetchRequest(
|
|
sortDescriptors: [NSSortDescriptor(keyPath: \AbstractTimer.order, ascending: true)],
|
|
animation: .default)
|
|
private var timers: FetchedResults<AbstractTimer>
|
|
|
|
@State private var tabSelection: Int = 0
|
|
|
|
var body: some View {
|
|
|
|
TabView(selection: $tabSelection) {
|
|
NavigationStack {
|
|
PresetsView(tabSelection: $tabSelection)
|
|
.environment(\.managedObjectContext, viewContext)
|
|
.tabItem { Label("Presets", systemImage: "globe") }
|
|
.tag(0)
|
|
}
|
|
NavigationStack {
|
|
ContentView<AbstractTimer>()
|
|
.environment(\.managedObjectContext, viewContext)
|
|
.environmentObject(Conductor.maestro)
|
|
.tabItem { Label("Home", systemImage: "clock.fill") }
|
|
.tag(1)
|
|
}
|
|
NavigationStack {
|
|
ActivitiesView()
|
|
.environment(\.managedObjectContext, viewContext)
|
|
.tabItem { Label("Stats", systemImage: "chart.bar.fill") }
|
|
.tag(2)
|
|
}
|
|
}
|
|
.tabViewStyle(.page)
|
|
.onAppear {
|
|
if self.timers.count > 0 {
|
|
self.tabSelection = 1
|
|
}
|
|
}
|
|
.onOpenURL { _ in
|
|
self.tabSelection = 1
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
struct RegularHomeView: View {
|
|
|
|
@Environment(\.managedObjectContext) private var viewContext
|
|
|
|
@State private var tabSelection: Int = 1
|
|
|
|
var body: some View {
|
|
|
|
NavigationStack {
|
|
TabView(selection: $tabSelection) {
|
|
PresetsView(tabSelection: $tabSelection)
|
|
.environment(\.managedObjectContext, viewContext)
|
|
.tabItem { Label("Presets", systemImage: "globe") }
|
|
.tag(0)
|
|
ContentView<AbstractTimer>()
|
|
.environment(\.managedObjectContext, viewContext)
|
|
.environmentObject(Conductor.maestro)
|
|
.tabItem { Label("Home", systemImage: "clock.fill") }
|
|
.tag(1)
|
|
ActivitiesView()
|
|
.environment(\.managedObjectContext, viewContext)
|
|
.tabItem { Label("Stats", systemImage: "chart.bar.fill") }
|
|
.tag(2)
|
|
}
|
|
}
|
|
.tabViewStyle(.page)
|
|
.onOpenURL { _ in
|
|
self.tabSelection = 1
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
struct CompactHomeView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CompactHomeView()
|
|
.environmentObject(Conductor.maestro)
|
|
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
|
|
}
|
|
}
|
|
|
|
struct RegularHomeView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
RegularHomeView()
|
|
.environmentObject(Conductor.maestro)
|
|
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
|
|
}
|
|
}
|
|
|