Skip to content
Open
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
6 changes: 3 additions & 3 deletions CoNet/Main/Home/CalendarDateFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import Foundation

class CalendarDateFormatter {
private var calendar = Calendar.current // Calendar 구조체를 현재 달력으로 초기화
private let dateFormatter = DateFormatter() // 원하는 String 타입으로 변화시켜줄 formatter
private var nowCalendarDate = Date() // 현재 시간
var calendar = Calendar.current // Calendar 구조체를 현재 달력으로 초기화
let dateFormatter = DateFormatter() // 원하는 String 타입으로 변화시켜줄 formatter
var nowCalendarDate = Date() // 현재 시간
private(set) var days = [String]() // 달력에 표시할 날짜를 담을 배열

init() {
Expand Down
29 changes: 27 additions & 2 deletions CoNet/Main/Home/CalendarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit

class CalendarViewController: UIViewController {
var meetingId = 0

var selectedDate: String?
// MARK: UIComponents

// 이전 달로 이동 버튼
Expand Down Expand Up @@ -76,7 +76,8 @@ class CalendarViewController: UIViewController {
format.dateFormat = "yyyy. MM"

// api 호출
getMonthPlanAPI(date: format.string(from: Date()))
getMonthPlanAPI(date: format.string(from: calendarDateFormatter.nowCalendarDate))

}

private func setupCollectionView() {
Expand Down Expand Up @@ -176,6 +177,22 @@ class CalendarViewController: UIViewController {

// api: 특정 달 약속 조회
getMonthPlanAPI(date: changedHeader)

// 캘린더에서 날짜 선택
selectDateOnCalendar()
}

func selectDateOnCalendar() {
if let selectedDate = selectedDate {
let dateComponents = selectedDate.split(separator: ".").map { String($0) }
if dateComponents.count == 3 {
let day = dateComponents[2]
if let index = calendarDateFormatter.days.firstIndex(of: day) {
let indexPath = IndexPath(item: index, section: 0)
calendarCollectionView.selectItem(at: indexPath, animated: false, scrollPosition: [])
}
}
}
}
}

Expand Down Expand Up @@ -207,6 +224,8 @@ extension CalendarViewController: UICollectionViewDataSource, UICollectionViewDe
// yyyy. MM. dd 형식
let clickDate = calendarDateFormatter.changeDateType(date: calendarDate) + calendarDay

selectedDate = clickDate

if let parentVC = parent {
if parentVC is HomeViewController {
// 부모 뷰컨트롤러가 HomeViewController
Expand Down Expand Up @@ -282,6 +301,12 @@ extension CalendarViewController: UICollectionViewDataSource, UICollectionViewDe
cell.reloadPlanMark()
}

// 셀의 날짜가 선택된 날짜와 일치하는지 확인
let cellDate = calendarDateFormatter.changeDateType(date: calendarDate) + calendarDateFormatter.formatNumberToTwoDigit(Int(cellDay) ?? 0)
if cellDate == selectedDate {
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: [])
}

return cell
}
}
Expand Down
17 changes: 15 additions & 2 deletions CoNet/Main/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class HomeViewController: UIViewController {
self.planNum.text = String(count)
self.dayPlanData = plans
self.dayPlanCollectionView.reloadData()
self.layoutConstraints()
self.updataPlanCollectionViewHeight()
}
}

Expand All @@ -143,7 +143,7 @@ class HomeViewController: UIViewController {
self.waitingPlanNum.text = String(count)
self.waitingPlanData = plans
self.waitingPlanCollectionView.reloadData()
self.layoutConstraints()
self.updataPlanCollectionViewHeight()
}
}

Expand Down Expand Up @@ -173,6 +173,19 @@ class HomeViewController: UIViewController {
dayPlanLabel.text = month + "월 " + day + "일의 약속"
}
}

// 높이 업데이트
func updataPlanCollectionViewHeight() {
let dayPlanHeight = (dayPlanData.count - 1) * 100 + 90
dayPlanCollectionView.snp.updateConstraints { make in
make.height.equalTo(dayPlanHeight)
}

let waitingPlanHeight = waitingPlanData.count * 100 - 1
waitingPlanCollectionView.snp.updateConstraints { make in
make.height.equalTo(waitingPlanHeight)
}
}
}

extension HomeViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
Expand Down
15 changes: 13 additions & 2 deletions CoNet/Main/Meeting/MeetingMain/MeetingMainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ class MeetingMainViewController: UIViewController {
format.locale = Locale(identifier: "ko_KR")
format.timeZone = TimeZone(abbreviation: "KST")

dayPlanAPI(date: format.string(from: Date()))
if let selectedDate = calendarVC.selectedDate {
dayPlanAPI(date: selectedDate)
} else {
dayPlanAPI(date: format.string(from: Date()))
}
}

override func viewWillDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -185,7 +189,7 @@ class MeetingMainViewController: UIViewController {
self.planNum.text = String(count)
self.dayPlanData = plans
self.dayPlanCollectionView.reloadData()
self.layoutContraints()
self.updataPlanCollectionViewHeight()
}
}

Expand Down Expand Up @@ -312,6 +316,13 @@ class MeetingMainViewController: UIViewController {

present(getMemberBottomSheet, animated: true, completion: nil)
}

func updataPlanCollectionViewHeight() {
let dayPlanHeight = dayPlanData.count * 80 - 1
dayPlanCollectionView.snp.updateConstraints { make in
make.height.equalTo(dayPlanHeight)
}
}
}

// 사이드바 화면 전환
Expand Down