Skip to content

Commit

Permalink
[Feat] sopt-makers#199 - 출석하기 진입 기능 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Apr 22, 2023
1 parent 389e3f1 commit 6418f1b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControl
private let attendanceButton: OPCustomButton = {
let button = OPCustomButton()
button.titleLabel!.setTypoStyle(.Attendance.h1)
button.isHidden = true
button.isEnabled = true
return button
}()

Expand Down Expand Up @@ -178,7 +180,7 @@ extension ShowAttendanceVC {
attendanceButton.publisher(for: .touchUpInside)
.withUnretained(self)
.sink { owner, _ in
let vc = owner.factory.makeAttendanceVC().viewController
let vc = owner.factory.makeAttendanceVC(lectureRound: owner.viewModel.lectureRound).viewController
vc.modalTransitionStyle = .crossDissolve
vc.modalPresentationStyle = .overFullScreen
owner.present(vc, animated: true)
Expand All @@ -197,11 +199,11 @@ extension ShowAttendanceVC {
self.sceneType = .scheduledDay
self.setScheduledData(model)
self.headerScheduleView.updateLayout(.scheduledDay)
self.setAttendanceButton(isHidden: false, title: "\(model.name) \(I18N.Attendance.takeAttendance)")
self.attendanceButton.isHidden = false
} else {
self.sceneType = .unscheduledDay
self.headerScheduleView.updateLayout(.unscheduledDay)
self.setAttendanceButton(isHidden: true)
self.attendanceButton.isHidden = true
}
self.endRefresh()
})
Expand All @@ -222,6 +224,13 @@ extension ShowAttendanceVC {
owner.headerScheduleView.setAttendanceInfo(model, true)
}
.store(in: self.cancelBag)

output.attendanceButtonInfo
.withUnretained(self)
.sink { owner, info in
owner.setAttendanceButton(title: info.title, isEnabled: info.isEnalbed)
}
.store(in: self.cancelBag)
}

private func endRefresh() {
Expand All @@ -246,9 +255,9 @@ extension ShowAttendanceVC {
attendanceScoreView.setMyAttendanceTableData(model.attendances)
}

private func setAttendanceButton(isHidden: Bool, title: String? = nil) {
attendanceButton.isHidden = isHidden
attendanceButton.setTitle(title, for: .normal)
private func setAttendanceButton(title: String, isEnabled: Bool) {
attendanceButton.isEnabled = isEnabled
isEnabled ? attendanceButton.setTitle(title, for: .normal) : attendanceButton.setTitle(title, for: .disabled)
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ import Core
import Domain
import Foundation

struct AttendanceButtonInfo {
let title: String
let isEnalbed: Bool
}

public final class ShowAttendanceViewModel: ViewModelType {

// MARK: - Properties

private let useCase: ShowAttendanceUseCase
private var cancelBag = CancelBag()
public var sceneType: AttendanceScheduleType?
public var lectureRound: AttendanceRoundModel = .EMPTY

// MARK: - Inputs

Expand All @@ -33,6 +39,7 @@ public final class ShowAttendanceViewModel: ViewModelType {
@Published var scheduleModel: AttendanceScheduleModel?
@Published var scoreModel: AttendanceScoreModel?
@Published var todayAttendances: [AttendanceStepModel]?
var attendanceButtonInfo = PassthroughSubject<AttendanceButtonInfo, Never>()
}

// MARK: - init
Expand Down Expand Up @@ -63,6 +70,8 @@ extension ShowAttendanceViewModel {
let fetchedSchedule = self.useCase.attendanceScheduleFetched
let fetchedScore = self.useCase.attendanceScoreFetched
let todayAttendances = self.useCase.todayAttendances
let lectureRound = self.useCase.lectureRound
let lectureRoundErrorTitle = self.useCase.lectureRoundErrorTitle

fetchedSchedule.asDriver()
.sink(receiveValue: { model in
Expand All @@ -72,6 +81,7 @@ extension ShowAttendanceViewModel {
let convertedEndDate = self.convertDateString(model.endDate) else { return }

let newModel = AttendanceScheduleModel(type: model.type,
id: model.id,
location: model.location,
name: model.name,
startDate: convertedStartDate,
Expand All @@ -86,8 +96,6 @@ extension ShowAttendanceViewModel {
})
.store(in: cancelBag)



fetchedScore.asDriver()
.sink(receiveValue: { model in
output.scoreModel = model
Expand All @@ -99,6 +107,24 @@ extension ShowAttendanceViewModel {
output.todayAttendances = attendances
}
.store(in: self.cancelBag)

lectureRound
.compactMap { $0 }
.withUnretained(self)
.sink { owner, lectureRound in
owner.lectureRound = lectureRound
let buttonInfo = AttendanceButtonInfo(title: I18N.Attendance.takeNthAttendance(lectureRound.round), isEnalbed: true)
output.attendanceButtonInfo.send(buttonInfo)
}
.store(in: self.cancelBag)

lectureRoundErrorTitle
.withUnretained(self)
.sink { owner, title in
let buttonInfo = AttendanceButtonInfo(title: title, isEnalbed: false)
output.attendanceButtonInfo.send(buttonInfo)
}
.store(in: self.cancelBag)
}

private func convertDateString(_ dateString: String) -> String? {
Expand Down

0 comments on commit 6418f1b

Please sign in to comment.