|
5 | 5 | // Created by 최정인 on 11/19/25. |
6 | 6 | // |
7 | 7 |
|
| 8 | +import Combine |
8 | 9 | import SnapKit |
9 | 10 | import UIKit |
10 | 11 |
|
11 | | -final class ReportCompleteViewController: UIViewController { |
| 12 | +final class ReportCompleteViewController: BaseViewController<ReportDetailViewModel> { |
12 | 13 | private enum Layout { |
13 | 14 | static let horizontalMargin: CGFloat = 20 |
14 | 15 | static let completeImageViewTopSpacing: CGFloat = 78 |
@@ -65,15 +66,27 @@ final class ReportCompleteViewController: UIViewController { |
65 | 66 | private let descriptionLabel = UILabel() |
66 | 67 | private let photoStackView = UIStackView() |
67 | 68 | private let confirmButton = PrimaryButton(buttonState: .default, buttonTitle: "확인") |
| 69 | + private let reportId: Int |
| 70 | + private var cancellables: Set<AnyCancellable> = [] |
| 71 | + |
| 72 | + init(viewModel: ReportDetailViewModel, reportId: Int) { |
| 73 | + self.reportId = reportId |
| 74 | + |
| 75 | + super.init(viewModel: viewModel) |
| 76 | + } |
| 77 | + |
| 78 | + required init?(coder: NSCoder) { |
| 79 | + fatalError("init(coder:) has not been implemented") |
| 80 | + } |
68 | 81 |
|
69 | 82 | override func viewDidLoad() { |
70 | 83 | super.viewDidLoad() |
71 | 84 | configureAttribute() |
72 | 85 | configureLayout() |
73 | | - fetchReport() |
| 86 | + viewModel.action(input: .fetchReportDetail(reportId: reportId)) |
74 | 87 | } |
75 | 88 |
|
76 | | - private func configureAttribute() { |
| 89 | + override func configureAttribute() { |
77 | 90 | view.backgroundColor = .white |
78 | 91 | scrollView.showsVerticalScrollIndicator = false |
79 | 92 |
|
@@ -105,7 +118,7 @@ final class ReportCompleteViewController: UIViewController { |
105 | 118 | photoStackView.spacing = Layout.photoStackViewSpacing |
106 | 119 | } |
107 | 120 |
|
108 | | - private func configureLayout() { |
| 121 | + override func configureLayout() { |
109 | 122 | let safeArea = view.safeAreaLayoutGuide |
110 | 123 |
|
111 | 124 | view.addSubview(scrollView) |
@@ -171,8 +184,30 @@ final class ReportCompleteViewController: UIViewController { |
171 | 184 | } |
172 | 185 | } |
173 | 186 |
|
174 | | - private func bind() { |
175 | | - fetchReport() |
| 187 | + override func bind() { |
| 188 | + viewModel.output.reportDetailPublisher |
| 189 | + .receive(on: DispatchQueue.main) |
| 190 | + .sink(receiveValue: { [weak self] reportDetail in |
| 191 | + guard let reportDetail else { return } |
| 192 | + |
| 193 | + self?.titleLabel.text = reportDetail.title |
| 194 | + self?.categoryLabel.text = reportDetail.category.name |
| 195 | + self?.locationLabel.text = reportDetail.location |
| 196 | + let descriptionText = reportDetail.description |
| 197 | + self?.descriptionLabel.attributedText = BitnagilFont(style: .body1, weight: .medium) |
| 198 | + .attributedString(text: descriptionText, alignment: .right) |
| 199 | + |
| 200 | + for photoURL in reportDetail.photoUrls { |
| 201 | + guard |
| 202 | + let photoView = self?.makePhotoView(), |
| 203 | + let url = URL(string: photoURL) |
| 204 | + else { continue } |
| 205 | + |
| 206 | + photoView.kf.setImage(with: url) |
| 207 | + self?.photoStackView.addArrangedSubview(photoView) |
| 208 | + } |
| 209 | + }) |
| 210 | + .store(in: &cancellables) |
176 | 211 | } |
177 | 212 |
|
178 | 213 | private func makeContentView(contentType: ReportCompleteContent) -> UIView { |
@@ -223,25 +258,8 @@ final class ReportCompleteViewController: UIViewController { |
223 | 258 | return contentContainerView |
224 | 259 | } |
225 | 260 |
|
226 | | - // TODO: 추후 ViewModel로 옮기기 |
227 | | - private func fetchReport() { |
228 | | - titleLabel.text = "가로등이 깜박거려요." |
229 | | - categoryLabel.text = "교통시설" |
230 | | - locationLabel.text = "서울특별시 강남구 삼성동" |
231 | | - let descriptionText = "150자 내용 채우기" |
232 | | - descriptionLabel.attributedText = BitnagilFont(style: .body1, weight: .medium) |
233 | | - .attributedString(text: descriptionText, alignment: .right) |
234 | | - |
235 | | - let photoView1 = makePhotoView() |
236 | | - let photoView2 = makePhotoView() |
237 | | - let photoView3 = makePhotoView() |
238 | | - [photoView1, photoView2, photoView3].forEach { |
239 | | - photoStackView.addArrangedSubview($0) |
240 | | - } |
241 | | - } |
242 | | - |
243 | | - private func makePhotoView() -> UIView { |
244 | | - let photoView = UIView() |
| 261 | + private func makePhotoView() -> UIImageView { |
| 262 | + let photoView = UIImageView() |
245 | 263 | photoView.backgroundColor = BitnagilColor.gray30 |
246 | 264 | photoView.layer.masksToBounds = true |
247 | 265 | photoView.layer.cornerRadius = 6 |
|
0 commit comments