Skip to content

Commit

Permalink
Add navigation to the app
Browse files Browse the repository at this point in the history
  • Loading branch information
IsabellaSulisufi committed Oct 31, 2024
1 parent 054224d commit fe38626
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 81 deletions.
8 changes: 4 additions & 4 deletions TaskManager.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -23,10 +23,10 @@
/* Begin PBXFileReference section */
EE00D2BB2C6F8D65004FF048 /* TaskViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskViewModel.swift; sourceTree = "<group>"; };
EE019E172C9460C600A8B764 /* TaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskModel.swift; sourceTree = "<group>"; };
EE3AE1702CC69970001A80C1 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
EE4BB9C62B88F49F00FFF4F2 /* TextStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextStyles.swift; sourceTree = "<group>"; };
EE59B6B32C342680003D59DF /* AboutPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutPageView.swift; sourceTree = "<group>"; };
EE996DF02B88E1EE0036470C /* Spacing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Spacing.swift; sourceTree = "<group>"; };
EEA7106B2C90808600785086 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
EEA7106D2C908CA000785086 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
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 = "<group>"; };
Expand All @@ -49,7 +49,6 @@
EE019E152C94604D00A8B764 /* Views */ = {
isa = PBXGroup;
children = (
EEA7106B2C90808600785086 /* MainView.swift */,
EE59B6B32C342680003D59DF /* AboutPageView.swift */,
EED772142B7BC0C6007BDA4A /* AddTaskView.swift */,
EEA7106D2C908CA000785086 /* HomeView.swift */,
Expand Down Expand Up @@ -100,6 +99,7 @@
EE996DF02B88E1EE0036470C /* Spacing.swift */,
EED772162B7BC0C8007BDA4A /* Assets.xcassets */,
EED772182B7BC0C8007BDA4A /* Preview Content */,
EE3AE1702CC69970001A80C1 /* Router.swift */,
);
path = TaskManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down
30 changes: 30 additions & 0 deletions TaskManager/Router.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
14 changes: 13 additions & 1 deletion TaskManager/TaskManagerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
25 changes: 13 additions & 12 deletions TaskManager/ViewModel/TaskViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import SwiftUI

class TaskViewModel: ObservableObject {


@Published var taskList: [Task] = []

Check failure on line 12 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 12 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
@Published var selectedDate: Date = Date()
Expand All @@ -20,10 +18,14 @@ class TaskViewModel: ObservableObject {
@Published var taskTitle: String = ""
@Published var taskDescription: String = ""

Check failure on line 20 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 20 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var router: Router

Check failure on line 22 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 22 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
init(router: Router) {
self.router = router
}

Check failure on line 26 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 26 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var dropdownOptions = Category.allCases.map { $0.rawValue }

Check failure on line 28 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 28 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

var task1 = Task(
title: "Science homework",
description: "Biology presentation on anatomy",
Expand All @@ -33,7 +35,6 @@ class TaskViewModel: ObservableObject {
isComplete: false
)


func emptyTaskListArray() {
taskList.removeAll()
print(taskList)
Expand All @@ -54,13 +55,13 @@ class TaskViewModel: ObservableObject {

Check failure on line 55 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 55 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func handleButtonToggle() {
isTaskComplete.toggle()

}

Check failure on line 59 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func navigateToViewAllTasks() {
router.navigate(to: .aboutPage)
}

Check failure on line 63 in TaskManager/ViewModel/TaskViewModel.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func navigateAddTask() {
router.navigate(to: .addTask)
}
}


//@Published var message: String = ""

//check if tasks array is empty
//if it is then
//message =
18 changes: 10 additions & 8 deletions TaskManager/Views/AboutPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import SwiftUI

struct AboutPageView: View {
@ObservedObject var viewModel: TaskViewModel

var body: some View {

VStack {
Expand Down Expand Up @@ -60,8 +62,8 @@ struct AboutPageView: View {

// View All Tasks Button

NavigationLink {
AddTaskView()
Button {
viewModel.navigateAddTask()

} label: {
Text("View All Tasks")
Expand All @@ -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))
Expand All @@ -106,6 +108,6 @@ struct AboutPageView: View {
}
}

#Preview {
AboutPageView()
}
//#Preview {
// AboutPageView()
//}
10 changes: 5 additions & 5 deletions TaskManager/Views/AddTaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import SwiftUI

struct AddTaskView: View {
@ObservedObject var viewModel = TaskViewModel()
@ObservedObject var viewModel: TaskViewModel

var body: some View {

NavigationView {
Expand Down Expand Up @@ -120,6 +120,6 @@ struct AddTaskView: View {
}


#Preview {
AddTaskView()
}
//#Preview {
// AddTaskView()
//}
58 changes: 45 additions & 13 deletions TaskManager/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -98,22 +99,53 @@ 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()
}
}
.padding(15)
.background(Color("Rose"))
Spacer()
}

}

#Preview {
HomeView()
}
//#Preview {
// HomeView()
//}
38 changes: 0 additions & 38 deletions TaskManager/Views/MainView.swift

This file was deleted.

0 comments on commit fe38626

Please sign in to comment.