166 lines
4.8 KiB
Swift
166 lines
4.8 KiB
Swift
import SwiftUI
|
|
import ComposeApp
|
|
|
|
struct HomeScreenView: View {
|
|
@StateObject private var viewModel = ResidenceViewModel()
|
|
@StateObject private var loginViewModel = LoginViewModel()
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
ZStack {
|
|
Color(.systemGroupedBackground)
|
|
.ignoresSafeArea()
|
|
|
|
if viewModel.isLoading {
|
|
ProgressView()
|
|
} else {
|
|
ScrollView {
|
|
VStack(spacing: 20) {
|
|
// Overview Card
|
|
if let summary = viewModel.residenceSummary {
|
|
OverviewCard(summary: summary.summary)
|
|
}
|
|
|
|
// Navigation Cards
|
|
VStack(spacing: 16) {
|
|
NavigationLink(destination: ResidencesListView()) {
|
|
HomeNavigationCard(
|
|
icon: "house.fill",
|
|
title: "Residences",
|
|
subtitle: "Manage your properties"
|
|
)
|
|
}
|
|
|
|
NavigationLink(destination: Text("Tasks (Coming Soon)")) {
|
|
HomeNavigationCard(
|
|
icon: "checkmark.circle.fill",
|
|
title: "Tasks",
|
|
subtitle: "View and manage tasks"
|
|
)
|
|
}
|
|
}
|
|
.padding(.horizontal)
|
|
}
|
|
.padding(.vertical)
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("MyCrib")
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button(action: {
|
|
loginViewModel.logout()
|
|
}) {
|
|
Image(systemName: "rectangle.portrait.and.arrow.right")
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
viewModel.loadResidenceSummary()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct OverviewCard: View {
|
|
let summary: OverallSummary
|
|
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
HStack {
|
|
Image(systemName: "chart.bar.fill")
|
|
.font(.title3)
|
|
Text("Overview")
|
|
.font(.title2)
|
|
.fontWeight(.bold)
|
|
Spacer()
|
|
}
|
|
|
|
HStack(spacing: 40) {
|
|
StatView(
|
|
icon: "house.fill",
|
|
value: "\(summary.totalResidences)",
|
|
label: "Properties"
|
|
)
|
|
|
|
StatView(
|
|
icon: "list.bullet",
|
|
value: "\(summary.totalTasks)",
|
|
label: "Total Tasks"
|
|
)
|
|
|
|
StatView(
|
|
icon: "clock.fill",
|
|
value: "\(summary.totalPending)",
|
|
label: "Pending"
|
|
)
|
|
}
|
|
}
|
|
.padding(20)
|
|
.background(Color.blue.opacity(0.1))
|
|
.cornerRadius(16)
|
|
.padding(.horizontal)
|
|
}
|
|
}
|
|
|
|
struct StatView: View {
|
|
let icon: String
|
|
let value: String
|
|
let label: String
|
|
|
|
var body: some View {
|
|
VStack(spacing: 8) {
|
|
Image(systemName: icon)
|
|
.font(.title2)
|
|
.foregroundColor(.blue)
|
|
|
|
Text(value)
|
|
.font(.title)
|
|
.fontWeight(.bold)
|
|
|
|
Text(label)
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct HomeNavigationCard: View {
|
|
let icon: String
|
|
let title: String
|
|
let subtitle: String
|
|
|
|
var body: some View {
|
|
HStack(spacing: 16) {
|
|
Image(systemName: icon)
|
|
.font(.system(size: 36))
|
|
.foregroundColor(.blue)
|
|
.frame(width: 60)
|
|
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(title)
|
|
.font(.title3)
|
|
.fontWeight(.semibold)
|
|
.foregroundColor(.primary)
|
|
|
|
Text(subtitle)
|
|
.font(.subheadline)
|
|
.foregroundColor(.secondary)
|
|
}
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: "chevron.right")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
.padding(20)
|
|
.background(Color(.systemBackground))
|
|
.cornerRadius(12)
|
|
.shadow(color: Color.black.opacity(0.05), radius: 5, x: 0, y: 2)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
HomeScreenView()
|
|
}
|