Skip to content

Commit

Permalink
Merge pull request #31 from vcuse/newUIlauren12dash4
Browse files Browse the repository at this point in the history
new UI
  • Loading branch information
deHank authored Jan 7, 2025
2 parents 094d35f + 9f9c971 commit 2e60918
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 199 deletions.
Binary file modified .DS_Store
Binary file not shown.
119 changes: 95 additions & 24 deletions Neuro App/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct HomeView: View {

@EnvironmentObject var signalingClient: SignalingClient
@StateObject private var formViewModel = StrokeScaleFormViewModel()
@State private var isSavedFormsPresented: Bool = false // State to control the modal presentation
@State private var isNavigatingToSavedForms = false // State variable to control navigation

var body: some View {
if signalingClient.isInCall {
Expand All @@ -23,27 +23,41 @@ struct HomeView: View {

NavigationView {
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)

*/
Spacer()
VStack(spacing: 10) {
Text("Your Peer ID:")
.font(.headline)
.bold()
.multilineTextAlignment(.center)
.foregroundColor(Color.black)
.foregroundColor(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .white : .black
})
)

Text(signalingClient.ourPeerID)
.font(.subheadline)
.multilineTextAlignment(.center)
.foregroundColor(.black)
.foregroundColor(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .white : .black
})
)
}
.padding()
.frame(maxWidth: .infinity)
.background(Color.white)
.background(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .black : .white
})
)
.cornerRadius(10)
.shadow(radius: 2)

Expand All @@ -60,11 +74,19 @@ struct HomeView: View {
Text("Hmm, nobody's here right now!")
.padding()
.frame(maxWidth: .infinity)
.background(Color.white)
.background(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .black : .white
})
)
.cornerRadius(10)
.shadow(radius: 2)
.padding(.horizontal)
.foregroundColor(Color.black)
.foregroundColor(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .white : .black
})
)
} else {
VStack(spacing: 10) {
ForEach(filteredOnlineUsers, id: \.self) { user in
Expand All @@ -77,17 +99,36 @@ struct HomeView: View {

Spacer()

NavigationLink(destination: SavedFormsView()) {
Text("NIH Forms")
.font(.headline)
.foregroundColor(.black)
.padding()
.frame(maxWidth: .infinity)
.background(Color.white)
.cornerRadius(10)
}
.padding(.horizontal)
.padding(.bottom, 20)
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() }
)
)
}

}

Expand All @@ -103,8 +144,18 @@ struct HomeView: View {
.onAppear {
signalingClient.fetchOnlineUsers()
}
.background(Color(.lightGray))
.background {
LinearGradient(colors: [.gray, .white, .gray], startPoint: .topLeading, endPoint: .bottomTrailing)
.edgesIgnoringSafeArea(.all)
.hueRotation(.degrees(45))
.onAppear {
withAnimation(
.easeInOut(duration: 2)
.repeatForever(autoreverses: true)){}
}
}
}

}
}
}
Expand All @@ -118,7 +169,11 @@ struct OnlineUserCardView: View {
.font(.subheadline)
.padding(.vertical, 10)
.padding(.leading, 15)
.foregroundColor(Color.black)
.foregroundColor(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .white : .black
})
)

Spacer()

Expand All @@ -127,18 +182,34 @@ struct OnlineUserCardView: View {
}, label: {
HStack {
Image(systemName: "phone.fill")
.foregroundColor(.white)
.foregroundColor(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .black : .white
})
)
Text("Call")
.foregroundColor(.white)
.foregroundColor(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .black : .white
})
)
}
.padding(10)
.background(Color.black)
.background(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .white : .black
})
)
.cornerRadius(8)
})
.padding(.trailing, 15)
}
.frame(maxWidth: .infinity)
.background(Color.white)
.background(
Color(UIColor { traitCollection in
return traitCollection.userInterfaceStyle == .dark ? .black : .white
})
)
.cornerRadius(10)
.shadow(radius: 2)
.padding(.horizontal)
Expand Down
3 changes: 1 addition & 2 deletions Neuro App/Neuro_AppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ struct Neuro_App: App {

var body: some Scene {
WindowGroup {

HomeView()
HomeView()
.environment(\.managedObjectContext, appDelegate.persistentContainer.viewContext) // Inject Core Data context
.environmentObject(appDelegate.signalingClient)
}
Expand Down
101 changes: 101 additions & 0 deletions Neuro App/NewNIHFormView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import SwiftUI

struct NewNIHFormView: View {
@Environment(\.managedObjectContext) private var viewContext
@StateObject private var viewModel = StrokeScaleFormViewModel()
@State private var patientName: String = ""
@Environment(\.presentationMode) var presentationMode

var body: some View {
VStack {
Text("New NIH Stroke Scale Form")
.font(.title)
.padding(.leading)
.padding(.trailing)
.padding(.top)
.padding(.bottom, 5)
.bold()

TextField("Enter Patient Name", text: $patientName)
.padding(.leading)
.padding(.trailing)
.padding(.bottom, 5)
.textFieldStyle(RoundedBorderTextFieldStyle())

Text("Date: \(Date(), style: .date)")
.padding(.bottom, 5)

Form {
ForEach(viewModel.questions.indices, id: \.self) { index in
let question = viewModel.questions[index]
Section {
OptionRowView(question: question, selectedOption: $viewModel.questions[index].selectedOption)
}
}
}


// Save and Cancel buttons
HStack {
Button(action: {
saveForm()
presentationMode.wrappedValue.dismiss() // Dismiss after saving
}) {
Text("Save")
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.green)
.cornerRadius(10)
}

Button(action: {
presentationMode.wrappedValue.dismiss() // Dismiss without saving
}) {
Text("Cancel")
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.red)
.cornerRadius(10)
}
}
.padding(.horizontal)
.padding(.bottom)
}
.background(Color.purple.opacity(0.2))
}

private func saveForm() {
// Get the Core Data context from the environment
let context = viewContext

// Create a new NIHFormEntity
let newForm = NIHFormEntity(context: context)
newForm.date = Date()
newForm.patientName = patientName

// Collect selected options from each question
let selectedOptions = viewModel.questions.map { $0.selectedOption ?? -1 }

// Encode the array of selected options into data and save it in Core Data
do {
let optionsData = try JSONEncoder().encode(selectedOptions)
newForm.selectedOptions = optionsData as Data

// Ensure the save operation happens on the main thread
DispatchQueue.main.async {
do {
try context.save()
print("Form saved successfully.")
} catch {
print("Failed to save form: \(error)")
}
}
} catch {
print("Failed to encode selected options: \(error)")
}
}
}
Loading

0 comments on commit 2e60918

Please sign in to comment.