-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 홈 동기화 작업 추가
- Loading branch information
Showing
12 changed files
with
406 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
14th-team5-iOS/App/Sources/Presentation/Home/Dependency/HomeFamilyDIContainer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
|
||
} |
125 changes: 125 additions & 0 deletions
125
14th-team5-iOS/App/Sources/Presentation/Home/Reactor/HomeFamilyViewReactor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.