Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (#976) ์—ด๋งค ์†Œ๋น„๊ฐ€ ํ•„์š”ํ•œ ๋กœ์ง ์ดํ›„ ์œ ์ €์ •๋ณด๋ฅผ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค. #979

Merged
merged 3 commits into from
Aug 3, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ public final class ContainSongsViewModel: ViewModelType {
description: "์ด๋ฏธ ๋‚ด ๋ฆฌ์ŠคํŠธ์— ๋‹ด๊ธด ๊ณก๋“ค์ž…๋‹ˆ๋‹ค."
))

case .badRequest:
output.showToastMessage.onNext(BaseEntity(
status: 400,
description: "๋…ธ๋ž˜๋Š” ์ตœ๋Œ€ 50๊ฐœ๊นŒ์ง€ ์„ ํƒ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค."
))

default:
output.showToastMessage.onNext(BaseEntity(status: 400, description: "์ž˜๋ชป๋œ ์š”์ฒญ์ž…๋‹ˆ๋‹ค."))
}
Expand Down Expand Up @@ -205,6 +199,9 @@ public final class ContainSongsViewModel: ViewModelType {
output.showToastMessage.onNext(BaseEntity(status: 400, description: wmError.errorDescription!))
})
.map { _ in BaseEntity(status: 201, description: "ํ”Œ๋ ˆ์ด๋ฆฌ์ŠคํŠธ๋ฅผ ์„ฑ๊ณก์ ์œผ๋กœ ์ƒ์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.") }
.do(onNext: { _ in
NotificationCenter.default.post(name: .willRefreshUserInfo, object: nil)
})
.bind(to: output.showToastMessage)
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,19 @@ final class MyInfoReactor: Reactor {
private let fetchNoticeIDListUseCase: any FetchNoticeIDListUseCase
private let setUsernameUseCase: any SetUserNameUseCase
private let fetchUserInfoUseCase: any FetchUserInfoUseCase
private let myInfoCommonService: any MyInfoCommonService
private let disposeBag = DisposeBag()

init(
fetchNoticeIDListUseCase: any FetchNoticeIDListUseCase,
setUserNameUseCase: any SetUserNameUseCase,
fetchUserInfoUseCase: any FetchUserInfoUseCase
fetchUserInfoUseCase: any FetchUserInfoUseCase,
myInfoCommonService: any MyInfoCommonService = DefaultMyInfoCommonService.shared
) {
self.fetchNoticeIDListUseCase = fetchNoticeIDListUseCase
self.setUsernameUseCase = setUserNameUseCase
self.fetchUserInfoUseCase = fetchUserInfoUseCase
self.myInfoCommonService = myInfoCommonService
self.initialState = .init(
isLoggedIn: false,
profileImage: "",
Expand Down Expand Up @@ -169,6 +172,15 @@ final class MyInfoReactor: Reactor {
}
return newState
}

func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let willRefreshUserInfoMutation = myInfoCommonService.willRefreshUserInfoEvent.withUnretained(self)
.flatMap { owner, _ -> Observable<Mutation> in
return owner.fetchUserInfo()
}

return Observable.merge(willRefreshUserInfoMutation, mutation)
}
}

private extension MyInfoReactor {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation
import RxSwift
import Utility

protocol MyInfoCommonService {
var willRefreshUserInfoEvent: Observable<Notification> { get }
}

final class DefaultMyInfoCommonService: MyInfoCommonService {
let willRefreshUserInfoEvent: Observable<Notification>
static let shared = DefaultMyInfoCommonService()

init() {
let notificationCenter = NotificationCenter.default
willRefreshUserInfoEvent = notificationCenter.rx.notification(.willRefreshUserInfo)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class MyPlaylistDetailReactor: Reactor {
case updateImageData(PlaylistImageKind?)
case showToast(String)
case showShareLink(String)
case updateRefresh
case updateNotiName(Notification.Name)
}

struct State {
Expand All @@ -48,7 +48,7 @@ final class MyPlaylistDetailReactor: Reactor {
var imageData: PlaylistImageKind?
@Pulse var toastMessage: String?
@Pulse var shareLink: String?
@Pulse var refresh: Void?
@Pulse var notiName: Notification.Name?
}

internal let key: String
Expand Down Expand Up @@ -97,7 +97,7 @@ final class MyPlaylistDetailReactor: Reactor {
backupPlaylistModels: [],
isLoading: true,
selectedCount: 0,
refresh: nil
notiName: nil
)
}

Expand Down Expand Up @@ -174,8 +174,8 @@ final class MyPlaylistDetailReactor: Reactor {

case let .showShareLink(link):
newState.shareLink = link
case .updateRefresh:
newState.refresh = ()
case let .updateNotiName(notiName):
newState.notiName = notiName
}

return newState
Expand Down Expand Up @@ -263,7 +263,10 @@ private extension MyPlaylistDetailReactor {
case let .custom(data):
mutations.append(
requestCustomImageURLUseCase.execute(key: self.key, data: data)
.andThen(.empty())
.andThen(.concat([
updateNotiName(notiName: .playlistRefresh), // ํ”Œ๋ฆฌ ์ด๋ฏธ์ง€ ๊ฐฑ์‹ 
updateNotiName(notiName: .willRefreshUserInfo) // ์—ด๋งค ๊ฐฑ์‹ 
]))
.catch { error in
let wmErorr = error.asWMError
return Observable.just(
Expand Down Expand Up @@ -339,7 +342,7 @@ private extension MyPlaylistDetailReactor {
return .concat([
.just(.updateHeader(prev)),
updateTitleAndPrivateUseCase.execute(key: key, title: text, isPrivate: nil)
.andThen(updateSendRefreshNoti())
.andThen(updateNotiName(notiName: .playlistRefresh))
])
}
}
Expand Down Expand Up @@ -446,7 +449,7 @@ private extension MyPlaylistDetailReactor {
.just(.updateSelectedCount(0)),
.just(.updateHeader(prevHeader)),
.just(.showToast("\(remainSongs.count)๊ฐœ์˜ ๊ณก์„ ์‚ญ์ œํ–ˆ์Šต๋‹ˆ๋‹ค.")),
updateSendRefreshNoti()
updateNotiName(notiName: .playlistRefresh)

]))
.catch { error in
Expand All @@ -461,7 +464,7 @@ private extension MyPlaylistDetailReactor {
return .just(.updateImageData(imageData))
}

func updateSendRefreshNoti() -> Observable<Mutation> {
.just(.updateRefresh)
func updateNotiName(notiName: Notification.Name) -> Observable<Mutation> {
.just(.updateNotiName(notiName))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ final class MyPlaylistDetailViewController: BaseReactorViewController<MyPlaylist
}
.disposed(by: disposeBag)

reactor.pulse(\.$refresh)
reactor.pulse(\.$notiName)
.compactMap { $0 }
.bind(with: self) { owner, _ in
NotificationCenter.default.post(name: .playlistRefresh, object: nil)
.bind(with: self) { owner, name in
NotificationCenter.default.post(name: name, object: nil)
}
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public extension Notification.Name {
static let playlistRefresh = Notification.Name("playlistRefresh") // ํ”Œ๋ ˆ์ด๋ฆฌ์ŠคํŠธ ๋ชฉ๋ก ๊ฐฑ์‹ (๋ณด๊ด€ํ•จ ๊ฐ™์€) (๋…ธ๋ž˜๋ชฉ๋ก ์•„๋‹˜)
static let likeListRefresh = Notification.Name("likeListRefresh")
static let subscriptionPlaylistDidRemoved = Notification.Name("subscriptionPlaylistDidRemoved") // ๋ณด๊ด€ํ•จ์—์„œ ๊ตฌ๋…ํ”Œ๋ฆฌ ์ œ๊ฑฐ
static let willRefreshUserInfo = Notification.Name("willRefreshUserInfo") // ์œ ์ € ์ •๋ณด ๊ฐฑ์‹ 
static let statusBarEnterDarkBackground = Notification.Name("statusBarEnterDarkBackground")
static let statusBarEnterLightBackground = Notification.Name("statusBarEnterLightBackground")
static let showSongCart = Notification.Name("showSongCart")
Expand Down
Loading