Skip to content

Commit

Permalink
Merge pull request #271 from depromeet/feat/#263-add-sync-at-home
Browse files Browse the repository at this point in the history
feat: 홈 동기화 작업 추가
  • Loading branch information
rlarjsdn3 authored Jan 14, 2024
2 parents 90673fb + 4571361 commit c910300
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class FamilyManagementDIContainer: BaseDIContainer {
}

public func makeUsecase() -> UseCase {
return InviteFamilyViewUseCase(familyRepository: makeRepository())
return FamilyViewUseCase(familyRepository: makeRepository())
}

public func makeRepository() -> FamilyRepositoryProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public final class HomeDIContainer {
}

func makeInviteFamilyUseCase() -> FamilyViewUseCaseProtocol {
return InviteFamilyViewUseCase(familyRepository: makeInviteFamilyRepository())
return FamilyViewUseCase(familyRepository: makeInviteFamilyRepository())
}

public func makeReactor() -> Reactor {
return HomeViewReactor(familyRepository: makeFamilyUseCase(), postRepository: makePostUseCase(), familyUseCase: makeInviteFamilyUseCase())
return HomeViewReactor(postRepository: makePostUseCase())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// HomeFamilyDIContainer.swift
// App
//
// Created by 마경미 on 14.01.24.
//

import Foundation

import Domain
import Data

final class HomeFamilyDIContainer {
func makeViewController() -> HomeFamilyViewController {
return HomeFamilyViewController(reactor: makeReactor())
}

public func makeFamilyRepository() -> SearchFamilyRepository {
return FamilyAPIs.Worker()
}

public func makeInviteFamilyRepository() -> FamilyRepositoryProtocol {
return FamilyRepository()
}

func makeFamilyUseCase() -> SearchFamilyMemberUseCaseProtocol {
return SearchFamilyUseCase(searchFamilyRepository: makeFamilyRepository())
}

func makeInviteFamilyUseCase() -> FamilyViewUseCaseProtocol {
return FamilyViewUseCase(familyRepository: makeInviteFamilyRepository())
}

public func makeReactor() -> HomeFamilyViewReactor {
return HomeFamilyViewReactor(searchFamilyUseCase: makeFamilyUseCase(), inviteFamilyUseCase: makeInviteFamilyUseCase())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//
// HomeFamilyViewReactor.swift
// App
//
// Created by 마경미 on 13.01.24.
//

import Foundation

import Core
import Domain

import ReactorKit
import RxDataSources

public final class HomeFamilyViewReactor: Reactor {
public enum Action {
case getFamilyMembers
case tapInviteFamily
case refreshCollectionview
}

public enum Mutation {
case setLoading(Bool)
case showShareAcitivityView(URL?)
case showInviteFamilyView
case setFamilyCollectionView([SectionModel<String, ProfileData>])
case setCopySuccessToastMessageView
case setFetchFailureToastMessageView
case setSharePanel(String)
case setRefreshing(Bool)
}

public struct State {
var isRefreshing: Bool = false
var showLoading: Bool = true
var isShowingInviteFamilyView: Bool = false
var familySections: [SectionModel<String, ProfileData>] = []
@Pulse var familyInvitationLink: URL?
@Pulse var shouldPresentCopySuccessToastMessageView: Bool = false
@Pulse var shouldPresentFetchFailureToastMessageView: Bool = false
}

public let initialState: State = State()
public let provider: GlobalStateProviderProtocol = GlobalStateProvider()
private let searchFamilyUseCase: SearchFamilyMemberUseCaseProtocol
private let inviteFamilyUseCase: FamilyViewUseCaseProtocol

init(searchFamilyUseCase: SearchFamilyMemberUseCaseProtocol, inviteFamilyUseCase: FamilyViewUseCaseProtocol) {
self.inviteFamilyUseCase = inviteFamilyUseCase
self.searchFamilyUseCase = searchFamilyUseCase
}
}

extension HomeFamilyViewReactor {
public func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let eventMutation = provider.activityGlobalState.event
.flatMap { event -> Observable<Mutation> in
switch event {
case .didTapCopyInvitationUrlAction:
return Observable<Mutation>.just(.setCopySuccessToastMessageView)
}
}

return Observable<Mutation>.merge(mutation, eventMutation)
}

public func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .tapInviteFamily:
return inviteFamilyUseCase.executeFetchInvitationUrl()
.map {
guard let invitationLink = $0?.url else {
return .setFetchFailureToastMessageView
}
return .setSharePanel(invitationLink)
}
case .getFamilyMembers:
let query: SearchFamilyQuery = SearchFamilyQuery(type: "FAMILY", page: 1, size: 20)
return searchFamilyUseCase.excute(query: query)
.asObservable()
.flatMap { familyMembers in
guard let familyMembers,
familyMembers.members.count > 1 else {
return Observable.just(Mutation.showInviteFamilyView)
}

var observables = [Observable.just(Mutation.setFamilyCollectionView([
SectionModel<String, ProfileData>(model: "section1", items: familyMembers.members)]))]


observables.append(Observable.just(Mutation.setRefreshing(false)))
return Observable.concat(observables)
}
case .refreshCollectionview:
let getFamilyMembersAction = Action.getFamilyMembers
return mutate(action: getFamilyMembersAction)
}
}

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

switch mutation {
case .showInviteFamilyView:
newState.isShowingInviteFamilyView = true
case let .setFamilyCollectionView(data):
newState.familySections = data
case let .showShareAcitivityView(url):
newState.familyInvitationLink = url
case .setLoading:
newState.showLoading = false
case .setCopySuccessToastMessageView:
newState.shouldPresentCopySuccessToastMessageView = true
case .setFetchFailureToastMessageView:
newState.shouldPresentFetchFailureToastMessageView = true
case let .setSharePanel(urlString):
newState.familyInvitationLink = URL(string: urlString)
case let .setRefreshing(isRefreshing):
newState.isRefreshing = isRefreshing
}

return newState
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,123 +14,52 @@ import RxDataSources

public final class HomeViewReactor: Reactor {
public enum Action {
case viewDidLoad
case getFamilyMembers
case getTodayPostList
case tapInviteFamily
case refreshCollectionview
}

public enum Mutation {
case setFamilyResponse(FamilyResponse?)
case setLoading(Bool)
case setDidPost
case setDescriptionText(String)
case showShareAcitivityView(URL?)
case showInviteFamilyView
case showNoPostTodayView
case setFamilyCollectionView([SectionModel<String, ProfileData>])
case setPostCollectionView([SectionModel<String, PostListData>])
case setCopySuccessToastMessageView
case setFetchFailureToastMessageView
case setSharePanel(String)
case setRefreshing(Bool)
}

public struct State {
var familyResponse: FamilyResponse?
@Pulse var familyInvitationLink: URL?
var isRefreshing: Bool = false
var showLoading: Bool = true
var didPost: Bool = false
var descriptionText: String = HomeStrings.Description.standard
var isShowingNoPostTodayView: Bool = false
var isShowingInviteFamilyView: Bool = false
var familySections: [SectionModel<String, ProfileData>] = []
var feedSections: [SectionModel<String, PostListData>] = []
@Pulse var shouldPresentCopySuccessToastMessageView: Bool = false
@Pulse var shouldPresentFetchFailureToastMessageView: Bool = false
}

public let initialState: State = State()
public let provider: GlobalStateProviderProtocol = GlobalStateProvider()
private let familyRepository: SearchFamilyMemberUseCaseProtocol
private let postRepository: PostListUseCaseProtocol
private let familyUseCase: FamilyViewUseCaseProtocol

init(familyRepository: SearchFamilyMemberUseCaseProtocol, postRepository: PostListUseCaseProtocol, familyUseCase: FamilyViewUseCaseProtocol) {
self.familyUseCase = familyUseCase
self.familyRepository = familyRepository
init(postRepository: PostListUseCaseProtocol) {
self.postRepository = postRepository
}
}

extension HomeViewReactor {
public func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let eventMutation = provider.activityGlobalState.event
.flatMap { event -> Observable<Mutation> in
switch event {
case .didTapCopyInvitationUrlAction:
return Observable<Mutation>.just(.setCopySuccessToastMessageView)
}
}

return Observable<Mutation>.merge(mutation, eventMutation)
}

public func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .viewDidLoad:
// guard App.Repository.member.familyId.value == nil else {
// return .empty()
// }
//
// return familyUseCase.executeCreateFamily()
// .map {
// guard let familyResponse: FamilyResponse = $0 else {
// return .setFamilyResponse(nil)
// }
// return .setFamilyResponse(familyResponse)
// }
return Observable.empty()

case .tapInviteFamily:
return familyUseCase.executeFetchInvitationUrl()
.map {
guard let invitationLink = $0?.url else {
return .setFetchFailureToastMessageView
}
return .setSharePanel(invitationLink)
}
case .getFamilyMembers:
let query: SearchFamilyQuery = SearchFamilyQuery(type: "FAMILY", page: 1, size: 20)
return familyRepository.excute(query: query)
.asObservable()
.flatMap { familyMembers in
guard let familyMembers else {
return Observable.just(Mutation.showInviteFamilyView)
}
if familyMembers.members.count == 1 {
return Observable.just(Mutation.showInviteFamilyView)
} else {
return Observable.just(.setFamilyCollectionView([
SectionModel<String, ProfileData>(model: "section1", items: familyMembers.members)
]))
}
}
case .getTodayPostList:
let query: PostListQuery = PostListQuery(page: 1, size: 20, date: Date().toFormatString(with: "YYYY-MM-DD"), memberId: "", sort: .desc)
return postRepository.excute(query: query)
.asObservable()
.flatMap { postList in
guard let postList else {
return Observable.just(Mutation.showNoPostTodayView)
}

if postList.postLists.isEmpty {
guard let postList,
!postList.postLists.isEmpty else {
return Observable.just(Mutation.showNoPostTodayView)
}

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

if postList.selfUploaded {
observables.append(Observable.just(Mutation.setDidPost))
}
Expand All @@ -139,43 +68,31 @@ extension HomeViewReactor {
observables.append(Observable.just(Mutation.setDescriptionText("우리 가족 모두가 사진을 올린 날🎉")))
}

observables.append(Observable.just(Mutation.setRefreshing(false)))
return Observable.concat(observables)
}
case .refreshCollectionview:
let getTodayPostListAction = Action.getTodayPostList
return mutate(action: getTodayPostListAction)
}
}

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

switch mutation {
// case .setTimerStatus:
// newState.descriptionText = HomeStringLiterals.Description.standard
case .showInviteFamilyView:
newState.isShowingInviteFamilyView = true
case let .setFamilyCollectionView(data):
newState.familySections = data
case .showNoPostTodayView:
newState.isShowingNoPostTodayView = true
case let .setPostCollectionView(data):
newState.feedSections = data
case let .showShareAcitivityView(url):
newState.familyInvitationLink = url
case .setDidPost:
newState.didPost = true
case .setDescriptionText(_):
break
case let .setDescriptionText(message):
newState.descriptionText = message
case .setLoading:
newState.showLoading = false
case .setCopySuccessToastMessageView:
newState.shouldPresentCopySuccessToastMessageView = true
case .setFetchFailureToastMessageView:
newState.shouldPresentFetchFailureToastMessageView = true
case let .setSharePanel(urlString):
newState.familyInvitationLink = URL(string: urlString)
case let .setFamilyResponse(familyResponse):
App.Repository.member.familyId.accept(familyResponse?.familyId)

newState.familyResponse = familyResponse
case let .setRefreshing(isRefreshing):
newState.isRefreshing = isRefreshing
}

return newState
Expand Down
Loading

0 comments on commit c910300

Please sign in to comment.