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

Added UI for saved events - Solved #603 #610

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
182 changes: 157 additions & 25 deletions HackIllinois/ViewControllers/HIScheduleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ extension HIScheduleViewController {
super.viewDidLoad()
guard let user = HIApplicationStateController.shared.user else { return }
if !user.roles.contains(.STAFF) {
super.setCustomTitle(customTitle: "SCHEDULE")
} else if user.roles.contains(.STAFF) {
setStaffShiftsControl()
}
// Non-staff
super.setCustomTitle(customTitle: "SCHEDULE") // This is optional if you want a big title
setScheduleSavedControl() // <--- Add this
} else {
// Staff
setStaffShiftsControl()
}
}
}

Expand All @@ -206,29 +209,65 @@ extension HIScheduleViewController {
let customFontSize = UIDevice.current.userInterfaceIdiom == .pad ? 48 : 24
let customFont = UIFont(name: "MontserratRoman-Bold", size: CGFloat(customFontSize))

// Create flexible space items to add space to the left
let flexibleSpaceLeft1 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let flexibleSpaceLeft2 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let flexibleSpaceLeft3 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

let scheduleButton = UIBarButtonItem(title: "SCHEDULE", style: .plain, target: self, action: #selector(scheduleButtonTapped(_:)))
scheduleButton.setTitleTextAttributes([NSAttributedString.Key.font: customFont, NSAttributedString.Key.foregroundColor: labelColor], for: .normal)

// Add the flexible space items and custom button to the leftBarButtonItems array
navigationItem.leftBarButtonItems = [flexibleSpaceLeft1, flexibleSpaceLeft2, flexibleSpaceLeft3, scheduleButton]

// Create flexible space items to add space to the right
let flexibleSpaceRight1 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let flexibleSpaceRight2 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

// Create custom right bar button item
let customButton = UIBarButtonItem(title: "SHIFTS", style: .plain, target: self, action: #selector(shiftsButtonTapped(_:)))
customButton.setTitleTextAttributes([NSAttributedString.Key.font: customFont, NSAttributedString.Key.foregroundColor: labelColor], for: .normal)
// 1) Create a container view
let containerView = UIView()
containerView.translatesAutoresizingMaskIntoConstraints = false

// 2) Create a stack view
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.alignment = .center
stackView.distribution = .equalSpacing
stackView.spacing = 8
stackView.translatesAutoresizingMaskIntoConstraints = false

// 3) "SCHEDULE" button (for staff)
let scheduleButton = UIButton(type: .system)
scheduleButton.setTitle("SCHEDULE", for: .normal)
scheduleButton.titleLabel?.font = customFont
scheduleButton.setTitleColor(labelColor, for: .normal)
scheduleButton.addTarget(self,
action: #selector(scheduleButtonTapped(_:)),
for: .touchUpInside)

// 4) "SHIFTS" button
let shiftsButton = UIButton(type: .system)
shiftsButton.setTitle("SHIFTS", for: .normal)
shiftsButton.titleLabel?.font = customFont
shiftsButton.setTitleColor(labelColor, for: .normal)
shiftsButton.addTarget(self,
action: #selector(shiftsButtonTapped(_:)),
for: .touchUpInside)

// 5) Add them to the stack
stackView.addArrangedSubview(scheduleButton)
stackView.addArrangedSubview(shiftsButton)

// 6) Add the stack to the container
containerView.addSubview(stackView)

// 7) Constrain the stackView inside the container
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: containerView.topAnchor),
stackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
stackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 40),
stackView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -40)
])

// 8) Match nav bar width & height
if let navBarWidth = navigationController?.navigationBar.frame.size.width {
containerView.widthAnchor.constraint(equalToConstant: navBarWidth).isActive = true
} else {
containerView.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width).isActive = true
}
containerView.heightAnchor.constraint(equalToConstant: 44).isActive = true

// Add the flexible space items and custom button to the rightBarButtonItems array
navigationItem.rightBarButtonItems = [flexibleSpaceRight1, flexibleSpaceRight2, customButton]
// 9) Assign as the titleView
navigationItem.titleView = containerView

self.navigationItem.leftItemsSupplementBackButton = true
// 10) Clear out old bar button items
navigationItem.leftBarButtonItems = nil
navigationItem.rightBarButtonItems = nil
}

func removeStaffShiftContainerViews() {
Expand Down Expand Up @@ -420,6 +459,99 @@ extension HIScheduleViewController {
}
}

// MARK: - Non-Staff Schedule/Saved Control Setup
extension HIScheduleViewController {
@objc func setScheduleSavedControl() {
let customFontSize = UIDevice.current.userInterfaceIdiom == .pad ? 48 : 24
let customFont = UIFont(name: "MontserratRoman-Bold", size: CGFloat(customFontSize))

// 1) Create a container view
let container = UIView()
container.translatesAutoresizingMaskIntoConstraints = false

// 2) Create a UIStackView
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.alignment = .center
// .equalSpacing ensures the space between buttons is uniform,
// but we'll also control left/right edges with constraints.
stackView.distribution = .equalSpacing
stackView.spacing = 8
stackView.translatesAutoresizingMaskIntoConstraints = false

// 3) Create the "SCHEDULE" button
let scheduleButton = UIButton(type: .system)
scheduleButton.setTitle("SCHEDULE", for: .normal)
scheduleButton.titleLabel?.font = customFont
scheduleButton.setTitleColor(labelColor, for: .normal)
scheduleButton.addTarget(self, action: #selector(scheduleButtonTappedForNonStaff(_:)), for: .touchUpInside)

// 4) Create the "SAVED" button
let savedButton = UIButton(type: .system)
savedButton.setTitle("SAVED", for: .normal)
savedButton.titleLabel?.font = customFont
savedButton.setTitleColor(labelColor, for: .normal)
savedButton.addTarget(self, action: #selector(savedButtonTappedForNonStaff(_:)), for: .touchUpInside)

// 5) Add buttons to the stack
stackView.addArrangedSubview(scheduleButton)
stackView.addArrangedSubview(savedButton)

// 6) Add the stack to the container
container.addSubview(stackView)

// Constrain the stackView to the container with equal insets on left & right
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: container.topAnchor),
stackView.bottomAnchor.constraint(equalTo: container.bottomAnchor),
// 40-pt “padding” on each side from container edges
stackView.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 40),
stackView.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -40)
])

// 7) Size the container to match nav bar width & typical height
if let navBarWidth = navigationController?.navigationBar.frame.size.width {
container.widthAnchor.constraint(equalToConstant: navBarWidth).isActive = true
} else {
// fallback to screen width if the nav bar size isn’t set yet
container.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width).isActive = true
}
// Typical nav bar height is ~44 for iPhone; you can adjust as needed
container.heightAnchor.constraint(equalToConstant: 44).isActive = true

// 8) Assign our container as the navigationItem.titleView
navigationItem.titleView = container

// 9) Clear any leftover bar button items on the edges
navigationItem.leftBarButtonItems = nil
navigationItem.rightBarButtonItems = nil
}

@objc func scheduleButtonTappedForNonStaff(_ sender: UIButton) {
// Similar logic, but for non-staff
if onlyFavorites {
onlyFavorites = false
backgroundView.image = #imageLiteral(resourceName: "ScheduleBackground")
labelColor = .white
setScheduleSavedControl()
updatePredicate()
animateReload()
}
}

@objc func savedButtonTappedForNonStaff(_ sender: UIButton) {
if !onlyFavorites {
onlyFavorites = true
backgroundView.image = #imageLiteral(resourceName: "ScheduleBackground") // Or a custom "Saved" background
labelColor = .white
setScheduleSavedControl()
updatePredicate()
animateReload()
}
}
}



// MARK: - UINavigationItem Setup
extension HIScheduleViewController {
Expand Down
Loading