diff --git a/LexAI_iOS/LexAI_iOS/Managers/ScanDocumentsView.swift b/LexAI_iOS/LexAI_iOS/Managers/ScanDocumentsView.swift index 94ab9c7..0b9e15b 100644 --- a/LexAI_iOS/LexAI_iOS/Managers/ScanDocumentsView.swift +++ b/LexAI_iOS/LexAI_iOS/Managers/ScanDocumentsView.swift @@ -17,17 +17,20 @@ struct ScanDocumentsView: UIViewControllerRepresentable { @Binding var isPresented: Bool var onTextAdded: ((String) -> Void)? + //Makes and configures the VNDocumentCameraViewController for document scanning func makeUIViewController(context: Context) -> VNDocumentCameraViewController { let scanner = VNDocumentCameraViewController() scanner.delegate = context.coordinator return scanner } + //Updates the view controller when SwiftUI state changes- keeps it currently empty as no updates are needed func updateUIViewController( _ uiViewController: VNDocumentCameraViewController, context: Context ) {} + //Makes a coordinator to handle delegate methods from the document camera view controller func makeCoordinator() -> Coordinator { Coordinator(self) } @@ -39,6 +42,7 @@ struct ScanDocumentsView: UIViewControllerRepresentable { self.parent = parent } + //Processes the scanned document pages, extracts text from each page and calls the onTextAdded callback with the combined text func documentCameraViewController( _ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan @@ -61,10 +65,12 @@ struct ScanDocumentsView: UIViewControllerRepresentable { parent.isPresented = false } + //Handles cancellation of the document scanner by dismissing the view func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) { parent.isPresented = false } + //Handles errors during document scanning by logging the error and dismissing the view func documentCameraViewController( _ controller: VNDocumentCameraViewController, didFailWithError error: Error @@ -73,6 +79,7 @@ struct ScanDocumentsView: UIViewControllerRepresentable { parent.isPresented = false } + //Extracts text from a given UIImage using Vision's text recognition private func extractText(from image: UIImage) -> String? { guard let cgImage = image.cgImage else { return nil } @@ -98,6 +105,7 @@ struct ScanDocumentsView: UIViewControllerRepresentable { struct ScanDocumentsPreviewWrapper: View { @State private var showScanner = true + //Gives a preview of the document scanner view for SwiftUI previews var body: some View { Text("Document Scanner Preview") .font(.title2) diff --git a/LexAI_iOS/LexAI_iOS/Views/ChatView.swift b/LexAI_iOS/LexAI_iOS/Views/ChatView.swift index 6218f83..cb655d1 100644 --- a/LexAI_iOS/LexAI_iOS/Views/ChatView.swift +++ b/LexAI_iOS/LexAI_iOS/Views/ChatView.swift @@ -23,6 +23,7 @@ struct ChatView: View { private let functions = Functions.functions() + //Defines the main chat interface layout, including the title, message list, and input bar. var body: some View { ZStack(alignment: .bottom) { VStack(spacing: 0) { @@ -150,6 +151,7 @@ struct ChatView: View { .buttonStyle(.plain) } + //Makes a scrollable list of chat messages with automatic scrolling to the bottom // MARK: Message List private var messageList: some View { @@ -176,6 +178,7 @@ struct ChatView: View { .frame(maxWidth: .infinity, maxHeight: .infinity) } + //Makes the input bar with scan document button, text field, and send button // MARK: Input Bar private var inputBar: some View { @@ -220,6 +223,7 @@ struct ChatView: View { .padding(.top) } + //Sends the user's message, validates input, and handles the AI response asynchronously // MARK: File Import Handler private func handleFileImport(_ result: Result<[URL], Error>) { @@ -282,8 +286,11 @@ struct ChatView: View { } } + //Calls the Firebase function to generate an AI response based on the prompt and chat history private func generateAnswer(prompt: String, targetLanguage: String) async throws -> String { let callable = functions.httpsCallable("chat") + + //Build chat history from previous messages (exclude the one we just added) let chatHistory: [[String: String]] = messages.dropLast().map { msg in ["role": msg.isFromUser ? "user" : "assistant", "content": msg.text] } @@ -307,6 +314,8 @@ struct ChatView: View { private struct MessageBubbleView: View { let message: ChatMessage + + //Defines the layout for displaying a single chat message bubble var body: some View { HStack(alignment: .top) { diff --git a/LexAI_iOS/LexAI_iOS/Views/HomeView.swift b/LexAI_iOS/LexAI_iOS/Views/HomeView.swift index 0a5372c..a108c8b 100644 --- a/LexAI_iOS/LexAI_iOS/Views/HomeView.swift +++ b/LexAI_iOS/LexAI_iOS/Views/HomeView.swift @@ -8,6 +8,7 @@ struct HomeView: View { @StateObject private var sidebarVM = SidebarViewModel() private let languages = ["English", "Spanish", "French", "Arabic", "German"] + //Defines the main view layout, including the chat view, sidebar, and language dropdown var body: some View { NavigationStack { GeometryReader { geo in diff --git a/installation.md b/installation.md index 41296df..7fbe3db 100644 --- a/installation.md +++ b/installation.md @@ -18,11 +18,11 @@ Supported MacOS Versions: - macOS 15 (Sequoia) Pre-installations: -Step 1: Xcode -Step 2: node.js | https://nodejs.org/en/ -Step 3: Git | https://git-scm.com/downloads -Step 4: Python 3.9+ | python.org/downloads -Step 5: Request to be added as a FireBase project member and download the GoogleService-Info.plist +1.) Xcode +2.) node.js | https://nodejs.org/en/ +3.) Git | https://git-scm.com/downloads +4.) Python 3.9+ | python.org/downloads +5.) Request to be added as a FireBase project member and download the GoogleService-Info.plist Instructions to build and Install the Software Step 1: Verify you have all prerequisite and pre-installations to build the project.