diff --git a/Neuro App/HomeView.swift b/Neuro App/HomeView.swift index 8540768..4696ce5 100644 --- a/Neuro App/HomeView.swift +++ b/Neuro App/HomeView.swift @@ -15,23 +15,15 @@ struct HomeView: View { @EnvironmentObject var signalingClient: SignalingClient @EnvironmentObject var authViewModel: AuthViewModel @StateObject private var formViewModel = StrokeScaleFormViewModel() - @State private var isNavigatingToSavedForms = false // State variable to control navigation + @State private var path = NavigationPath() var body: some View { if signalingClient.isInCall { CallView(formViewModel: formViewModel) } else { - - NavigationView { + NavigationStack(path: $path) { VStack { - /* Can use when we implement login and replace 'user' with username - Text("Hello, user!") - .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/) - .bold() - .padding(10) - .foregroundColor(Color.black) - */ - + // Logout button HStack { Spacer() Button(action: { @@ -51,107 +43,83 @@ struct HomeView: View { .padding(.bottom, 5) } + // Peer ID VStack(spacing: 10) { - Text("Your Peer ID:") - .font(.headline) - .bold() - .multilineTextAlignment(.center) - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .white : .black - }) - ) + Text("Your Peer ID:") + .font(.headline) + .bold() + .multilineTextAlignment(.center) + .foregroundColor(adaptiveColor()) + + Text(signalingClient.ourPeerID) + .font(.subheadline) + .multilineTextAlignment(.center) + .foregroundColor(adaptiveColor()) + } + .padding() + .frame(maxWidth: .infinity) + .background(adaptiveBackground()) + .cornerRadius(10) + .shadow(radius: 2) - Text(signalingClient.ourPeerID) - .font(.subheadline) - .multilineTextAlignment(.center) - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .white : .black - }) - ) - } + // Active Consultations Header + Text("Active Consultations:") + .font(.headline) + .padding(.top, 20) + .foregroundColor(.black) + + // Online Users List + ScrollView { + let filteredOnlineUsers = signalingClient.onlineUsers.filter { $0 != signalingClient.ourPeerID } + + if filteredOnlineUsers.isEmpty { + Text("Hmm, nobody's here right now!") .padding() .frame(maxWidth: .infinity) - .background( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .black : .white - }) - ) + .background(adaptiveBackground()) .cornerRadius(10) .shadow(radius: 2) - - Text("Active Consultations:") - .font(.headline) - .padding(.top, 20) - .foregroundColor(Color.black) - - // Online Users List - ScrollView { - let filteredOnlineUsers = signalingClient.onlineUsers.filter { $0 != signalingClient.ourPeerID } - - if filteredOnlineUsers.isEmpty { - Text("Hmm, nobody's here right now!") - .padding() - .frame(maxWidth: .infinity) - .background( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .black : .white - }) - ) - .cornerRadius(10) - .shadow(radius: 2) - .padding(.horizontal) - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .white : .black - }) - ) - } else { - VStack(spacing: 10) { - ForEach(filteredOnlineUsers, id: \.self) { user in - OnlineUserCardView(uuid: user) - } - } - } + .padding(.horizontal) + .foregroundColor(adaptiveColor()) + } else { + VStack(spacing: 10) { + ForEach(filteredOnlineUsers, id: \.self) { user in + OnlineUserCardView(uuid: user) } - .padding(.top, 10) - - Spacer() - - VStack { - Button(action: { - isNavigatingToSavedForms = true // Trigger navigation - }) { - Text("NIH Forms") - .font(.headline) - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .white : .black - }) - ) - .padding() - .frame(maxWidth: .infinity) - .background( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .black : .white - }) - ) - .cornerRadius(10) } - .padding(.horizontal) - .padding(.bottom, 20) - .background( - NavigationLink( - destination: SavedFormsView(isNavigatingBack: $isNavigatingToSavedForms), - isActive: $isNavigatingToSavedForms, - label: { EmptyView() } - ) - ) } + } + .padding(.top, 10) + + Spacer() + + // NIH Forms Button + Button(action: { + path.append("savedForms") + }) { + Text("NIH Forms") + .font(.headline) + .foregroundColor(adaptiveColor()) + .padding() + .frame(maxWidth: .infinity) + .background(adaptiveBackground()) + .cornerRadius(10) + } + .padding(.horizontal) + .padding(.bottom, 20) + } + // Navigation destination + .navigationDestination(for: String.self) { route in + switch route { + case "savedForms": + SavedFormsView(navigationPath: $path) + default: + EmptyView() + } } + // Ringing overlay .overlay( Group { if signalingClient.isRinging { @@ -159,25 +127,35 @@ struct HomeView: View { } } ) + + // Background .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) .padding() .onAppear { signalingClient.fetchOnlineUsers() } - .background { + .background( LinearGradient(colors: [.gray, .white, .gray], startPoint: .topLeading, endPoint: .bottomTrailing) - .edgesIgnoringSafeArea(.all) - .hueRotation(.degrees(45)) - .onAppear { - withAnimation( - .easeInOut(duration: 2) - .repeatForever(autoreverses: true)) {} - } + .edgesIgnoringSafeArea(.all) + .hueRotation(.degrees(45)) + .onAppear { + withAnimation( + .easeInOut(duration: 2) + .repeatForever(autoreverses: true)) {} } + ) } .navigationBarBackButtonHidden(true) } } + + private func adaptiveColor() -> Color { + Color(UIColor { $0.userInterfaceStyle == .dark ? .white : .black }) + } + + private func adaptiveBackground() -> Color { + Color(UIColor { $0.userInterfaceStyle == .dark ? .black : .white }) + } } struct OnlineUserCardView: View { @@ -189,48 +167,27 @@ struct OnlineUserCardView: View { .font(.subheadline) .padding(.vertical, 10) .padding(.leading, 15) - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .white : .black - }) - ) + .foregroundColor(Color(UIColor { $0.userInterfaceStyle == .dark ? .white : .black })) Spacer() Button(action: { - // Action for call button + // Call action }, label: { HStack { Image(systemName: "phone.fill") - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .black : .white - }) - ) + .foregroundColor(Color(UIColor { $0.userInterfaceStyle == .dark ? .black : .white })) Text("Call") - .foregroundColor( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .black : .white - }) - ) + .foregroundColor(Color(UIColor { $0.userInterfaceStyle == .dark ? .black : .white })) } .padding(10) - .background( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .white : .black - }) - ) + .background(Color(UIColor { $0.userInterfaceStyle == .dark ? .white : .black })) .cornerRadius(8) }) .padding(.trailing, 15) } - .frame(maxWidth: .infinity) .frame(maxWidth: .infinity, minHeight: 60) - .background( - Color(UIColor { traitCollection in - return traitCollection.userInterfaceStyle == .dark ? .black : .white - }) - ) + .background(Color(UIColor { $0.userInterfaceStyle == .dark ? .black : .white })) .cornerRadius(10) .shadow(radius: 2) .padding(.horizontal) @@ -248,13 +205,13 @@ struct RingingPopopView: View { .foregroundColor(.white) Button(action: { signalingClient.cancelCall() - }, label: { + }) { Text("Cancel") .foregroundColor(.red) .padding(5) .background(Color.white) .cornerRadius(10) - }) + } .padding(.bottom, 10) } .frame(width: 200, height: 100) diff --git a/Neuro App/NewNIHFormView.swift b/Neuro App/NewNIHFormView.swift index ec6e4a5..ec7ebb1 100644 --- a/Neuro App/NewNIHFormView.swift +++ b/Neuro App/NewNIHFormView.swift @@ -4,7 +4,7 @@ struct NewNIHFormView: View { var remoteForm: RemoteStrokeForm? var initialSelectedOptions: [Int] - @Environment(\.presentationMode) var presentationMode + @Binding var navigationPath: NavigationPath @Environment(\.managedObjectContext) private var viewContext @StateObject private var viewModel = StrokeScaleFormViewModel() @State private var patientName: String @@ -12,7 +12,12 @@ struct NewNIHFormView: View { @State private var selectedOptions: [Int] @State private var showDOBPicker: Bool = false - init(remoteForm: RemoteStrokeForm? = nil, initialSelectedOptions: [Int] = Array(repeating: -1, count: 15)) { + init( + navigationPath: Binding, + remoteForm: RemoteStrokeForm? = nil, + initialSelectedOptions: [Int] = Array(repeating: -1, count: 15) + ) { + self._navigationPath = navigationPath self.remoteForm = remoteForm self.initialSelectedOptions = initialSelectedOptions @@ -143,6 +148,7 @@ struct NewNIHFormView: View { HStack { Button(action: { saveForm() + navigationPath.removeLast(navigationPath.count) }) { Text("Save") .font(.headline) @@ -155,7 +161,7 @@ struct NewNIHFormView: View { } Button(action: { - presentationMode.wrappedValue.dismiss() // Dismiss without saving + navigationPath.removeLast(navigationPath.count) }) { Text("Cancel") .font(.headline) diff --git a/Neuro App/SavedFormDetailView.swift b/Neuro App/SavedFormDetailView.swift index 389d18f..6c6ea36 100644 --- a/Neuro App/SavedFormDetailView.swift +++ b/Neuro App/SavedFormDetailView.swift @@ -9,7 +9,7 @@ struct SavedFormDetailView: View { @State var selectedOptions: [Int] @State private var isPresentingUpdateForm = false @State private var showDeleteConfirmation = false - @Environment(\.dismiss) private var dismiss + @Binding var navigationPath: NavigationPath var totalScore: Int { selectedOptions.enumerated().reduce(0) { acc, item in @@ -18,9 +18,18 @@ struct SavedFormDetailView: View { } } - init(remoteForm: RemoteStrokeForm, selectedOptions: [Int]) { + init( + navigationPath: Binding, + remoteForm: RemoteStrokeForm, + selectedOptions: [Int] + ) { + self._navigationPath = navigationPath self.remoteForm = remoteForm self._selectedOptions = State(initialValue: selectedOptions) + + for indice in 0..