Skip to content

Commit

Permalink
Feat: 보관함 캘린더 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
iHyunWoo committed Nov 5, 2024
1 parent 27f905e commit 302547c
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// DiaryScheduleType.swift
// DomainDiary
//
// Created by 정현우 on 11/2/24.
//

public enum DiaryScheduleType {
case noSchedule
case personalOrBirthdaySchedule
case meetingSchedule
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,29 @@ import CoreNetwork

@DependencyClient
public struct DiaryUseCase {
// 캘린더 일정 월별로 가져오기
public func getCalendarByMonth(ym: YearMonth) async throws -> DiaryCalendar {
let response: BaseResponse<DiaryCalendar> = try await APIManager.shared.performRequest(endPoint: DiaryEndPoint.getCalendarByMonth(ym: ym))
// 캘린더 일정 +-1 달씩 월별로 가져오기
public func getCalendarByMonth(ym: YearMonth) async throws -> [YearMonthDay: DiaryScheduleType] {
var result: [YearMonthDay: DiaryScheduleType] = [:]

return response.result!
for i in -1...1 {
let currentYM = ym.addMonth(i)
let response: BaseResponse<DiaryCalendar> = try await APIManager.shared.performRequest(endPoint: DiaryEndPoint.getCalendarByMonth(ym: currentYM))

response.result?.diaryDateForPersonal.forEach { day in
result[YearMonthDay(year: currentYM.year, month: currentYM.month, day: day), default: .noSchedule] = .personalOrBirthdaySchedule
}

response.result?.diaryDateForBirthday.forEach { day in
result[YearMonthDay(year: currentYM.year, month: currentYM.month, day: day), default: .noSchedule] = .personalOrBirthdaySchedule
}

response.result?.diaryDateForMeeting.forEach { day in
result[YearMonthDay(year: currentYM.year, month: currentYM.month, day: day), default: .noSchedule] = .meetingSchedule
}

}

return result
}

// 특정 일 스케쥴 가져오기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
import ComposableArchitecture
import SwiftUICalendar

import CoreLocation
import DomainDiary

@Reducer
Expand All @@ -21,6 +22,8 @@ public struct ArchiveCalendarStore {
// 달력에서 현재 focusing된 날짜
var focusDate: YearMonthDay? = nil

// 캘린더 타입
var diaryScheduleTypes: [YearMonthDay: DiaryScheduleType] = [:]
// 캘린더에 표시될 일정
var schedules: [YearMonthDay: [DiarySchedule]] = [:]
}
Expand All @@ -32,8 +35,17 @@ public struct ArchiveCalendarStore {
// 특정 날짜 선택
case selectDate(YearMonthDay)

// +- 2달 일정 가져오기
case getSchedules(ym: YearMonth)
case getSchedulesCompleted([YearMonthDay: DiaryScheduleType])
// 특정 날짜 일정 상세 가져오기
case getScheduleDetail(ymd: YearMonthDay)
case getScheduleDetailCompleted(ymd: YearMonthDay, schedules: [DiarySchedule])

}

@Dependency(\.diaryUseCase) var diaryUseCase

public var body: some ReducerOf<Self> {
BindingReducer()

Expand All @@ -53,6 +65,39 @@ public struct ArchiveCalendarStore {
}

return .none

case .getSchedules(let ym):
return .run { send in
do {
let response = try await diaryUseCase.getCalendarByMonth(ym: ym)
await send(.getSchedulesCompleted(response))
} catch(let error) {
print(error.localizedDescription)
}
}

case .getSchedulesCompleted(let response):
state.diaryScheduleTypes = response
return .none

case .getScheduleDetail(let ymd):
// 이미 받아온 스케쥴들이 있다면 리턴
if !state.schedules[ymd, default: []].isEmpty {
return .none
}

return .run { send in
do {
let response = try await diaryUseCase.getDiaryByDate(ymd: ymd)
await send(.getScheduleDetailCompleted(ymd: ymd, schedules: response))
} catch(let error) {
print(error.localizedDescription)
}
}

case .getScheduleDetailCompleted(let ymd, let response):
state.schedules[ymd, default: []] = response
return .none
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public struct ArchiveCalendarView: View {
NamoArchiveCalendarView(
calendarController: calendarController,
focusDate: $store.focusDate,
diaryScheduleTypes: $store.diaryScheduleTypes,
schedules: $store.schedules,
dateTapAction: { date in
store.send(.getScheduleDetail(ymd: date))
store.send(.selectDate(date), animation: .default)
}
)
Expand All @@ -39,6 +41,12 @@ public struct ArchiveCalendarView: View {
.frame(height: tabBarHeight)
}
.ignoresSafeArea(edges: .bottom)
.onAppear {
store.send(.getSchedules(ym: calendarController.yearMonth))
}
.onChange(of: calendarController.yearMonth) { newYM in
store.send(.getSchedules(ym: calendarController.yearMonth))
}
.namoNabBar(
center: {
Text("보관함")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import DomainDiary
struct ArchiveCalendarItem: View {
@Binding var focusDate: YearMonthDay?
let date: YearMonthDay
let schedules: [DiarySchedule]
let diaryScheduleType: DiaryScheduleType

private let MAX_SCHEDULE = screenHeight < 800 ? 3 : 4

Expand All @@ -24,7 +24,9 @@ struct ArchiveCalendarItem: View {
VStack(alignment: .leading, spacing: 4) {
dayView

// calendarItem(geometry: geometry)
if diaryScheduleType != .noSchedule {
calendarItem
}
}
.padding(.top, 4)
.padding(.leading, 5)
Expand All @@ -46,4 +48,23 @@ struct ArchiveCalendarItem: View {
}
}

private var calendarItem: some View {
VStack {
if focusDate == nil {
if diaryScheduleType == .meetingSchedule {
Image(asset: SharedDesignSystemAsset.Assets.icArchiveMongOrange)
} else if diaryScheduleType == .personalOrBirthdaySchedule {
Image(asset: SharedDesignSystemAsset.Assets.icArchiveMongGray)
}
} else {
if diaryScheduleType == .meetingSchedule {
Image(asset: SharedDesignSystemAsset.Assets.icArchiveLeafOrange)
} else if diaryScheduleType == .personalOrBirthdaySchedule {
Image(asset: SharedDesignSystemAsset.Assets.icArchiveLeafGray)
}
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import SharedUtil
import SharedDesignSystem
import DomainDiary


public struct NamoArchiveCalendarView: View {
@ObservedObject var calendarController: CalendarController
// 현재 포커싱된(detailView) 날짜
@Binding var focusDate: YearMonthDay?
// 스케쥴 타입
@Binding var diaryScheduleTypes: [YearMonthDay: DiaryScheduleType]
// 캘린더에 표시할 스케쥴
@Binding var schedules: [YearMonthDay: [DiarySchedule]]
// 상단에 요일을 보이게 할지
Expand All @@ -32,13 +33,15 @@ public struct NamoArchiveCalendarView: View {
public init(
calendarController: CalendarController,
focusDate: Binding<YearMonthDay?> = .constant(nil),
diaryScheduleTypes: Binding<[YearMonthDay: DiaryScheduleType]> = .constant([:]),
schedules: Binding<[YearMonthDay: [DiarySchedule]]> = .constant([:]),
showWeekDay: Bool = true,
showDetailView: Bool = true,
dateTapAction: @escaping (YearMonthDay) -> Void = { _ in }
) {
self.calendarController = calendarController
self._focusDate = focusDate
self._diaryScheduleTypes = diaryScheduleTypes
self._schedules = schedules
self.showWeekDay = showWeekDay
self.showDetailView = showDetailView
Expand All @@ -60,7 +63,7 @@ public struct NamoArchiveCalendarView: View {
ArchiveCalendarItem(
focusDate: $focusDate,
date: date,
schedules: schedules[date] ?? []
diaryScheduleType: diaryScheduleTypes[date] ?? .noSchedule
)
.onTapGesture {
dateTapAction(date)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "ic_archive_leaf_gray.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "ic_archive_leaf_orange.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading

0 comments on commit 302547c

Please sign in to comment.