Skip to content

Commit

Permalink
[FEAT] DO-NOTTO-DO#84 - 성취뷰 월간 캘린더
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongdung-eo committed Jan 13, 2023
1 parent 6a91a7b commit 8f54c5e
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 38 deletions.
8 changes: 8 additions & 0 deletions NotToDo/NotToDo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
099F0728296B94790036CF55 /* StatisticsEmptyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099F0727296B94790036CF55 /* StatisticsEmptyTableViewCell.swift */; };
099F072A296B98B90036CF55 /* SituationTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099F0729296B98B90036CF55 /* SituationTitleView.swift */; };
099F073D296C2F770036CF55 /* CustomSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099F073C296C2F770036CF55 /* CustomSegmentedControl.swift */; };
09AF3FD229719DD900518D52 /* String+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AF3FD129719DD900518D52 /* String+.swift */; };
09AF3FD429719E2200518D52 /* Date+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09AF3FD329719E2200518D52 /* Date+.swift */; };
09D3C535296FFD3500F1488D /* SituationStasticsResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C534296FFD3500F1488D /* SituationStasticsResponseDTO.swift */; };
09D3C538296FFD7C00F1488D /* AchieveAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C537296FFD7C00F1488D /* AchieveAPI.swift */; };
09D3C53D29700DC800F1488D /* AchieveService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D3C53C29700DC800F1488D /* AchieveService.swift */; };
Expand Down Expand Up @@ -171,6 +173,8 @@
099F0727296B94790036CF55 /* StatisticsEmptyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatisticsEmptyTableViewCell.swift; sourceTree = "<group>"; };
099F0729296B98B90036CF55 /* SituationTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SituationTitleView.swift; sourceTree = "<group>"; };
099F073C296C2F770036CF55 /* CustomSegmentedControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSegmentedControl.swift; sourceTree = "<group>"; };
09AF3FD129719DD900518D52 /* String+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+.swift"; sourceTree = "<group>"; };
09AF3FD329719E2200518D52 /* Date+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+.swift"; sourceTree = "<group>"; };
09D3C534296FFD3500F1488D /* SituationStasticsResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SituationStasticsResponseDTO.swift; sourceTree = "<group>"; };
09D3C537296FFD7C00F1488D /* AchieveAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchieveAPI.swift; sourceTree = "<group>"; };
09D3C53C29700DC800F1488D /* AchieveService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchieveService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -464,6 +468,8 @@
3B3405DD295B162600D44722 /* UITabBar+.swift */,
3BED5327295C018700157A3B /* adjust+.swift */,
3B5B34AB29618441002E1161 /* UIButton+.swift */,
09AF3FD129719DD900518D52 /* String+.swift */,
09AF3FD329719E2200518D52 /* Date+.swift */,
3B576323296403CB00E03637 /* UILabel+.swift */,
3B4187CE296D342900F0FBF4 /* UIViewController+.swift */,
3B882606296DDC0E00A51B50 /* UIDevice+.swift */,
Expand Down Expand Up @@ -1220,6 +1226,7 @@
3B162874295AD7860077AE7B /* AppDelegate.swift in Sources */,
3BEF92AF29686A8E0090A290 /* HomeCalendarCollectionViewCell.swift in Sources */,
096BE0172966A142009ED396 /* CustomTabBarCell.swift in Sources */,
09AF3FD429719E2200518D52 /* Date+.swift in Sources */,
3BE07017296F44D3002CC50A /* MyInfoViewController.swift in Sources */,
3B0155872971512C00E7BBF1 /* MissionCalendarDayCell.swift in Sources */,
3BE07006296F43A2002CC50A /* UIStackView+.swift in Sources */,
Expand All @@ -1244,6 +1251,7 @@
3BBE56E7296C214600771DE4 /* FirstOnboardingView.swift in Sources */,
09F695D9296C332D00877EA7 /* CompositionalLayout.swift in Sources */,
3B4B90C62965CB8D008C5CA8 /* myInfoUserCollectionViewCell.swift in Sources */,
09AF3FD229719DD900518D52 /* String+.swift in Sources */,
6C88260F2967D8280005E222 /* AddSituationCollectionViewCell.swift in Sources */,
3B59AFB8296346650050FF49 /* Numbers.swift in Sources */,
6CDC2D212966C86D00BFF5F4 /* AddMissionTextField.swift in Sources */,
Expand Down
17 changes: 17 additions & 0 deletions NotToDo/NotToDo/Global/Extensions/Date+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Date+.swift
// NotToDo
//
// Created by JEONGEUN KIM on 2023/01/13.
//

import Foundation

extension Date {
func toString() -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
return dateFormatter.string(from: self)
}
}
23 changes: 23 additions & 0 deletions NotToDo/NotToDo/Global/Extensions/String+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// String+.swift
// NotToDo
//
// Created by JEONGEUN KIM on 2023/01/13.
//

import Foundation

extension String {

func toDate() -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
if let date = dateFormatter.date(from: self) {
return date
} else {
return nil
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@ import Foundation
struct AchieveCalendarResponseDTO: Codable {
let actionDate: String
let count: Int

func toDate(dateString: String) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy.MM.dd"
dateFormatter.timeZone = TimeZone(identifier: "UTC")
if let date = dateFormatter.date(from: dateString) {
return date
} else {
return nil
}
}

func convert() -> [Date:Int] {
guard let date = self.toDate(dateString: actionDate) else { return [:]}
return [date:count]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class AchievementViewController: UIViewController {
situationView.isHidden = !self.missionView.isHidden
}
}


// MARK: - UI Components

Expand All @@ -42,12 +42,13 @@ final class AchievementViewController: UIViewController {
var missionList: [MissionStatistcsResponseDTO] = []
var dataSource: [String: Int] = [:]


// MARK: - View Life Cycle

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
requestAchieveAPI()
// requestMonthAPI(month: month)
requestMonthAPI(month: dateFormatter.string(from: calendarView.calendar.today!))
}

override func viewDidLoad() {
Expand Down Expand Up @@ -78,7 +79,7 @@ extension AchievementViewController {
$0.monthCalendarClosure = { [self] result in
let month = result
self.reloadMonthData(month: month)
}
}
$0.layer.borderWidth = 1
$0.layer.borderColor = UIColor.nottodoGray2?.cgColor
$0.calendar.delegate = self
Expand Down Expand Up @@ -120,7 +121,13 @@ extension AchievementViewController {
AchieveAPI.shared.getAchieveCalendar(month: month) { [self] result in
switch result {
case let .success(data):
guard data is [AchieveCalendarResponseDTO] else { return }
guard let data = data as? [AchieveCalendarResponseDTO] else { return }
self.dataSource = [:]
for item in data {
self.dataSource[item.actionDate] = item.count
}
calendarView.calendar.reloadData()

case .requestErr:
print("requestErr")
case .pathErr:
Expand Down Expand Up @@ -256,42 +263,24 @@ extension AchievementViewController: FSCalendarDelegate {

extension AchievementViewController: FSCalendarDataSource {

// 서버에서 넘어온 dateString이랑 이 메서드의 date를 잘 매칭시켜줘야 함
// date 매칭된 것에 맞게 데이터를 넘겨줘야 함
func calendar(_ calendar: FSCalendar, cellFor date: Date, at position: FSCalendarMonthPosition) -> FSCalendarCell {
let cell = calendar.dequeueReusableCell(withIdentifier: String(describing: MissionCalendarDayCell.self), for: date, at: position) as! MissionCalendarDayCell
// switch cell.state {
// case .none:
// return
// case .step1:
// return
// case .step2:
// return
// case .step3:
// return
// default:
// break
// }

// MARK: 서버에서 넘어온 값에 따라 셀 상태 변화시켜주기
// Date : Int(Enum)
/*
NotToDoCalendarCell에 가보면 Enum이 보일 것임
프로젝트 상황에 따라 적절하게 바꿔서 사용하기
현재는 5개의 case가 있음
- none, step1, step2, step3, bordered
case에 따라서 backgroundColor 변화시키는 식으로 구현되어 있는데 UI 디테일을 살리고 싶으면
그냥 case에 따라 이미지를 넣는 것이 더 쉬움
*/

// 캘린더 셀 설정해주는 코드 : CollectionViewCell이랑 동일하게 생각하면 됨
cell.configure(.step1)
if let count = self.dataSource[date.toString()] {
switch count {
case 0:
cell.configure(.none)
case 1:
cell.configure(.step1)
case 2:
cell.configure(.step2)
case 3:
cell.configure(.step3)
default:
cell.configure(.none)
}
}
return cell
}
}

extension AchievementViewController: FSCalendarDelegateAppearance {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CustomCalendar: UIView {
lazy var dateFormatter = DateFormatter()
var monthData: [AchieveCalendarResponseDTO] = []
var monthCalendarClosure: ((_ month:String) -> Void)?

// MARK: - View Life Cycle

override init(frame: CGRect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class MissionStatisticsView: UIView {

override init(frame: CGRect) {
super.init(frame: .zero)
// setUI()
register()
setLayout()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ final class MissionCalendarDayCell: FSCalendarCell {
extension MissionCalendarDayCell {
func configure(_ state: ToDoState) {
self.state = state
updateUI()
}
}

0 comments on commit 8f54c5e

Please sign in to comment.