Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ final class BottomContentView: UIView {
currentState = state

switch state {
case .empty:
showEmptyState()
case .empty(let hasPhotos):
showEmptyState(hasPhotos: hasPhotos)
case .processing(let records):
if let first = records.first {
showProcessingState(record: first)
Expand Down Expand Up @@ -182,7 +182,7 @@ final class BottomContentView: UIView {
containerView.layer.borderWidth = show ? Constants.containerBorderWidth : 0
}

private func showEmptyState() {
private func showEmptyState(hasPhotos: Bool) {
cardStackStateView.isHidden = true
processingStateView.isHidden = true
showContainerStyle(false)
Expand All @@ -192,20 +192,27 @@ final class BottomContentView: UIView {
cancellables.removeAll()

// 새로 생성
let newEmptyView = EmptyFoodRecordView(text: "오늘의 음식 사진을 추가해보세요")
let newEmptyView = EmptyFoodRecordView(
text: hasPhotos
? "오늘의 음식 사진을 추가해보세요"
: "기록 가능한 음식 사진이 없어요",
style: hasPhotos ? .addable : .unavailable
)
containerView.addSubview(newEmptyView)
emptyStateView = newEmptyView

newEmptyView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

// Publisher 바인딩
newEmptyView.addButtonTapPublisher
.sink { [weak self] in
self?.addButtonTapSubject.send()
}
.store(in: &cancellables)
// 사진이 있을 때만 탭 Publisher 바인딩
if hasPhotos {
newEmptyView.addButtonTapPublisher
.sink { [weak self] in
self?.addButtonTapSubject.send()
}
.store(in: &cancellables)
}
}

private func showCardStackState(record: FoodRecord, totalCount: Int) {
Expand Down Expand Up @@ -245,7 +252,7 @@ final class BottomContentView: UIView {

extension BottomContentView {
enum State: Equatable {
case empty
case empty(hasPhotos: Bool)
case processing([FoodRecord])
case recorded([FoodRecord])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,30 @@ public final class WeeklyCalendarViewModel<
let completedRecords = allRecords.filter { !$0.isProcessing }
let processingRecords = allRecords.filter { $0.isProcessing }

var hasFoodPhotos = false
if completedRecords.isEmpty && processingRecords.isEmpty {
hasFoodPhotos = await checkFoodPhotosExist(for: date)
}

state.dateContent = DateContent(
records: completedRecords,
processingRecords: processingRecords
processingRecords: processingRecords,
hasFoodPhotos: hasFoodPhotos
)
}

private func checkFoodPhotosExist(for date: Date) async -> Bool {
guard requestPhotoAuthorizationUseCase.isAuthorized() else {
return false
}
do {
let photos = try await loadWeeklyCalendarDataUseCase.loadPhotos(for: date)
return !photos.isEmpty
} catch {
return false
}
}

@MainActor
private func savePhotosAsRecord(_ assets: [AssetRepo.Asset]) async {
guard !assets.isEmpty else { return }
Expand Down Expand Up @@ -318,6 +336,7 @@ extension WeeklyCalendarViewModel {
public struct DateContent: Equatable {
public let records: [FoodRecord]
public let processingRecords: [FoodRecord]
public let hasFoodPhotos: Bool
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public final class WeeklyCalendarViewController<
} else if !content.processingRecords.isEmpty {
.processing(content.processingRecords)
} else {
.empty
.empty(hasPhotos: content.hasFoodPhotos)
}

bottomContentView.configure(state: state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import UIKit
/// 음식 기록이 없을 때 표시되는 빈 상태 뷰
final class EmptyFoodRecordView: UIView {

// MARK: - Style

enum Style {
case addable
case unavailable
}

// MARK: - Constants

private enum Constants {
Expand All @@ -35,7 +42,6 @@ final class EmptyFoodRecordView: UIView {

private let addImageView: UIImageView = {
let iv = UIImageView()
iv.image = DesignSystemAsset.add.image
iv.contentMode = .scaleAspectFit
return iv
}()
Expand All @@ -49,11 +55,13 @@ final class EmptyFoodRecordView: UIView {

// MARK: - Init

init(text: String) {
init(text: String, style: Style = .addable) {
super.init(frame: .zero)
setupUI()
setupUI(style: style)
setupConstraints()
setupActions()
if style == .addable {
setupActions()
}
placeholderLabel.setText(text, style: .p14, color: .gray050)
}

Expand All @@ -64,14 +72,21 @@ final class EmptyFoodRecordView: UIView {

// MARK: - Setup

private func setupUI() {
private func setupUI(style: Style) {
dashedBorderView.cornerRadius = Constants.cornerRadius
dashedBorderView.backgroundColor = .sd900
dashedBorderView.layer.cornerRadius = Constants.cornerRadius
dashedBorderView.clipsToBounds = true
addSubview(dashedBorderView)
dashedBorderView.addSubview(contentView)

switch style {
case .addable:
addImageView.image = DesignSystemAsset.add.image
case .unavailable:
addImageView.image = DesignSystemAsset.emptyMeal.image
}

contentView.addSubview(addImageView)
contentView.addSubview(placeholderLabel)
}
Expand Down
Loading