From 98139b1e9c1747dcbc0cdffee2dfd27a247f3ac7 Mon Sep 17 00:00:00 2001 From: yungu0010 Date: Fri, 13 Jan 2023 16:50:11 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20#88=20-=20=ED=99=88=20=EB=B7=B0=20?= =?UTF-8?q?=ED=97=A4=EB=8D=94=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=BA=98?= =?UTF-8?q?=EB=A6=B0=EB=8D=94=20=EA=B0=92=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cells/HomeCollectionReusableView.swift | 10 ++-------- .../ViewControllers/HomeViewController.swift | 19 ++++++++++++++----- .../HomeScene/Views/HomeView.swift | 2 -- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift b/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift index aebf1d1..3703077 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCollectionReusableView.swift @@ -19,8 +19,7 @@ final class HomeCollectionReusableView: UICollectionReusableView { // MARK: - UI Components - private lazy var dateFormatter = DateFormatter() - private var dateLabel = UILabel() + var dateLabel = UILabel() private let dateView = UIView() private var motivationLabel = UILabel() private var graphicImageView = UIImageView() @@ -42,15 +41,10 @@ final class HomeCollectionReusableView: UICollectionReusableView { extension HomeCollectionReusableView { private func setUI() { backgroundColor = .nottodoWhite - dateFormatter.do { - $0.locale = Locale(identifier: "ko_KR") - $0.dateFormat = "YYYY년 M월" - $0.timeZone = TimeZone(identifier: "KST") - } dateLabel.do { $0.textColor = .nottodoBlack $0.font = .PretendardBold(size: 18.adjusted) - $0.text = "2023년 1월" // dateFormatter로 수정 +// $0.text = "2023년 1월" // dateFormatter로 수정 } dateView.backgroundColor = .yellow_basic motivationLabel.do { diff --git a/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift b/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift index 885620a..4951851 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift @@ -19,7 +19,9 @@ final class HomeViewController: UIViewController { var banner: BannerResponseDTO? var missionId: Int? private var clickedDay: String? - private let dateFormatter = DateFormatter() + private let todayDateFormatter = DateFormatter() + private let mothlyDateFormatter = DateFormatter() + private var currentPage: Date? = Date() // MARK: - UI Components @@ -44,7 +46,7 @@ final class HomeViewController: UIViewController { super.viewWillAppear(animated) requestBannerAPI() requestWeeklyMissoinAPI(startDate: "2023-01-23") - requestDailyMissionAPI(date: "2023-01-25") + requestDailyMissionAPI(date: clickedDay ?? "") } } @@ -73,10 +75,15 @@ extension HomeViewController: UICollectionViewDelegate { for: .valueChanged) } - dateFormatter.do { + todayDateFormatter.do { $0.locale = Locale(identifier: "ko_KR") $0.dateFormat = "yyyy-MM-dd" } + + mothlyDateFormatter.do { + $0.locale = Locale(identifier: "ko_KR") + $0.dateFormat = "yyyy년 M월" + } } private func setAddTarget() { @@ -152,7 +159,7 @@ extension HomeViewController: UICollectionViewDelegate { @objc func handleRefreshControl() { // 컨텐츠를 업데이트하세요. requestBannerAPI() - requestDailyMissionAPI(date: "2023-01-25") + requestDailyMissionAPI(date: clickedDay ?? "") homeView.homeCollectionView.reloadData() DispatchQueue.main.async { @@ -171,6 +178,7 @@ extension HomeViewController: UICollectionViewDataSource { case 0: guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeCalendarCollectionViewCell.identifier, for: indexPath) as? HomeCalendarCollectionViewCell else { return UICollectionViewCell() } cell.calendar.delegate = self + self.currentPage = cell.calendar.currentPage return cell default: if missionList.isEmpty { @@ -233,6 +241,7 @@ extension HomeViewController: UICollectionViewDataSource { withReuseIdentifier: HomeCollectionReusableView.identifier, for: indexPath ) as? HomeCollectionReusableView else { return UICollectionReusableView() } + header.dateLabel.text = mothlyDateFormatter.string(from: self.currentPage ?? Date()) if let banner = banner { header.setRandomData(banner: banner) } @@ -284,7 +293,7 @@ extension HomeViewController: UICollectionViewDelegateFlowLayout { extension HomeViewController: FSCalendarDelegate { func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { - clickedDay = dateFormatter.string(from: date) + clickedDay = todayDateFormatter.string(from: date) requestDailyMissionAPI(date: clickedDay ?? "") } } diff --git a/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift b/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift index 48ed7a1..cae9bf3 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/Views/HomeView.swift @@ -1,6 +1,5 @@ import UIKit -import FSCalendar import SnapKit import Then @@ -9,7 +8,6 @@ final class HomeView: UIView { // MARK: - UI Components lazy var homeCollectionView = UICollectionView(frame: .zero, collectionViewLayout: layout()) - var calendar = FSCalendar(frame: .zero) let addMissionButton = NotTodoButton(frame: CGRect(), mode: .withImage, text: I18N.addMissoinButton, image: .plus, font: .semiBold, size: 16) // MARK: - Life Cycle