Skip to content

Commit

Permalink
#26 [Chore] 폴더 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
soletree committed May 16, 2024
1 parent b7e1eb4 commit 2cfbdcb
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 143 deletions.
136 changes: 0 additions & 136 deletions Score/Score/View/Calendar/CalendarView.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import SwiftUI

//MARK: - CalendarGridItem

// - FIXME: CalendarView에서 무조건 store를 받아와야 하는데, 효율적인지?
/// - Parameters:
/// - store: ViewStore<CalendarFeature.State, CalendarFeature.Action> CalendarView에서 받아옵니다.
/// - dateComponents: DateComponents를 정의합니다.
/// - action: 사용자가 컴포넌트를 Tap했을 때 수행할 동작을 정의합니다.
struct CalendarGridItem: View {
let store: ViewStore<CalendarFeature.State,
CalendarFeature.Action>
let store: StoreOf<CalendarFeature>
@ObservedObject var viewStore: ViewStoreOf<CalendarFeature>

let dateComponents: DateComponents?
let action: () -> (Void)

//MARK: - style

private var style: SCNumberIconStyle {
guard let dateComponents
else {
Expand All @@ -35,7 +37,7 @@ struct CalendarGridItem: View {
}

// - FIXME: 오늘 날짜가 black인지? 디자인 확인 필요
if store.state.selectedDateComponents == dateComponents {
if viewStore.state.selectedDateComponents == dateComponents {
return .gray
}

Expand All @@ -44,11 +46,24 @@ struct CalendarGridItem: View {
return .plain
}

//MARK: - init

init(store: StoreOf<CalendarFeature>,
dateComponents: DateComponents? = nil,
action: @escaping () -> Void) {
self.store = store
self.dateComponents = dateComponents
self.action = action
self.viewStore = ViewStore(store,
observe: { $0 })
}

//MARK: - body

var body: some View {
Button(action: action) {
SCNumberIcon(style: style,
number: dateComponents?.day
?? 0)
number: dateComponents?.day ?? 0)
/// 양쪽 layout padding 효과
.layoutOfCalendarItem()
.background {
Expand All @@ -71,7 +86,8 @@ struct CalendarGridItem: View {
//MARK: - Preview

#Preview {
CalendarGridItem(store: .init(.init(initialState: CalendarFeature.State(appearedYear: 0, appearedMonth: 0, appearedDay: 0, appearedDateComponentsMatrix: []), reducer: {CalendarFeature().body}), observe: {$0}), dateComponents: nil) {
CalendarGridItem(store: .init(initialState: .init(),
reducer: { CalendarFeature() })) {

}
}
132 changes: 132 additions & 0 deletions Score/Score/View/MyPage/Calendar/CalendarView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//
// CalendarView.swift
// Score
//
// Created by sole on 4/12/24.
//

import ComposableArchitecture
import SwiftUI

//MARK: - CalendarView

struct CalendarView: View {
let store: StoreOf<CalendarFeature>
@ObservedObject var viewStore: ViewStoreOf<CalendarFeature>

init(store: StoreOf<CalendarFeature>) {
self.store = store
self.viewStore = ViewStore(store,
observe: { $0 })
}

var body: some View {
VStack(spacing: 9) {
// Calendar Header Section
// year, month, buttons to control appearedMonth
calendarHeader()

// WeekOfDay Label Section
dayOfWeekLabel()

// Calendar Section
/// frame: calendarGrid의 높이에 따라 View가 움직이는 현상을 방지합니다.
calendarGrid()
.frame(height: .calendarItemSize * 6)
}
.layout()
.onAppear {
store.send(.viewAppearing)
}
}

//MARK: - calendarHeader

@ViewBuilder
func calendarHeader() -> some View {
HStack {
Group {
Text(String(
format: "%4d",
viewStore.appearedYear))

Text((Month(rawValue: viewStore.appearedMonth) ??
.october).capitalizedString())
}
.pretendard(weight: .black,
size: .m)

Spacer()

/// FIXME: Asset으로 변경
Button {
store.send(.decrementMonthButtonTapped)
} label: {
Image(systemName: "chevron.left")
.foregroundStyle(
Color.brandColor(
color: .sub1
)
)
.frame(width: 34,
height: 34)
}

Button {
store.send(.incrementMonthButtonTapped)
} label: {
Image(systemName: "chevron.right")
.foregroundStyle(
Color.brandColor(
color: .sub1
)
)
.frame(width: 34,
height: 34)
}
}
}

//MARK: - dayOfWeekLabel

@ViewBuilder
func dayOfWeekLabel() -> some View {
HStack(spacing: 0) {
ForEach(DayOfWeek.allCases,
id: \.self) { dayOfWeek in
Text(dayOfWeek.stringValue())
.pretendard(.body3)
}
.layoutOfCalendarItem()
}
}

//MARK: - calendarGrid

@ViewBuilder
func calendarGrid() -> some View {
VStack(spacing: 0) {
ForEach(viewStore.appearedDateComponentsMatrix,
id: \.self) { dateComponentsArray in
HStack(spacing: 0) {
ForEach(dateComponentsArray,
id: \.self) { dateComponentsWithID in
CalendarGridItem(
store: store,
dateComponents: dateComponentsWithID.dateComponents
) {
store.send(.dayComponentButtonTapped(dateComponentsWithID.dateComponents))
}
}
}
}
}
}
}

//MARK: - Preview

#Preview {
CalendarView(store: .init(initialState: .init(),
reducer: { CalendarFeature() }))
}

0 comments on commit 2cfbdcb

Please sign in to comment.