Untitled
unknown
swift
a year ago
15 kB
9
Indexable
import SwiftUI import Amplify import Foundation struct HomePageView: View { let columns: [GridItem] = Array(repeating: .init(.flexible()), count: 2) @EnvironmentObject var tabSelectionManager: TabSelectionManager @State private var showSessionTypeSelection = false @Binding var selectedTab: Int @StateObject private var viewModel = ArgumentDetailsViewModel() var body: some View { GeometryReader { geometry in ZStack { NavigationView { ScrollView { VStack(alignment: .center, spacing: 0) { // Greeting text Text("Welcome to YinYang \nRelationship Therapy") .foregroundColor(.black) .font(.custom("Helvetica", size: 32)) .fontWeight(.thin) .padding(.top, 30) .padding([.leading, .trailing]) ReportView(totalSessions: viewModel.totalSessions, totalRelationshipAnalysisSessions: viewModel.totalRelationshipAnalysisSessions, totalArgumentAnalysisSessions: viewModel.totalArgumentAnalysisSessions) .padding(.top, 50) ZStack { Image("HomePageBackground") .resizable() .scaledToFill() .frame(width: UIScreen.main.bounds.size.width, height: (geometry.size.height / 7 ) + 50 , alignment: .top) .ignoresSafeArea() .overlay( Color.white.opacity(0.4) ) VStack { Spacer() // Adjust space above "Start Session" .frame(height: geometry.size.height / 7) // Start a session rectangle StartSessionView(showSessionTypeSelection: $showSessionTypeSelection) .padding(.horizontal) Spacer() // Adjust space below "Start Session" .frame(height: geometry.size.height / 10) // Adjust this value to change the space below "Start Session" VStack(alignment: .leading, spacing: 20) { LazyVGrid(columns: columns, spacing: 20) { SecondaryPageView(title: "Sessions", systemIconName: "list.bullet") .onTapGesture { withAnimation { tabSelectionManager.selectedTab = 1 // Adjust accordingly } } .padding(.bottom, 15) SecondaryPageView(title: "Profile", systemIconName: "person.fill") .onTapGesture { withAnimation { tabSelectionManager.selectedTab = 3 // Adjust accordingly } } .padding(.bottom, 15) } .padding(.horizontal) } } } } .navigationBarHidden(true) .background(secondaryColor.ignoresSafeArea()) } .onAppear { Task { print("Fetching argument details...") await viewModel.fetchArgumentDetails(userId: UserManager.shared.userSub) } } .background(secondaryColor.ignoresSafeArea()) if showSessionTypeSelection { SessionTypeSelectionView(showSessionTypeSelection: $showSessionTypeSelection, selectedTab: $selectedTab) .transition(.opacity) .animation(.easeInOut) } } } } } struct ArgumentsDetails: Decodable { var totalCount: Int var relationshipAdviceCount: Int var argumentAnalysisCount: Int } class ArgumentDetailsViewModel: ObservableObject { @Published var totalSessions = "0" @Published var totalRelationshipAnalysisSessions = "0" @Published var totalArgumentAnalysisSessions = "0" func fetchArgumentDetails(userId: String) async { let request = RESTRequest(path: "/arguments/details/\(userId)") do { let data = try await Amplify.API.get(request: request) // Assuming the API returns a singular `Session` object in its response let session = try JSONDecoder().decode(ArgumentsDetails.self, from: data) await MainActor.run { self.totalSessions = "\(session.totalCount)" self.totalRelationshipAnalysisSessions = "\(session.relationshipAdviceCount)" self.totalArgumentAnalysisSessions = "\(session.argumentAnalysisCount)" } } catch { print("Error fetching argument details: \(error)") } } } struct ReportView: View { let totalSessions: String let totalRelationshipAnalysisSessions: String let totalArgumentAnalysisSessions: String var body: some View { HStack { // Aligning the title to the top left VStack(alignment: .leading) { Text("Sessions Completed") .font(.subheadline) .foregroundColor(.gray) .padding(.leading, 8) .padding(.top, 8) Spacer() } Spacer() VStack { Text(totalSessions) .font(.title2) .fontWeight(.thin) .foregroundColor(.gray) Text("Total\nSessions") .font(.caption) .foregroundColor(.gray) } // Vertical Divider Divider() .frame(height: 50) VStack { Text(totalRelationshipAnalysisSessions) .font(.title2) .fontWeight(.thin) .foregroundColor(.gray) Text("Relationship\nAdvice") .font(.caption) .foregroundColor(.gray) } // Vertical Divider Divider() .frame(height: 50) VStack { Text(totalArgumentAnalysisSessions) .font(.title2) .fontWeight(.thin) .foregroundColor(.gray) Text("Argument\nAnalysis") .font(.caption) .foregroundColor(.gray) } } .padding([.top, .horizontal, .bottom]) // Add padding around the content .background(secondaryColor) .cornerRadius(10) .shadow(color: .gray, radius: 2, x: 0.5, y: 0.5) } } struct SecondaryPageView: View { let title: String let systemIconName: String var body: some View { ZStack { RoundedRectangle(cornerRadius: 15) .fill(secondaryColor) .shadow(color: .gray, radius: 2, x: 0, y: 2) VStack { Image(systemName: systemIconName) .font(.system(size: 20)) // Reduced font size for the icon .foregroundColor(.gray) .padding(.bottom, 4) // Adjusted bottom padding Text(title) .fontWeight(.thin) .font(.custom("Helvetica", size: 14)) .multilineTextAlignment(.center) .padding(.horizontal, 4) // Adjusted horizontal padding .foregroundColor(.black) } .padding(8) // Adjusted overall padding } .aspectRatio(1, contentMode: .fit) .frame(width: 150, height: 125) // Set a fixed width and height for the square } } struct StartSessionView: View { @Binding var showSessionTypeSelection: Bool var body: some View { Button(action: { withAnimation { showSessionTypeSelection = true } }) { HStack { Image("YinYangOutline") // Replace with your image asset name .resizable() .aspectRatio(contentMode: .fit) .frame(width: 100, height: 100) // Adjust the size as needed .padding(24) // Space between the image and the text Text("Start Session") .fontWeight(.thin) .font(.custom("Helvetica", size: 26)) .foregroundColor(.black) .padding(.vertical) // Add vertical padding for the text Spacer() // Ensures the text and image stay on the left } .frame(height: 75) // Height to match the SessionView .background(primaryColor) // Assuming primaryColor is a predefined color .cornerRadius(15) // Match the corner radius .shadow(color: .gray, radius: 2, x: 0, y: 2) // Match the shadow } .padding(.horizontal, 20) // Horizontal padding to match the grid's spacing } } struct SessionTypeSelectionView: View { @Binding var showSessionTypeSelection: Bool @Binding var selectedTab: Int @EnvironmentObject var tabSelectionManager: TabSelectionManager var body: some View { ZStack { Button(action: { withAnimation { showSessionTypeSelection = false } }) { Color.black.opacity(0.4) .edgesIgnoringSafeArea(.all) } VStack { Spacer() VStack(spacing: 20) { VStack { Text("Argument Analysis") .font(.custom("Helvetica", size: 20)) .frame(maxWidth: .infinity, alignment: .center) (Text("Record a real-time argument with your partner. Your relationship therapist will discuss insights and guide you towards growth. \n\n").font(.custom("Helvetica", size: 15)).fontWeight(.thin)+Text("Tap to start").font(.custom("Helvetica", size: 15))) .multilineTextAlignment(.center) .frame(maxWidth: .infinity, alignment: .center) .padding() } .padding() .background(secondaryColor) .cornerRadius(20) .shadow(radius: 10) .onTapGesture { selectedTab = 0 tabSelectionManager.selectedTab = 2 showSessionTypeSelection = false } VStack { Text("Relationship Advice") .font(.system(size: 20)) .frame(maxWidth: .infinity, alignment: .center) (Text("Get your relationship concerns off your chest. Your relationship therapist will help you make sense of your emotions and situation. \n\n").font(.custom("Helvetica", size: 15)).fontWeight(.thin)+Text("Tap to start").font(.custom("Helvetica", size: 15))) .multilineTextAlignment(.center) .frame(maxWidth: .infinity, alignment: .center) .padding() } .padding() .background(secondaryColor) .cornerRadius(20) .shadow(radius: 10) .onTapGesture { selectedTab = 1 tabSelectionManager.selectedTab = 2 showSessionTypeSelection = false } } .padding(.horizontal, 40) Spacer() } .transition(.opacity) } .frame(maxWidth: .infinity, maxHeight: .infinity) .transition(.opacity) .animation(.easeInOut) } } }
Editor is loading...
Leave a Comment