Skip to content

Commit

Permalink
Merge pull request #59 from YAPP-Github/TNT-214-trainerAddSession
Browse files Browse the repository at this point in the history
[TNT-214] TrainerAddPTSession ๊ด€๋ จ ์‹ ๊ทœ ๋””์ž์ธ ์ปดํฌ๋„ŒํŠธ ์ถ”๊ฐ€
  • Loading branch information
FpRaArNkK authored Feb 7, 2025
2 parents b733379 + 822f7f0 commit c8a8668
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ struct AutoSizingBottomSheetModifier: ViewModifier {
GeometryReader { proxy in
Color.clear
.onAppear {
contentHeight = proxy.size.height + 50
contentHeight = proxy.size.height + 10
}
.onChange(of: proxy.size.height) { _, newHeight in
contentHeight = newHeight + 50
contentHeight = newHeight + 10
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FSCalendar
final class TCalendarCell: FSCalendarCell {
// MARK: Properties
static let identifier: String = "TCalendarCell"
static let cellSize: CGSize = CGSize(width: 51, height: 54)

/// Cell์— ํ‘œ์‹œ๋˜๋Š” ๋‚ ์งœ
private var customDate: Date?
Expand All @@ -22,8 +21,8 @@ final class TCalendarCell: FSCalendarCell {
private var style: Style = .default
/// Cell์— ํ‘œ์‹œ๋˜๋Š” ์ผ์ • ์นด์šดํŠธ
private var eventCount: Int = 0
/// ์ฃผ๊ฐ„/์›”๊ฐ„ ๋ชจ๋“œ์ธ์ง€ ํ‘œ์‹œ
private var isWeekMode: Bool = false
/// ์ฃผ๊ฐ„/์›”๊ฐ„/์ปดํŒฉํŠธ ๋ชจ๋“œ์ธ์ง€ ํ‘œ์‹œ
private var mode: TCalendarType = .month

// MARK: UI Elements
private let dayLabel: UILabel = UILabel()
Expand Down Expand Up @@ -100,10 +99,14 @@ final class TCalendarCell: FSCalendarCell {

/// ์ผ์ • ์นด์šดํŠธ ํ‘œ์‹œ ์—…๋ฐ์ดํŠธ
private func updateEventDisplay() {
guard mode != .compactMonth else {
eventStackView.isHidden = true
return
}
eventCountLabel.text = "\(eventCount)"
let eventExists: Bool = eventCount > 0
eventStackView.isHidden = !eventExists
let presentCount: Bool = !isWeekMode && eventExists
let presentCount: Bool = mode == .month && eventExists
eventCountLabel.isHidden = !presentCount
}

Expand All @@ -112,7 +115,7 @@ final class TCalendarCell: FSCalendarCell {
// ๋‚ ์งœ ๋ฐ ์„ ํƒ ์ƒํƒœ ์ดˆ๊ธฐํ™”
customDate = nil
isCellSelected = false
isWeekMode = false
mode = .month

// ์ผ์ • ๊ด€๋ จ ์ดˆ๊ธฐํ™”
eventCount = 0
Expand All @@ -132,12 +135,12 @@ extension TCalendarCell {
with date: Date,
isCellSelected: Bool,
eventCount: Int = 0,
isWeekMode: Bool = false
mode: TCalendarType = .month
) {
self.customDate = date
self.isCellSelected = isCellSelected
self.eventCount = eventCount
self.isWeekMode = isWeekMode
self.mode = mode

// ํ˜„์žฌ ๋‚ ์งœ ๋ฐ ์„ ํƒ ์ƒํƒœ๋ฅผ ๋ฐ˜์˜, Style ์„ค์ •
if isCellSelected {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ public struct TCalendarRepresentable: UIViewRepresentable {
@Binding private var currentPage: Date
/// ์บ˜๋ฆฐ๋” ๋†’์ด
@Binding var calendarHeight: CGFloat
/// ์ฃผ๊ฐ„/์›”๊ฐ„ ํ‘œ์‹œ ์—ฌ๋ถ€
private var isWeekMode: Bool
/// ์ฃผ๊ฐ„/์›”๊ฐ„/์ปดํŒฉํŠธ ๋ชจ๋“œ์ธ์ง€ ํ‘œ์‹œ
private var mode: TCalendarType = .month
/// ์บ˜๋ฆฐ๋” ํ‘œ์‹œ ์ด๋ฒคํŠธ ๋”•์…”๋„ˆ๋ฆฌ
private var events: [Date: Int]

public init(
selectedDate: Binding<Date>,
currentPage: Binding<Date>,
calendarHeight: Binding<CGFloat>,
isWeekMode: Bool = false,
mode: TCalendarType = .month,
events: [Date: Int] = [:]
) {
self._selectedDate = selectedDate
self._currentPage = currentPage
self._calendarHeight = calendarHeight
self.isWeekMode = isWeekMode
self.mode = mode
self.events = events
}

Expand All @@ -44,7 +44,7 @@ public struct TCalendarRepresentable: UIViewRepresentable {

// Cell ์„ค์ •
calendar.register(TCalendarCell.self, forCellReuseIdentifier: TCalendarCell.identifier)
calendar.collectionView.contentSize = TCalendarCell.cellSize
calendar.collectionView.contentSize = mode.cellSize

// ๊ธฐ๋ณธ ์„ค์ •
calendar.delegate = context.coordinator
Expand All @@ -55,7 +55,7 @@ public struct TCalendarRepresentable: UIViewRepresentable {
calendar.placeholderType = .none
calendar.headerHeight = 0
calendar.weekdayHeight = 18
calendar.rowHeight = TCalendarCell.cellSize.height
calendar.rowHeight = mode.cellSize.height
calendar.appearance.weekdayTextColor = UIColor(.neutral400)
calendar.appearance.weekdayFont = Typography.FontStyle.label2Medium.uiFont
calendar.appearance.selectionColor = .clear
Expand All @@ -77,7 +77,7 @@ public struct TCalendarRepresentable: UIViewRepresentable {
}

// `isWeekMode` ๋ฐ˜์˜
let targetScope: FSCalendarScope = isWeekMode ? .week : .month
let targetScope: FSCalendarScope = mode.scope
if uiView.scope != targetScope {
uiView.scope = targetScope
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public extension TCalendarRepresentable {
with: date,
isCellSelected: isSelected,
eventCount: eventCount,
isWeekMode: parent.isWeekMode
mode: parent.mode
)

return cell
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// TCalendarType.swift
// DesignSystem
//
// Created by ๋ฐ•๋ฏผ์„œ on 2/6/25.
// Copyright ยฉ 2025 yapp25thTeamTnT. All rights reserved.
//

import FSCalendar

/// TCalendar์— ์‚ฌ์šฉ๋˜๋Š” ์บ˜๋ฆฐ๋” ํƒ€์ž…์ž…๋‹ˆ๋‹ค
public enum TCalendarType {
/// ์ฃผ๊ฐ„ ์บ˜๋ฆฐ๋” - ์ผ์ • ํ‘œ์‹œ
case week
/// ์›”๊ฐ„ ์บ˜๋ฆฐ๋” - ์ผ์ • ํ‘œ์‹œ
case month
/// ์›”๊ฐ„ ์บ˜๋ฆฐ๋” - ๋‚ ์งœ์™€ ์„ ํƒ ํ‘œ์‹œ๋งŒ
case compactMonth

var scope: FSCalendarScope {
switch self {
case .week:
return .week
case .month, .compactMonth:
return .month
}
}

var calendarHeight: CGFloat {
switch self {
case .week:
return 80
case .month:
return 340
case .compactMonth:
return 320
}
}

var cellSize: CGSize {
switch self {
case .week, .month:
return CGSize(width: 51, height: 54)
case .compactMonth:
return CGSize(width: 51, height: 40)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,32 @@ import SwiftUI
/// ์•ฑ ์ „๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ์บ˜๋ฆฐ๋”์ž…๋‹ˆ๋‹ค.
/// ์ฃผ๊ฐ„/์›”๊ฐ„ ํ‘œ์‹œ๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.
public struct TCalendarView: View {

/// ์ฃผ๊ฐ„ ์บ˜๋ฆฐ๋” ๋†’์ด
static let weeklyCalendarHeight: CGFloat = 80
/// ์›”๊ฐ„ ์บ˜๋ฆฐ๋” ๋†’์ด
static let monthlyCalendarHeight: CGFloat = 340

/// ์„ ํƒํ•œ ๋‚ ์งœ
@Binding var selectedDate: Date
/// ํ˜„์žฌ ํŽ˜์ด์ง€
@Binding var currentPage: Date
/// ์—…๋ฐ์ดํŠธ ํ”Œ๋ž˜๊ทธ
@State private var forceUpdate: UUID = UUID()
/// ์บ˜๋ฆฐ๋” ๋†’์ด
@State private var calendarHeight: CGFloat = monthlyCalendarHeight
/// ์ฃผ๊ฐ„/์›”๊ฐ„ ํ‘œ์‹œ ์—ฌ๋ถ€
private var isWeekMode: Bool
@State private var calendarHeight: CGFloat = TCalendarType.month.calendarHeight
/// ์ฃผ๊ฐ„/์›”๊ฐ„/์ปดํŒฉํŠธ ๋ชจ๋“œ์ธ์ง€ ํ‘œ์‹œ
private var mode: TCalendarType = .month
/// ์บ˜๋ฆฐ๋” ํ‘œ์‹œ ์ด๋ฒคํŠธ ๋”•์…”๋„ˆ๋ฆฌ
private var events: [Date: Int]

public init(
selectedDate: Binding<Date>,
currentPage: Binding<Date>,
forceUpdate: UUID = UUID(),
events: [Date: Int],
isWeekMode: Bool = false
events: [Date: Int] = [:],
mode: TCalendarType = .month
) {
self._selectedDate = selectedDate
self._currentPage = currentPage
self.events = events
self.forceUpdate = forceUpdate
self.isWeekMode = isWeekMode
self.mode = mode
}

public var body: some View {
Expand All @@ -49,23 +45,19 @@ public struct TCalendarView: View {
selectedDate: $selectedDate,
currentPage: $currentPage,
calendarHeight: $calendarHeight,
isWeekMode: isWeekMode,
mode: mode,
events: events
)
.frame(width: proxy.size.width, height: TCalendarView.monthlyCalendarHeight)
.frame(width: proxy.size.width, height: TCalendarType.month.calendarHeight)
.id(forceUpdate)
.onChange(of: events) {
forceUpdate = UUID()
}
.onAppear {
calendarHeight = isWeekMode
? TCalendarView.weeklyCalendarHeight
: TCalendarView.monthlyCalendarHeight
calendarHeight = mode.calendarHeight
}
.onChange(of: isWeekMode) {
calendarHeight = isWeekMode
? TCalendarView.weeklyCalendarHeight
: TCalendarView.monthlyCalendarHeight
.onChange(of: mode) {
calendarHeight = mode.calendarHeight
}
}
.frame(height: calendarHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ public struct TDatePickerView: View {
private let title: String
/// ๋ฒ„ํŠผ ์‹คํ–‰ action
private let buttonAction: (Date) -> Void
/// ํ—ค๋” formatter
private let monthFormatter: (Date) -> String
/// ์„ ํƒ ๋‚ ์งœ
@State private var selectedDate: Date = .now
/// ํ‘œ์‹œ ๋‚ ์งœ
@State private var currentDate: Date = .now

@Environment(\.dismiss) var dismiss

/// `TDatePickerView` ์ƒ์„ฑ์ž
/// - Parameters:
Expand All @@ -26,33 +32,55 @@ public struct TDatePickerView: View {
public init(
selectedDate: Date = .now,
title: String,
monthFormatter: @escaping (Date) -> String,
buttonAction: @escaping (Date) -> Void
) {
self.selectedDate = selectedDate
self.title = title
self.monthFormatter = monthFormatter
self.buttonAction = buttonAction
}

public var body: some View {
VStack {
DatePicker(
title,
selection: $selectedDate,
displayedComponents: [.date]
VStack(spacing: 12) {
HStack {
Text(title)
.typographyStyle(.heading3, with: .neutral900)
Spacer()
Button(action: {
dismiss()
}, label: {
Image(.icnDelete)
.renderingMode(.template)
.resizable()
.tint(.neutral400)
.frame(width: 32, height: 32)
})
}
.padding(20)

TCalendarHeader<EmptyView>(
currentPage: $currentDate,
formatter: monthFormatter
)
.padding(.top, 20)

TCalendarView(
selectedDate: $selectedDate,
currentPage: $currentDate,
mode: .compactMonth
)
.tint(Color.red500)
.datePickerStyle(.graphical)
.labelsHidden()
.padding()
.padding(.horizontal, 16)

TBottomButton(
title: "์™„๋ฃŒ",
isEnable: true,
TButton(
title: "ํ™•์ธ",
config: .large,
state: .default(.primary(isEnabled: true)),
action: {
buttonAction(selectedDate)
}
)
.ignoresSafeArea(.all, edges: .bottom)
.padding(20)
}
}
}
Loading

0 comments on commit c8a8668

Please sign in to comment.