diff --git a/TaskManager.xcodeproj/project.pbxproj b/TaskManager.xcodeproj/project.pbxproj index 6253905..8cff047 100644 --- a/TaskManager.xcodeproj/project.pbxproj +++ b/TaskManager.xcodeproj/project.pbxproj @@ -9,10 +9,10 @@ /* 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 */; }; + 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 */; }; EE996DF12B88E1EE0036470C /* Spacing.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE996DF02B88E1EE0036470C /* Spacing.swift */; }; - EEA7106C2C90808600785086 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEA7106B2C90808600785086 /* MainView.swift */; }; EEA7106E2C908CA000785086 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEA7106D2C908CA000785086 /* HomeView.swift */; }; EED772132B7BC0C6007BDA4A /* TaskManagerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = EED772122B7BC0C6007BDA4A /* TaskManagerApp.swift */; }; EED772152B7BC0C6007BDA4A /* AddTaskView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EED772142B7BC0C6007BDA4A /* AddTaskView.swift */; }; @@ -23,10 +23,10 @@ /* 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 = ""; }; + 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 = ""; }; EE996DF02B88E1EE0036470C /* Spacing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Spacing.swift; sourceTree = ""; }; - EEA7106B2C90808600785086 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = ""; }; EEA7106D2C908CA000785086 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = ""; }; EED7720F2B7BC0C6007BDA4A /* TaskManager.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TaskManager.app; sourceTree = BUILT_PRODUCTS_DIR; }; EED772122B7BC0C6007BDA4A /* TaskManagerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskManagerApp.swift; sourceTree = ""; }; @@ -49,7 +49,6 @@ EE019E152C94604D00A8B764 /* Views */ = { isa = PBXGroup; children = ( - EEA7106B2C90808600785086 /* MainView.swift */, EE59B6B32C342680003D59DF /* AboutPageView.swift */, EED772142B7BC0C6007BDA4A /* AddTaskView.swift */, EEA7106D2C908CA000785086 /* HomeView.swift */, @@ -100,6 +99,7 @@ EE996DF02B88E1EE0036470C /* Spacing.swift */, EED772162B7BC0C8007BDA4A /* Assets.xcassets */, EED772182B7BC0C8007BDA4A /* Preview Content */, + EE3AE1702CC69970001A80C1 /* Router.swift */, ); path = TaskManager; sourceTree = ""; @@ -184,13 +184,13 @@ files = ( EEA7106E2C908CA000785086 /* HomeView.swift in Sources */, EE59B6B42C342680003D59DF /* AboutPageView.swift in Sources */, + EE3AE1712CC69970001A80C1 /* Router.swift in Sources */, EE00D2BC2C6F8D65004FF048 /* TaskViewModel.swift in Sources */, EE019E182C9460C600A8B764 /* TaskModel.swift in Sources */, EED772152B7BC0C6007BDA4A /* AddTaskView.swift in Sources */, EE4BB9C72B88F49F00FFF4F2 /* TextStyles.swift in Sources */, EED772132B7BC0C6007BDA4A /* TaskManagerApp.swift in Sources */, EE996DF12B88E1EE0036470C /* Spacing.swift in Sources */, - EEA7106C2C90808600785086 /* MainView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TaskManager/Router.swift b/TaskManager/Router.swift new file mode 100644 index 0000000..74e9c3f --- /dev/null +++ b/TaskManager/Router.swift @@ -0,0 +1,30 @@ +// +// Router.swift +// TaskManager +// +// Created by Isabella Sulisufi on 21/10/2024. +// + +import SwiftUI + +final class Router: ObservableObject { + + public enum Destination: Codable, Hashable { + case addTask + case aboutPage + } + + @Published var navPath = NavigationPath() + + func navigate(to destination: Destination) { + navPath.append(destination) + } + + func navigateBack() { + navPath.removeLast() + } + + func navigateToRoot() { + navPath.removeLast(navPath.count) + } +} diff --git a/TaskManager/TaskManagerApp.swift b/TaskManager/TaskManagerApp.swift index 457f480..7d7c343 100644 --- a/TaskManager/TaskManagerApp.swift +++ b/TaskManager/TaskManagerApp.swift @@ -9,9 +9,21 @@ import SwiftUI @main struct TaskManagerApp: App { + @ObservedObject var router = Router() var body: some Scene { WindowGroup { - MainView() + NavigationStack(path: $router.navPath) { + HomeView(viewModel: TaskViewModel(router: router)) + .navigationDestination(for: Router.Destination.self) { destination in + switch destination { + case .addTask: + AddTaskView(viewModel: TaskViewModel(router: router)) + case .aboutPage: + AboutPageView(viewModel: TaskViewModel(router: router)) + } + } + } + .environmentObject(router) } } } diff --git a/TaskManager/ViewModel/TaskViewModel.swift b/TaskManager/ViewModel/TaskViewModel.swift index 8587278..73fdb69 100644 --- a/TaskManager/ViewModel/TaskViewModel.swift +++ b/TaskManager/ViewModel/TaskViewModel.swift @@ -8,8 +8,6 @@ import SwiftUI class TaskViewModel: ObservableObject { - - @Published var taskList: [Task] = [] @Published var selectedDate: Date = Date() @@ -20,10 +18,14 @@ class TaskViewModel: ObservableObject { @Published var taskTitle: String = "" @Published var taskDescription: String = "" + var router: Router + + init(router: Router) { + self.router = router + } var dropdownOptions = Category.allCases.map { $0.rawValue } - var task1 = Task( title: "Science homework", description: "Biology presentation on anatomy", @@ -33,7 +35,6 @@ class TaskViewModel: ObservableObject { isComplete: false ) - func emptyTaskListArray() { taskList.removeAll() print(taskList) @@ -54,13 +55,13 @@ class TaskViewModel: ObservableObject { func handleButtonToggle() { isTaskComplete.toggle() - + } + + func navigateToViewAllTasks() { + router.navigate(to: .aboutPage) + } + + func navigateAddTask() { + router.navigate(to: .addTask) } } - - -//@Published var message: String = "" - -//check if tasks array is empty -//if it is then -//message = diff --git a/TaskManager/Views/AboutPageView.swift b/TaskManager/Views/AboutPageView.swift index 9061c70..ce93624 100644 --- a/TaskManager/Views/AboutPageView.swift +++ b/TaskManager/Views/AboutPageView.swift @@ -8,6 +8,8 @@ import SwiftUI struct AboutPageView: View { + @ObservedObject var viewModel: TaskViewModel + var body: some View { VStack { @@ -60,8 +62,8 @@ struct AboutPageView: View { // View All Tasks Button - NavigationLink { - AddTaskView() + Button { + viewModel.navigateAddTask() } label: { Text("View All Tasks") @@ -77,9 +79,9 @@ struct AboutPageView: View { //Add Task Button - NavigationLink { - AddTaskView() - + Button { + viewModel.navigateAddTask() + } label: { Image(systemName: "plus.circle") .font(.system(size: Spacing.large, weight: .bold)) @@ -106,6 +108,6 @@ struct AboutPageView: View { } } -#Preview { - AboutPageView() -} +//#Preview { +// AboutPageView() +//} diff --git a/TaskManager/Views/AddTaskView.swift b/TaskManager/Views/AddTaskView.swift index 99a11b2..eaf9629 100644 --- a/TaskManager/Views/AddTaskView.swift +++ b/TaskManager/Views/AddTaskView.swift @@ -6,8 +6,8 @@ import SwiftUI struct AddTaskView: View { - @ObservedObject var viewModel = TaskViewModel() - + @ObservedObject var viewModel: TaskViewModel + var body: some View { NavigationView { @@ -120,6 +120,6 @@ struct AddTaskView: View { } -#Preview { - AddTaskView() -} +//#Preview { +// AddTaskView() +//} diff --git a/TaskManager/Views/HomeView.swift b/TaskManager/Views/HomeView.swift index dc2b5f1..a7e6c21 100644 --- a/TaskManager/Views/HomeView.swift +++ b/TaskManager/Views/HomeView.swift @@ -8,18 +8,19 @@ import SwiftUI struct HomeView: View { - - @ObservedObject var viewModel = TaskViewModel() + @ObservedObject var viewModel: TaskViewModel + @EnvironmentObject var router: Router var body: some View { VStack { + //Logo Image("LogoImage") .resizable() .scaledToFit() .frame(width: 200, height: 100) + + //Welcome Text VStack(alignment: .leading) { - - Text("Hi, Welcome Back!") .font(.custom("Gill Sans", size: Spacing.extensive)) .foregroundColor(Color("DarkPurple")) @@ -66,8 +67,8 @@ struct HomeView: View { .padding(.bottom, Spacing.small) HStack { - NavigationLink { - AddTaskView() + Button { + viewModel.navigateAddTask() } label: { Image(systemName: "checkmark.circle") .font(.system(size: Spacing.medium, weight: .bold)) @@ -78,8 +79,8 @@ struct HomeView: View { } Spacer() - NavigationLink { - AddTaskView() + Button { + viewModel.navigateAddTask() } label: { Image(systemName: "pencil.circle") .font(.system(size: Spacing.medium, weight: .bold)) @@ -98,12 +99,44 @@ struct HomeView: View { } .padding(.top, 10.0) - .background(Color("Cream")) .overlay( RoundedRectangle(cornerRadius: Spacing.small) .stroke(Color("Purple3"), lineWidth: 1) ) + + Spacer() + + //Buttons + HStack { + // View All Tasks Button + Button("View All Tasks") { + viewModel.navigateToViewAllTasks() + } + .font(Font.custom("NotoSansOriya", size: Spacing.medium)) + .foregroundColor(Color.cPink) + .padding(Spacing.standard) + .background(Color("DarkestPurple")) + .cornerRadius(Spacing.medium) + + 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) + } Spacer() } } @@ -111,9 +144,8 @@ struct HomeView: View { .background(Color("Rose")) Spacer() } - } -#Preview { - HomeView() -} +//#Preview { +// HomeView() +//} diff --git a/TaskManager/Views/MainView.swift b/TaskManager/Views/MainView.swift deleted file mode 100644 index d1ed104..0000000 --- a/TaskManager/Views/MainView.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// HomePageView.swift -// TaskManager -// -// Created by Isabella Sulisufi on 10/09/2024. -// - -import SwiftUI - -struct MainView: View { - var body: some View { - TabView { - HomeView() - .tabItem { - Label("Home", systemImage: "house") - } - - - AddTaskView() - .tabItem { - Label("Task List", systemImage: "list.bullet") - } - - - AboutPageView() - .tabItem { - Label("Help", systemImage: "questionmark") - } - } - } -} - - -#Preview { - MainView() -} - -