Files
honeyDueKMP/iosApp/iosApp/Residence/ResidencesListView.swift
Trey t 97eed0eee9 wip
2025-11-08 10:52:28 -06:00

91 lines
3.0 KiB
Swift

import SwiftUI
import ComposeApp
struct ResidencesListView: View {
@StateObject private var viewModel = ResidenceViewModel()
@State private var showingAddResidence = false
@State private var showingJoinResidence = false
var body: some View {
ZStack {
Color(.systemGroupedBackground)
.ignoresSafeArea()
if viewModel.isLoading {
ProgressView()
} else if let error = viewModel.errorMessage {
ErrorView(message: error) {
viewModel.loadMyResidences()
}
} else if let response = viewModel.myResidences {
if response.residences.isEmpty {
EmptyResidencesView()
} else {
ScrollView {
VStack(spacing: 16) {
// Summary Card
SummaryCard(summary: response.summary)
.padding(.horizontal)
.padding(.top)
// Properties Header
HStack {
Text("Your Properties")
.font(.title2)
.fontWeight(.bold)
Spacer()
}
.padding(.horizontal)
.padding(.top, 8)
// Residences List
ForEach(response.residences, id: \.id) { residence in
NavigationLink(destination: ResidenceDetailView(residenceId: residence.id)) {
ResidenceCard(residence: residence)
}
.buttonStyle(PlainButtonStyle())
}
.padding(.horizontal)
}
.padding(.bottom)
}
}
}
}
.navigationTitle("My Properties")
.navigationBarTitleDisplayMode(.large)
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button(action: {
showingJoinResidence = true
}) {
Image(systemName: "person.badge.plus")
}
Button(action: {
showingAddResidence = true
}) {
Image(systemName: "plus")
}
}
}
.sheet(isPresented: $showingAddResidence) {
AddResidenceView(isPresented: $showingAddResidence)
}
.sheet(isPresented: $showingJoinResidence) {
JoinResidenceView(onJoined: {
viewModel.loadMyResidences()
})
}
.onAppear {
viewModel.loadMyResidences()
}
}
}
#Preview {
NavigationView {
ResidencesListView()
}
}