Skip to content

Commit

Permalink
Merge pull request #280 from depromeet/fix/#272-fix-feed-QA-1
Browse files Browse the repository at this point in the history
fix: 포스트 관련 QA 수정사항
  • Loading branch information
akrudal authored Jan 15, 2024
2 parents d16ab25 + 298dc1f commit 627e7d3
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//

import Foundation
import UIKit

import Core
import Domain

Expand All @@ -16,24 +18,32 @@ public final class HomeViewReactor: Reactor {
public enum Action {
case getTodayPostList
case refreshCollectionview
case startTimer
}

public enum Mutation {
case setLoading(Bool)
case setDidPost
case setDescriptionText(String)
case showNoPostTodayView
case showNoPostTodayView(Bool)
case setPostCollectionView([SectionModel<String, PostListData>])
case setRefreshing(Bool)
case hideCamerButton(Bool)
case setTimer(Int)
case setTimerColor(UIColor)
}

public struct State {
var isRefreshing: Bool = false
var showLoading: Bool = true
var didPost: Bool = false
var descriptionText: String = HomeStrings.Description.standard
var isShowingNoPostTodayView: Bool = false
var feedSections: [SectionModel<String, PostListData>] = []
var isHideCameraButton: Bool = true
var descriptionText: String = ""

@Pulse var timerLabelColor: UIColor = .white
@Pulse var timer: String = ""
@Pulse var feedSections: [SectionModel<String, PostListData>] = []
}

public let initialState: State = State()
Expand All @@ -54,16 +64,19 @@ extension HomeViewReactor {
.flatMap { postList in
guard let postList,
!postList.postLists.isEmpty else {
return Observable.just(Mutation.showNoPostTodayView)
return Observable.just(Mutation.showNoPostTodayView(true))
}

var observables = [Observable.just(Mutation.setPostCollectionView([
SectionModel<String, PostListData>(model: "section1", items: postList.postLists)]))]
var observables = [
Observable.just(Mutation.showNoPostTodayView(false)),
Observable.just(Mutation.setPostCollectionView([
SectionModel<String, PostListData>(model: "section1", items: postList.postLists)]))]

if postList.selfUploaded {
observables.append(Observable.just(Mutation.hideCamerButton(true)))
observables.append(Observable.just(Mutation.setDidPost))
}

if postList.allFamilyMembersUploaded {
observables.append(Observable.just(Mutation.setDescriptionText("우리 가족 모두가 사진을 올린 날🎉")))
}
Expand All @@ -74,15 +87,44 @@ extension HomeViewReactor {
case .refreshCollectionview:
let getTodayPostListAction = Action.getTodayPostList
return mutate(action: getTodayPostListAction)
case .startTimer:
return Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
.startWith(0)
.flatMap {_ in
let time = self.calculateRemainingTime()

// 시간 이외
guard time > 0 else {
return Observable.concat([
Observable.just(Mutation.hideCamerButton(true)),
Observable.just(Mutation.setDescriptionText(HomeStrings.Timer.notTime)),
Observable.just(Mutation.setTimer(time))
])
}

var observables = [
Observable.just(Mutation.setTimer(time))
]

if time <= 3600 && !self.currentState.didPost {
observables.append(Observable.just(Mutation.hideCamerButton(false)))
observables.append(Observable.just(Mutation.setTimerColor(.warningRed)))
observables.append(Observable.just(Mutation.setDescriptionText("시간이 얼마 남지 않았어요!")))
} else {
observables.append(Observable.just(Mutation.setDescriptionText(HomeStrings.Description.standard)))
}

return Observable.concat(observables)
}
}
}

public func reduce(state: State, mutation: Mutation) -> State {
var newState = state

switch mutation {
case .showNoPostTodayView:
newState.isShowingNoPostTodayView = true
case let .showNoPostTodayView(isShow):
newState.isShowingNoPostTodayView = isShow
case let .setPostCollectionView(data):
newState.feedSections = data
case .setDidPost:
Expand All @@ -93,8 +135,32 @@ extension HomeViewReactor {
newState.showLoading = false
case let .setRefreshing(isRefreshing):
newState.isRefreshing = isRefreshing
case let .hideCamerButton(isHide):
newState.isHideCameraButton = isHide
case let .setTimer(time):
newState.timer = time.setTimerFormat() ?? "00:00:00"
case let .setTimerColor(color):
newState.timerLabelColor = color
}

return newState
}
}

extension HomeViewReactor {
private func calculateRemainingTime() -> Int {
let calendar = Calendar.current
let currentTime = Date()

let isAfterNoon = calendar.component(.hour, from: currentTime) >= 12

if isAfterNoon {
if let nextMidnight = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: currentTime.addingTimeInterval(24 * 60 * 60)) {
let timeDifference = calendar.dateComponents([.second], from: currentTime, to: nextMidnight)
return max(0, timeDifference.second ?? 0)
}
}

return 0
}
}
Loading

0 comments on commit 627e7d3

Please sign in to comment.