diff --git a/TaskManager.xcodeproj/project.pbxproj b/TaskManager.xcodeproj/project.pbxproj index 808e655..93cd108 100644 --- a/TaskManager.xcodeproj/project.pbxproj +++ b/TaskManager.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ EE00D2BC2C6F8D65004FF048 /* TaskViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE00D2BB2C6F8D65004FF048 /* TaskViewModel.swift */; }; EE019E182C9460C600A8B764 /* TaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE019E172C9460C600A8B764 /* TaskModel.swift */; }; + EE0AD8132D282DEF00AEF204 /* TemplateViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE0AD8122D282DEF00AEF204 /* TemplateViews.swift */; }; EE3AE1712CC69970001A80C1 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE3AE1702CC69970001A80C1 /* Router.swift */; }; EE4BB9C72B88F49F00FFF4F2 /* TextStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4BB9C62B88F49F00FFF4F2 /* TextStyles.swift */; }; EE59B6B42C342680003D59DF /* AboutPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE59B6B32C342680003D59DF /* AboutPageView.swift */; }; @@ -24,6 +25,7 @@ /* Begin PBXFileReference section */ EE00D2BB2C6F8D65004FF048 /* TaskViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskViewModel.swift; sourceTree = ""; }; EE019E172C9460C600A8B764 /* TaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskModel.swift; sourceTree = ""; }; + EE0AD8122D282DEF00AEF204 /* TemplateViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateViews.swift; sourceTree = ""; }; EE3AE1702CC69970001A80C1 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = ""; }; EE4BB9C62B88F49F00FFF4F2 /* TextStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyles.swift; sourceTree = ""; }; EE59B6B32C342680003D59DF /* AboutPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutPageView.swift; sourceTree = ""; }; @@ -54,6 +56,7 @@ EE59B6B32C342680003D59DF /* AboutPageView.swift */, EED772142B7BC0C6007BDA4A /* AddTaskView.swift */, EEA7106D2C908CA000785086 /* HomeView.swift */, + EE0AD8122D282DEF00AEF204 /* TemplateViews.swift */, EEFAD1902CD3A7F900018043 /* AllTasksView.swift */, ); path = Views; @@ -195,6 +198,7 @@ EE4BB9C72B88F49F00FFF4F2 /* TextStyles.swift in Sources */, EED772132B7BC0C6007BDA4A /* TaskManagerApp.swift in Sources */, EE996DF12B88E1EE0036470C /* Spacing.swift in Sources */, + EE0AD8132D282DEF00AEF204 /* TemplateViews.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TaskManager/Router.swift b/TaskManager/Router.swift index 831f87f..29e687f 100644 --- a/TaskManager/Router.swift +++ b/TaskManager/Router.swift @@ -10,6 +10,7 @@ import SwiftUI final class Router: ObservableObject { public enum Destination: Codable, Hashable { + case home case addTask case aboutPage case allTasks diff --git a/TaskManager/TaskManagerApp.swift b/TaskManager/TaskManagerApp.swift index 33aa2f4..00b43f4 100644 --- a/TaskManager/TaskManagerApp.swift +++ b/TaskManager/TaskManagerApp.swift @@ -10,19 +10,25 @@ import SwiftUI @main struct TaskManagerApp: App { @ObservedObject var router = Router() + var body: some Scene { + let viewModel = TaskViewModel(router: router) WindowGroup { NavigationStack(path: $router.navPath) { - HomeView(viewModel: TaskViewModel(router: router)) + HomeView(viewModel: viewModel) .navigationDestination(for: Router.Destination.self) { destination in switch destination { case .addTask: - AddTaskView(viewModel: TaskViewModel(router: router)) + AddTaskView(viewModel: viewModel) + case .aboutPage: - AboutPageView(viewModel: TaskViewModel(router: router)) + AboutPageView(viewModel: viewModel) case .allTasks: - AllTasksView(viewModel: TaskViewModel(router: router)) + AllTasksView(viewModel: viewModel) + + case .home: + HomeView(viewModel: viewModel) } } } diff --git a/TaskManager/Views/AboutPageView.swift b/TaskManager/Views/AboutPageView.swift index 4ffd76a..d349065 100644 --- a/TaskManager/Views/AboutPageView.swift +++ b/TaskManager/Views/AboutPageView.swift @@ -12,13 +12,7 @@ struct AboutPageView: View { var body: some View { VStack { - HStack { - Image("LogoImage") - .resizable() - .scaledToFit() - .frame(width: 200, height: 100) - } - .padding(.top) + LogoImage() Text("This is ToTask!") .modifier(TextStyles.descriptionStyle()) @@ -69,23 +63,10 @@ struct AboutPageView: View { Spacer() // Add Task Button - Button { - viewModel.navigateAddTask() - } label: { - Image(systemName: "plus.circle") - .font(.system(size: Spacing.large, weight: .bold)) - .foregroundColor(Color("DarkestPurple")) - Text("Add Task") - .font(Font.custom("NotoSansOriya", size: Spacing.medium)) - .foregroundColor(Color("DarkestPurple")) - .baselineOffset(-5) - } - .padding(12.0) - .background(Color.cPink) - .cornerRadius(Spacing.medium) + AddTaskButton(action: viewModel.navigateAddTask, title: "Add Task") } - .padding(.horizontal, 20.0) - .padding(.bottom, 20.0) + .padding(.horizontal, Spacing.medium) + .padding(.bottom, Spacing.medium) } .padding(10.0) @@ -93,7 +74,3 @@ struct AboutPageView: View { } } - -// #Preview { -// AboutPageView() -// } diff --git a/TaskManager/Views/AddTaskView.swift b/TaskManager/Views/AddTaskView.swift index 25e8c11..d1d46a4 100644 --- a/TaskManager/Views/AddTaskView.swift +++ b/TaskManager/Views/AddTaskView.swift @@ -6,23 +6,15 @@ import SwiftUI struct AddTaskView: View { + @EnvironmentObject var router: Router @ObservedObject var viewModel: TaskViewModel + // might need to pass task list from this view back to home + var body: some View { NavigationView { VStack { - // Image and back arrow - HStack { - Image(systemName: "arrow.left") - .font(.system(size: Spacing.big, weight: .bold)) - .foregroundColor(Color("Purple2")) - - Image("LogoImage") - .resizable() - .scaledToFit() - .frame(width: 200, height: 100) - } - .padding(.top) + LogoImage() // Entered text section VStack(alignment: .leading) { @@ -86,6 +78,17 @@ struct AddTaskView: View { .cornerRadius(Spacing.medium) }) + Button { + router.navigate(to: .home) + } label: { + Text("Back to Home") + .font(Font.custom("NotoSansOriya", size: Spacing.medium)) + .foregroundColor(Color.cPink) + .padding(Spacing.standard) + .background(Color("DarkestPurple")) + .cornerRadius(Spacing.medium) + } + // Delete Button Button(action: { viewModel.emptyTaskListArray() @@ -112,7 +115,3 @@ struct AddTaskView: View { } } } - -// #Preview { -// AddTaskView() -// } diff --git a/TaskManager/Views/AllTasksView.swift b/TaskManager/Views/AllTasksView.swift index 98c20d9..ee913ae 100644 --- a/TaskManager/Views/AllTasksView.swift +++ b/TaskManager/Views/AllTasksView.swift @@ -13,94 +13,39 @@ struct AllTasksView: View { var body: some View { ScrollView { VStack { - // if !task.isComplete { + LogoImage() + TaskCardView(viewModel: viewModel, title: "Task 1", category: .school, description: "This is a task", dueDate: Date()) - // } - Spacer() - } - } - .padding(10.0) - .background(Color("Cream")) - } + .padding(.bottom, Spacing.medium) -} - -struct TaskCardView: View { - @ObservedObject var viewModel: TaskViewModel - let title: String - let category: Category - let description: String? - let dueDate: Date - // var isComplete: Bool + TaskCardView(viewModel: viewModel, title: "Task 2", + category: .work, description: "This is another task", dueDate: Date()) + Spacer() - var body: some View { - HStack { - VStack(alignment: .leading) { - HStack { - Text(title) + // testing showing task list + if viewModel.taskList.isEmpty { + Text("No tasks to display") .font(.custom("Gill Sans", size: Spacing.medium)) .foregroundColor(Color("DarkPurple")) - .padding(.bottom, 4) - Spacer() - Text(category.rawValue) - .font(.custom("Gill Sans", size: Spacing.small)) - .foregroundColor(Color("DarkPurple")) - .padding(.horizontal, 16) - .padding(.vertical, 8) - .background(Color("CPink")) - .cornerRadius(25) - } - .padding(.trailing, Spacing.small) - - Text(description ?? "") - .font(.custom("Gill Sans", size: Spacing.standard)) - .foregroundColor(Color("DarkPurple")) - .padding(.bottom, 6.0) - - Text(dueDate.formatted(date: .abbreviated, time: .omitted)) - .font(.custom("Gill Sans", size: 13)) - .foregroundColor(Color("DarkPurple")) - .padding(.bottom, Spacing.small) - - HStack { - // complete button - Button { - viewModel.navigateAddTask() - } label: { - Image(systemName: "checkmark.circle") - .font(.system(size: Spacing.medium, weight: .bold)) - .foregroundColor(Color("CPink")) - Text("Complete?") - .font(.custom("Gill Sans", size: Spacing.standard)) - .foregroundColor(Color("DarkPurple")) - } - Spacer() - - // update button - Button { - viewModel.navigateAddTask() - } label: { - Image(systemName: "pencil.circle") - .font(.system(size: Spacing.medium, weight: .bold)) - .foregroundColor(Color("CPink")) - Text("Update?") - .font(.custom("Gill Sans", size: Spacing.standard)) - .foregroundColor(Color("DarkPurple")) + } else { + ForEach(viewModel.taskList.indices, id: \.self) { index in + TaskCardView(viewModel: viewModel, title: viewModel.taskList[index].title, + category: viewModel.taskList[index].category, + description: viewModel.taskList[index].description, + dueDate: viewModel.taskList[index].dueDate) } } - .padding([.bottom, .trailing], Spacing.standard) + ForEach(viewModel.taskList, id: \.title) { task in + Text(task.title) + Text(task.description ?? "No Description") + Text(task.category.rawValue) + Text(task.dueDate, style: .date) + } } - .padding(.leading, Spacing.standard) - Spacer() - } - .padding(.top, 10.0) - .background(Color("Cream")) - .overlay( - RoundedRectangle(cornerRadius: Spacing.small) - .stroke(Color("Purple3"), lineWidth: 1) - ) + .padding(Spacing.small) + .background(Color("Rose")) } } diff --git a/TaskManager/Views/HomeView.swift b/TaskManager/Views/HomeView.swift index 5c9951a..c807b69 100644 --- a/TaskManager/Views/HomeView.swift +++ b/TaskManager/Views/HomeView.swift @@ -13,11 +13,7 @@ struct HomeView: View { var body: some View { VStack { - // Logo - Image("LogoImage") - .resizable() - .scaledToFit() - .frame(width: 200, height: 100) + LogoImage() // Welcome Text VStack(alignment: .leading) { @@ -38,71 +34,22 @@ struct HomeView: View { Spacer() // Card - HStack { - VStack(alignment: .leading) { - HStack { - Text(viewModel.task1.title) - .font(.custom("Gill Sans", size: Spacing.medium)) - .foregroundColor(Color("DarkPurple")) - .padding(.bottom, 4) - Spacer() - Text(viewModel.task1.category.rawValue) - .font(.custom("Gill Sans", size: Spacing.small)) - .foregroundColor(Color("DarkPurple")) - .padding(.horizontal, 16) - .padding(.vertical, 8) - .background(Color("CPink")) - .cornerRadius(25) - } - .padding(.trailing, Spacing.small) - - Text(viewModel.task1.description ?? "") - .font(.custom("Gill Sans", size: Spacing.standard)) - .foregroundColor(Color("DarkPurple")) - .padding(.bottom, 6.0) - - Text(viewModel.task1.dueDate.formatted(date: .abbreviated, time: .omitted)) - .font(.custom("Gill Sans", size: 13)) - .foregroundColor(Color("DarkPurple")) - .padding(.bottom, Spacing.small) - - HStack { - Button { - viewModel.navigateAddTask() - } label: { - Image(systemName: "checkmark.circle") - .font(.system(size: Spacing.medium, weight: .bold)) - .foregroundColor(Color("CPink")) - Text("Complete?") - .font(.custom("Gill Sans", size: Spacing.standard)) - .foregroundColor(Color("DarkPurple")) - } - Spacer() - - Button { - viewModel.navigateAddTask() - } label: { - Image(systemName: "pencil.circle") - .font(.system(size: Spacing.medium, weight: .bold)) - .foregroundColor(Color("CPink")) - Text("Update?") - .font(.custom("Gill Sans", size: Spacing.standard)) - .foregroundColor(Color("DarkPurple")) - } - } - .padding([.bottom, .trailing], Spacing.standard) - + TaskCardView(viewModel: viewModel, title: viewModel.task1.title, + category: viewModel.task1.category, description: viewModel.task1.description, + dueDate: viewModel.task1.dueDate) + + if viewModel.taskList.isEmpty { + Text("No tasks to display") + .font(.custom("Gill Sans", size: Spacing.medium)) + .foregroundColor(Color("DarkPurple")) + } else { + ForEach(viewModel.taskList.indices, id: \.self) { index in + TaskCardView(viewModel: viewModel, title: viewModel.taskList[index].title, + category: viewModel.taskList[index].category, + description: viewModel.taskList[index].description, + dueDate: viewModel.taskList[index].dueDate) } - .padding(.leading, Spacing.standard) - Spacer() - } - .padding(.top, 10.0) - .background(Color("Cream")) - .overlay( - RoundedRectangle(cornerRadius: Spacing.small) - .stroke(Color("Purple3"), lineWidth: 1) - ) Spacer() @@ -121,30 +68,22 @@ struct HomeView: View { Spacer() // Add Task Button - Button { - router.navigate(to: .addTask) - } label: { - Image(systemName: "plus.circle") - .font(.system(size: Spacing.large, weight: .bold)) - .foregroundColor(Color("DarkestPurple")) - Text("Add Task") - .font(Font.custom("NotoSansOriya", size: Spacing.medium)) - .foregroundColor(Color("DarkestPurple")) - .baselineOffset(-5) - } - .padding(12.0) - .background(Color.cPink) - .cornerRadius(Spacing.medium) + AddTaskButton(action: viewModel.navigateAddTask, title: "Add Task") + + } + // about page button + Button("About Page") { + router.navigate(to: .aboutPage) } Spacer() } Spacer() } - .padding(15) + .padding(Spacing.standard) .background(Color("Rose")) + .onAppear { + print("HomeView appeared, task list count: \(viewModel.taskList.count)") + } } -} -// #Preview { -// HomeView() -// } +} diff --git a/TaskManager/Views/TemplateViews.swift b/TaskManager/Views/TemplateViews.swift new file mode 100644 index 0000000..909e9d0 --- /dev/null +++ b/TaskManager/Views/TemplateViews.swift @@ -0,0 +1,118 @@ +// +// TemplateViews.swift +// TaskManager +// +// Created by Isabella Sulisufi on 03/01/2025. +// + +import SwiftUI + +struct LogoImage: View { + var body: some View { + Image("LogoImage") + .resizable() + .scaledToFit() + .frame(width: 200, height: 100) + } +} + +struct AddTaskButton: View { + let action: () -> Void + let title: String + + var body: some View { + Button { + action() + } label: { + Image(systemName: "plus.circle") + .font(.system(size: Spacing.large, weight: .bold)) + .foregroundColor(Color("DarkestPurple")) + Text(title) + .font(Font.custom("NotoSansOriya", size: Spacing.medium)) + .foregroundColor(Color("DarkestPurple")) + .baselineOffset(-5) + } + .padding(Spacing.small) + .background(Color.cPink) + .cornerRadius(Spacing.medium) + } +} + +struct TaskCardView: View { + @ObservedObject var viewModel: TaskViewModel + let title: String + let category: Category + let description: String? + let dueDate: Date + // var isComplete: Bool + + var body: some View { + HStack { + VStack(alignment: .leading) { + HStack { + Text(title) + .font(.custom("Gill Sans", size: Spacing.medium)) + .foregroundColor(Color("DarkPurple")) + .padding(.bottom, Spacing.micro) + Spacer() + Text(category.rawValue) + .font(.custom("Gill Sans", size: Spacing.standard)) + .foregroundColor(Color("DarkPurple")) + .padding(.horizontal, Spacing.standard) + .padding(.vertical, Spacing.tiny) + .background(Color("CPink")) + .cornerRadius(Spacing.spacious) + } + .padding(.trailing, Spacing.small) + + Text(description ?? "") + .font(.custom("Gill Sans", size: Spacing.standard)) + .foregroundColor(Color("DarkPurple")) + .padding(.bottom, 6.0) + + Text(dueDate.formatted(date: .abbreviated, time: .omitted)) + .font(.custom("Gill Sans", size: Spacing.standard)) + .foregroundColor(Color("DarkPurple")) + .padding(.bottom, Spacing.small) + + HStack { + // complete button + Button { + viewModel.emptyTaskListArray() + } label: { + Image(systemName: "checkmark.circle") + .font(.system(size: Spacing.medium, weight: .bold)) + .foregroundColor(Color("CPink")) + Text("Complete?") + .font(.custom("Gill Sans", size: Spacing.standard)) + .foregroundColor(Color("DarkPurple")) + } + Spacer() + + // update button + Button { + viewModel.navigateAddTask() + } label: { + Image(systemName: "pencil.circle") + .font(.system(size: Spacing.medium, weight: .bold)) + .foregroundColor(Color("CPink")) + Text("Update?") + .font(.custom("Gill Sans", size: Spacing.standard)) + .foregroundColor(Color("DarkPurple")) + } + } + .padding([.bottom, .trailing], Spacing.standard) + + } + .padding(.leading, Spacing.standard) + Spacer() + + } + .padding(.top, Spacing.small) + .background(Color("Cream")) + .overlay( + RoundedRectangle(cornerRadius: Spacing.small) + .stroke(Color("Purple3"), lineWidth: 1) + ) + } +}