Skip to content

Commit

Permalink
[Feat] sopt-makers#336 - 내 친구 뷰에 토스트 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Dec 27, 2023
1 parent f5a7da6 commit 70a9bc5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol PokeMyFriendsUseCase {
var myFriends: PassthroughSubject<PokeMyFriendsModel, Never> { get }
var myFriendsList: PassthroughSubject<PokeMyFriendsListModel, Never> { get }
var pokedResponse: PassthroughSubject<PokeUserModel, Never> { get }
var errorMessage: PassthroughSubject<String?, Never> { get }

func getFriends()
func getFriends(relation: String, page: Int)
Expand All @@ -27,6 +28,7 @@ public class DefaultPokeMyFriendsUseCase {
public let myFriends = PassthroughSubject<PokeMyFriendsModel, Never>()
public let myFriendsList = PassthroughSubject<PokeMyFriendsListModel, Never>()
public let pokedResponse = PassthroughSubject<PokeUserModel, Never>()
public let errorMessage = PassthroughSubject<String?, Never>()

public init(repository: PokeMyFriendsRepositoryInterface) {
self.repository = repository
Expand Down Expand Up @@ -55,9 +57,11 @@ extension DefaultPokeMyFriendsUseCase: PokeMyFriendsUseCase {
public func poke(userId: Int, message: PokeMessageModel) {
self.repository
.poke(userId: userId, message: message.content)
.sink { event in
print("Poke State: \(event)")
} receiveValue: { [weak self] user in
.catch { [weak self] error in
let message = error.toastMessage
self?.errorMessage.send(message)
return Empty<PokeUserModel, Never>()
}.sink { [weak self] user in
self?.pokedResponse.send(user)
}.store(in: self.cancelBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Core
import Domain

import PokeFeatureInterface
import BaseFeatureDependency

public class PokeMyFriendsListViewModel:
PokeMyFriendsListViewModelType {
Expand Down Expand Up @@ -119,5 +120,11 @@ extension PokeMyFriendsListViewModel {

output.needToReloadFriendList.send()
}.store(in: cancelBag)

useCase.errorMessage
.compactMap { $0 }
.sink { message in
ToastUtils.showMDSToast(type: .alert, text: message)
}.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Core
import Domain

import PokeFeatureInterface
import BaseFeatureDependency

public class PokeMyFriendsViewModel:
PokeMyFriendsViewModelType {
Expand Down Expand Up @@ -103,5 +104,11 @@ extension PokeMyFriendsViewModel {
output.myFriends.send(myFriends)
}
}.store(in: cancelBag)

useCase.errorMessage
.compactMap { $0 }
.sink { message in
ToastUtils.showMDSToast(type: .alert, text: message)
}.store(in: cancelBag)
}
}

0 comments on commit 70a9bc5

Please sign in to comment.