Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
5 changes: 5 additions & 0 deletions AIReviewSwiftUI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ struct ContentView: View {
newTaskTitle = ""
}

TaskSummaryView(
totalTasks: viewModel.tasks.count,
completedTasks: viewModel.completedTasks,
overdueTasks: viewModel.overdueTasks
)
List {
ForEach(viewModel.tasks) { task in
HStack {
Expand Down
1 change: 1 addition & 0 deletions AIReviewSwiftUI/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ struct Task: Identifiable {
let id = UUID()
var title: String
var isCompleted: Bool = false
var dueDate: Date? = nil
}
34 changes: 34 additions & 0 deletions AIReviewSwiftUI/TaskSummaryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// TaskSummaryView.swift
// AIReviewSwiftUI
//
// Created by kanagasabapathy on 26.04.25.
//


import SwiftUI

struct TaskSummaryView: View {
let totalTasks: Int
let completedTasks: Int
let overdueTasks: Int
Copy link

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overdueTasks property is defined but not displayed in the view. Consider adding a UI element to show the overdue task count to align with the PR description.

Copilot uses AI. Check for mistakes.

var body: some View {
HStack {
VStack(alignment: .leading) {
Text("Total Tasks")
.font(.headline)
Text("\(totalTasks)")
.font(.largeTitle)
}
Spacer()
VStack(alignment: .leading) {
Text("Completed Tasks")
.font(.headline)
Text("\(completedTasks)")
.font(.largeTitle)
}
}
.padding()
}
Comment on lines +16 to +33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Implement display of overdue tasks

The view declares an overdueTasks property but doesn't display it in the UI. According to the PR objectives, one of the goals was to display overdue tasks information.

var body: some View {
    HStack {
        VStack(alignment: .leading) {
            Text("Total Tasks")
                .font(.headline)
            Text("\(totalTasks)")
                .font(.largeTitle)
        }
        Spacer()
        VStack(alignment: .leading) {
            Text("Completed Tasks")
                .font(.headline)
            Text("\(completedTasks)")
                .font(.largeTitle)
        }
+       Spacer()
+       VStack(alignment: .leading) {
+           Text("Overdue Tasks")
+               .font(.headline)
+           Text("\(overdueTasks)")
+               .font(.largeTitle)
+               .foregroundColor(.red)
+       }
    }
    .padding()
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var body: some View {
HStack {
VStack(alignment: .leading) {
Text("Total Tasks")
.font(.headline)
Text("\(totalTasks)")
.font(.largeTitle)
}
Spacer()
VStack(alignment: .leading) {
Text("Completed Tasks")
.font(.headline)
Text("\(completedTasks)")
.font(.largeTitle)
}
}
.padding()
}
var body: some View {
HStack {
VStack(alignment: .leading) {
Text("Total Tasks")
.font(.headline)
Text("\(totalTasks)")
.font(.largeTitle)
}
Spacer()
VStack(alignment: .leading) {
Text("Completed Tasks")
.font(.headline)
Text("\(completedTasks)")
.font(.largeTitle)
}
Spacer()
VStack(alignment: .leading) {
Text("Overdue Tasks")
.font(.headline)
Text("\(overdueTasks)")
.font(.largeTitle)
.foregroundColor(.red)
}
}
.padding()
}

}
8 changes: 7 additions & 1 deletion AIReviewSwiftUI/TaskViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ final class TaskViewModel: ObservableObject {
guard let index = tasks.firstIndex(where: { $0.id == task.id }) else { return }
tasks[index].isCompleted.toggle()
}
}
var completedTasks: Int {
tasks.filter { $0.isCompleted }.count
}
var overdueTasks: Int {
tasks.filter { $0.dueDate != nil && $0.dueDate! < Date() && !$0.isCompleted }.count
}
Comment on lines +26 to +28
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid force unwrapping in overdueTasks calculation

While the force unwrap is preceded by a nil check, it's generally better to use safe unwrapping techniques to prevent potential runtime issues.

var overdueTasks: Int {
-    tasks.filter { $0.dueDate != nil && $0.dueDate! < Date() && !$0.isCompleted }.count
+    tasks.filter { 
+        if let dueDate = $0.dueDate, dueDate < Date(), !$0.isCompleted {
+            return true
+        }
+        return false
+    }.count
}

Alternative shorter implementation:

var overdueTasks: Int {
-    tasks.filter { $0.dueDate != nil && $0.dueDate! < Date() && !$0.isCompleted }.count
+    tasks.filter { guard let dueDate = $0.dueDate else { return false }
+        return dueDate < Date() && !$0.isCompleted
+    }.count
}

}
Loading