Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add navigation to the app #15

Merged
merged 3 commits into from
Oct 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion SwiftUIView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SwiftUIView.swift
//
//
//
// Created by Isabella Sulisufi on 16/08/2024.
//
Expand Down
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
20 changes: 10 additions & 10 deletions TaskManager/Model/TaskModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

import Foundation

//struct TaskModel {
// struct TaskModel {
// var id: UUID = UUID()
// var title: String
// var description: String?
//
//
// var startDate: Date
// var dueDate: Date
//
//
// var category: Category
// var isCompleted: Bool
//
//

//}
// }

enum Category: String, CaseIterable {
case school = "School"
case work = "Work"
case personal = "Personal"
case fitness = "Fitness"
}
case school = "School"
case work = "Work"
case personal = "Personal"
case fitness = "Fitness"
}

struct Task {
let title: String
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)
}
}
24 changes: 12 additions & 12 deletions TaskManager/Spacing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
import SwiftUI

struct Spacing {

static let none: CGFloat = 0

static let micro: CGFloat = 4

static let tiny: CGFloat = 8

static let small: CGFloat = 12

static let standard: CGFloat = 16

static let medium: CGFloat = 20

static let considerable: CGFloat = 22

static let spacious: CGFloat = 24

static let large: CGFloat = 30

static let extensive: CGFloat = 32

static let big: CGFloat = 36

static let huge: CGFloat = 40
}
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)
}
}
}
16 changes: 7 additions & 9 deletions TaskManager/TextStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ struct TextStyles {
// Style for Titles
static func titleStyle() -> some ViewModifier {
return TextStyleModifier(font: .custom("Gill Sans", size: Spacing.large),
color: Color("DarkPurple"),
applyPadding: false)
color: Color("DarkPurple"),
applyPadding: false)
}

// Style for Descriptions
static func descriptionStyle() -> some ViewModifier {
return TextStyleModifier(font: .custom("Gill Sans", size: Spacing.spacious),
color: Color("DarkPurple"),
applyPadding: false)
color: Color("DarkPurple"),
applyPadding: false)
}

// Style for Bullet Points
static func bulletPointStyle() -> some ViewModifier {
return TextStyleModifier(font: .custom("Gill Sans", size: Spacing.considerable),
color: Color("DarkPurple"),
applyPadding: true)
color: Color("DarkPurple"),
applyPadding: true)
}

struct TextStyleModifier: ViewModifier {
Expand All @@ -42,5 +42,3 @@ struct TextStyles {
}
}
}


37 changes: 19 additions & 18 deletions TaskManager/ViewModel/TaskViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
import SwiftUI

class TaskViewModel: ObservableObject {


@Published var taskList: [Task] = []

@Published var selectedDate: Date = Date()
@Published var startDate: Date = Date()

@Published var selectedCategory: Category = .school
@Published var isTaskComplete: Bool = false
@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",
Expand All @@ -33,34 +35,33 @@ class TaskViewModel: ObservableObject {
isComplete: false
)


func emptyTaskListArray() {
taskList.removeAll()
print(taskList)
}

func addToTaskListArray() {
let newTask = Task(
title: taskTitle,
description: taskDescription,
startDate: startDate,
dueDate: selectedDate,
category:selectedCategory,
category: selectedCategory,
isComplete: isTaskComplete
)
taskList.append(newTask)
print(taskList)
}

func handleButtonToggle() {
isTaskComplete.toggle()

}
}


//@Published var message: String = ""
func navigateToViewAllTasks() {
router.navigate(to: .aboutPage)
}

//check if tasks array is empty
//if it is then
//message =
func navigateAddTask() {
router.navigate(to: .addTask)
}
}
Loading
Loading