Skip to content

Commit

Permalink
알 수 없음 오류와 온보딩에서 화면이 넘어가지 않는 오류를 수정해요 (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrudal authored Sep 29, 2024
1 parent 29cbd50 commit 075d9f1
Show file tree
Hide file tree
Showing 29 changed files with 353 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import Domain


final class PostDIContainer: BaseContainer {
private let repository: PostListRepositoryProtocol = PostRepository()
private let familyRepository: FamilyRepositoryProtocol = FamilyRepository()
private let postListRepository: PostListRepositoryProtocol = PostRepository()

private func makePostUseCase() -> FetchPostListUseCaseProtocol {
return FetchPostListUseCase(postListRepository: repository)
return FetchPostListUseCase(postListRepository: postListRepository, familyRepository: familyRepository)
}

private func makeFetchMembersPostListUseCase() -> FetchMembersPostListUseCaseProtocol {
return FetchMembersPostListUseCase(postListRepository: repository)
return FetchMembersPostListUseCase(postListRepository: postListRepository)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public final class CalendarPostCellReactor: Reactor {

case .requestAuthorName:
let authorId = initialState.post.authorId

let authorName = fetchUserNameUseCase.execute(memberId: authorId) ?? "알 수 없음"
return Observable<Mutation>.just(.setAuthorName(authorName))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ extension MainPostViewReactor {
.asObservable()
.flatMap { (postList) -> Observable<Mutation> in
guard let postList = postList,
!postList.postLists.isEmpty else {
!postList.isEmpty else {
return Observable.from([
Mutation.setNoPostTodayView(true),
Mutation.updateRefreshEnd(true),
])
}

let postSectionItem = postList.postLists.map(PostSection.Item.main)
let postSectionItem = postList.map(PostSection.Item.main)
let mutations = [
Mutation.updatePostDataSource(postSectionItem),
Mutation.setNoPostTodayView(false),
Expand All @@ -83,7 +83,6 @@ extension MainPostViewReactor {
case .updatePostDataSource(let postSectionItem):
newState.isRefreshEnd = true
newState.postSection.items = postSectionItem
App.Repository.member.postId.accept(UserDefaults.standard.postId)
case .setNoPostTodayView(let isShow):
newState.isShowingNoPostTodayView = isShow
case .updateRefreshEnd(let status):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ final class MainViewController: BBNavigationViewController<MainViewReactor>, UIC

override func viewDidLoad() {
super.viewDidLoad()

UserDefaults.standard.inviteCode = nil
}

override func bind(reactor: MainViewReactor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extension MainPostCollectionViewCell {
}

missionBadge.isHidden = data.missionId == nil ? true : false
nameLabel.text = data.author?.name ?? "알 수 없음"
nameLabel.text = data.author.name
timeLabel.text = data.time.toDate(with: "yyyy-MM-dd'T'HH:mm:ssZ").relativeFormatter()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,21 @@ extension OnBoardingReactor {
public func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .permissionTapped:
return Observable.zip(
Observable.create { observer in
MPEvent.Account.invitedGroupFinished.track(with: nil)
UNUserNotificationCenter.current().requestAuthorization(
options: [.alert, .badge, .sound],
completionHandler: { granted, error in
if granted {
MPEvent.Account.allowNotification.track(with: nil)
}
observer.onNext(granted)
observer.onCompleted()
Observable.create { observer in
MPEvent.Account.invitedGroupFinished.track(with: nil)
UNUserNotificationCenter.current().requestAuthorization(
options: [.alert, .badge, .sound],
completionHandler: { granted, error in
if granted {
MPEvent.Account.allowNotification.track(with: nil)
}
)
return Disposables.create()
},
familyUseCase.executeFetchPaginationFamilyMembers(query: .init())
)
.flatMap { [weak self] (granted: Bool, _) -> Observable<Mutation> in
observer.onNext(granted)
observer.onCompleted()
}
)
return Disposables.create()
}
.flatMap { [weak self] (granted: Bool) -> Observable<Mutation> in
if granted {
return Observable.just(.permissionTapped)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension PostDetailViewReactor {
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .didTapProfileImageView:
let memberId = initialState.post.author?.memberId ?? .none
let memberId = initialState.post.author.memberId
if memberUseCase.executeCheckIsValidMember(memberId: memberId) {
provider.postGlobalState.pushProfileViewController(memberId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import RxCocoa
import RxDataSources

final class ReactionViewController: BaseViewController<ReactionViewReactor>, UICollectionViewDelegateFlowLayout {
let postListData: BehaviorRelay<PostEntity> = BehaviorRelay<PostEntity>(value: .init(postId: "", author: nil, commentCount: 0, emojiCount: 0, imageURL: "", content: nil, time: ""))
let postListData: BehaviorRelay<PostEntity> = BehaviorRelay<PostEntity>(value: PostEntity.empty)

private let selectedReactionSubject: PublishSubject<Void> = PublishSubject<Void>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class PostDetailCollectionViewCell: BaseCollectionViewCell<PostDetailViewR
self.init(frame: .zero)
self.reactor = reacter
}


override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -50,7 +50,7 @@ final class PostDetailCollectionViewCell: BaseCollectionViewCell<PostDetailViewR
profileImageView.image = nil
postImageView.image = nil
}

override func bind(reactor: PostDetailViewReactor) {
bindInput(reactor: reactor)
bindOutput(reactor: reactor)
Expand All @@ -64,7 +64,7 @@ final class PostDetailCollectionViewCell: BaseCollectionViewCell<PostDetailViewR
profileStackView.addArrangedSubviews(containerView, userNameLabel)
postImageView.addSubviews(contentCollectionView, missionTextView)
}

override func setupAutoLayout() {
super.setupAutoLayout()

Expand Down Expand Up @@ -197,7 +197,7 @@ extension PostDetailCollectionViewCell {
.bind(to: contentCollectionView.rx.items(dataSource: contentDatasource))
.disposed(by: disposeBag)

reactor.state.map { $0.post.author?.name[0] ?? "" }
reactor.state.map { $0.post.author.name[0] ?? "" }
.distinctUntilChanged()
.bind(to: firstNameLabel.rx.text)
.disposed(by: disposeBag)
Expand Down Expand Up @@ -234,7 +234,7 @@ extension PostDetailCollectionViewCell {
]
)

if let imageUrl = post.author?.profileImageURL {
if let imageUrl = post.author.profileImageURL {
profileImageView.kf.setImage(
with: URL(string: imageUrl),
options: [
Expand All @@ -243,9 +243,8 @@ extension PostDetailCollectionViewCell {
)
}

if let name = post.author?.name {
userNameLabel.text = name
}
userNameLabel.text = post.author.name

}
}

Expand All @@ -272,10 +271,10 @@ extension PostDetailCollectionViewCell: UICollectionViewDelegateFlowLayout {

let totalCellWidth = 28 * cellCount
let totalSpacingWidth = 2 * (cellCount - 1)

let leftInset = (collectionView.frame.width - CGFloat(totalCellWidth + totalSpacingWidth)) / 2
let rightInset = leftInset

return UIEdgeInsets(top: 0, left: leftInset, bottom: 0, right: rightInset)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Core
import Domain

import SnapKit
import RxSwift
import RxCocoa
import Then

final class PostNavigationView: BaseView<PostReactor> {
Expand All @@ -25,7 +27,7 @@ final class PostNavigationView: BaseView<PostReactor> {
self.init(frame: .zero)
self.reactor = reactor
}

override init(frame: CGRect) {
super.init(frame: frame)
}
Expand All @@ -42,9 +44,9 @@ final class PostNavigationView: BaseView<PostReactor> {

reactor.state
.map { $0.selectedPost }
.debug("selectedPost")
.asObservable()
.withUnretained(self)
.observe(on: MainScheduler.instance)
.bind(onNext: { $0.0.setData(data: $0.1) })
.disposed(by: disposeBag)
}
Expand Down Expand Up @@ -92,6 +94,7 @@ final class PostNavigationView: BaseView<PostReactor> {
}

profileImageView.do {
$0.isHidden = true
$0.clipsToBounds = true
$0.contentMode = .scaleAspectFill
$0.layer.cornerRadius = Layout.ProfileImageView.cornerRadius
Expand All @@ -101,25 +104,21 @@ final class PostNavigationView: BaseView<PostReactor> {

extension PostNavigationView {
private func setData(data: PostEntity) {
if let author = data.author,
let profileImageURL = author.profileImageURL,
let url = URL(string: profileImageURL), !profileImageURL.isEmpty {
profileImageView.kf.setImage(with: url)
defaultNameLabel.isHidden = true
} else {
if let author = data.author,
let first = author.name.first {
defaultNameLabel.text = "\(first)"
if let profileImageURL = data.author.profileImageURL,
let url = URL(string: profileImageURL),
!profileImageURL.isEmpty {
profileImageView.kf.setImage(with: url)
defaultNameLabel.isHidden = true
} else {
defaultNameLabel.text = ""
defaultNameLabel.text = "\(data.author.name.first ?? "")"
profileImageView.kf.base.image = nil
defaultNameLabel.isHidden = false
profileImageView.backgroundColor = .gray800
}

profileImageView.kf.base.image = nil
defaultNameLabel.isHidden = false
profileImageView.backgroundColor = .gray800
}

nameLabel.text = data.author?.name ?? "알 수 없음"

nameLabel.text = data.author.name
dateLabel.text = data.time.toDate(with: "yyyy-MM-dd'T'HH:mm:ssZ").relativeFormatter()

profileImageView.isHidden = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ReactorKit

final class ProfileFeedViewReactor: Reactor {
var initialState: State
@Injected private var feedUseCase: FetchMembersPostListUseCaseProtocol
@Injected private var feedUseCase: FetchPostListUseCaseProtocol
@Injected private var provider: ServiceProviderProtocol
enum Action {
case reloadFeedItems
Expand Down Expand Up @@ -146,8 +146,8 @@ final class ProfileFeedViewReactor: Reactor {
missionType: $0.missionType,
author: FamilyMemberProfileEntity(
memberId: currentState.memberId,
profileImageURL: $0.author?.profileImageURL,
name: $0.author?.name ?? ""),
profileImageURL: $0.author.profileImageURL,
name: $0.author.name),
commentCount: $0.commentCount,
emojiCount: $0.emojiCount,
imageURL: $0.imageURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ final class DeepLinkManager {
// 이번 3차 끝나고, postdetailviewcontroller에서 post 불러오는 형태로 바꿔보겠습니다.
let disposeBag: DisposeBag = DisposeBag()
let postRepository: PostListRepositoryProtocol = PostRepository()
lazy var postUseCase: FetchPostListUseCaseProtocol = FetchPostListUseCase(postListRepository: postRepository)
let familyRepository: FamilyRepositoryProtocol = FamilyRepository()
lazy var postUseCase: FetchPostListUseCaseProtocol = FetchPostListUseCase(
postListRepository: postRepository, familyRepository: familyRepository)

private init() {}

private func todayDeepLink(type: PostType, data: NotificationDeepLink) {
fetchTodayPost(type: type) { result in
guard let result = result else { return }
let items = result.postLists.map(PostSection.Item.main)
let items = result.map(PostSection.Item.main)

items.enumerated().forEach { (index, item) in
switch item {
Expand All @@ -56,7 +58,7 @@ final class DeepLinkManager {
private func todayCommentDeepLink(type: PostType, data: NotificationDeepLink) {
fetchTodayPost(type: type) { result in
guard let result = result else { return }
let items = result.postLists.map(PostSection.Item.main)
let items = result.map(PostSection.Item.main)

items.enumerated().forEach { (index, item) in
switch item {
Expand All @@ -71,12 +73,12 @@ final class DeepLinkManager {

}

private func fetchTodayPost(type: PostType, completion: @escaping (PostListPageEntity?) -> Void) {
private func fetchTodayPost(type: PostType, completion: @escaping ([PostEntity]?) -> Void) {
let dateString = Date().toFormatString(with: "yyyy-MM-dd")
let query = PostListQuery(date: dateString, type: type)

postUseCase.execute(query: query)
.subscribe(onSuccess: { result in
.subscribe(onNext: { result in
completion(result)
})
.disposed(by: disposeBag)
Expand Down Expand Up @@ -112,7 +114,7 @@ extension DeepLinkManager {
func handleWidgetDeepLink(data: WidgetDeepLink) {
fetchTodayPost(type: .survival) { result in
guard let result = result else { return }
let items = result.postLists.map(PostSection.Item.main)
let items = result.map(PostSection.Item.main)

items.enumerated().forEach { (index, item) in
switch item {
Expand Down
5 changes: 5 additions & 0 deletions 14th-team5-iOS/Core/Sources/Extensions/Reactive+Ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import RxCocoa
import RxSwift

extension Reactive where Base: UIViewController {
public var viewDidLoad: ControlEvent<Bool> {
let event = self.methodInvoked(#selector(Base.viewDidLoad)).map { $0.first as? Bool ?? false }
return ControlEvent(events: event)
}

public var viewWillAppear: ControlEvent<Bool> {
let event = self.methodInvoked(#selector(Base.viewWillAppear)).map { $0.first as? Bool ?? false }
return ControlEvent(events: event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension FamilyAPIWorker {

// MARK: - Fetch Family Member

public func fetchPaginationFamilyMember(familyId: String, query: FamilyPaginationQuery) -> Single<PaginationResponseFamilyMemberProfileDTO?> {
public func fetchPaginationFamilyMember(query: FamilyPaginationQuery) -> Single<PaginationResponseFamilyMemberProfileDTO?> {
let page = query.page
let size = query.size
let spec = FamilyAPIs.fetchPaginationFamilyMembers(page, size).spec
Expand Down
Loading

0 comments on commit 075d9f1

Please sign in to comment.