-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7db265
commit 6f1016e
Showing
3 changed files
with
111 additions
and
30 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
22 changes: 22 additions & 0 deletions
22
iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/Modal/ViewModel/ModalViewModel.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,22 @@ | ||
// | ||
// ModalViewModel.swift | ||
// iOS-NOTTODO | ||
// | ||
// Created by JEONGEUN KIM on 3/21/24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
protocol ModalViewModelPresentable {} | ||
|
||
protocol ModalViewModel: ViewModel where Input == ModalViewModelInput, Output == ModalViewModelOutput {} | ||
|
||
struct ModalViewModelInput { | ||
let viewWillAppearSubject: PassthroughSubject<Void, Never> | ||
let modalDismiss: PassthroughSubject<Void, Never> | ||
let safariDismiss: PassthroughSubject<ViewType, Never> | ||
let safariPresent: PassthroughSubject<Void, Never> | ||
} | ||
|
||
struct ModalViewModelOutput {} |
59 changes: 59 additions & 0 deletions
59
iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/Modal/ViewModel/ModalViewModelImpl.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,59 @@ | ||
// | ||
// ModalViewModelImpl.swift | ||
// iOS-NOTTODO | ||
// | ||
// Created by JEONGEUN KIM on 3/21/24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
final class ModalViewModelImpl: ModalViewModel { | ||
|
||
private weak var coordinator: MypageCoordinator? | ||
private var manager: MyPageManger | ||
private var cancelBag = Set<AnyCancellable>() | ||
|
||
init(coordinator: MypageCoordinator, manager: MyPageManger) { | ||
self.coordinator = coordinator | ||
self.manager = manager | ||
} | ||
|
||
func transform(input: ModalViewModelInput) -> ModalViewModelOutput { | ||
|
||
input.viewWillAppearSubject | ||
.sink { _ in | ||
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.AccountInfo.appearWithdrawalModal) | ||
} | ||
.store(in: &cancelBag) | ||
|
||
input.modalDismiss | ||
.sink { [weak self] _ in | ||
self?.coordinator?.dismiss() | ||
} | ||
.store(in: &cancelBag) | ||
|
||
input.safariDismiss | ||
.sink { [weak self] type in | ||
self?.coordinator?.connectAuthCoordinator(type: type) | ||
} | ||
.store(in: &cancelBag) | ||
|
||
input.safariPresent | ||
.sink { [weak self] _ in | ||
self?.withdrawal() | ||
} | ||
.store(in: &cancelBag) | ||
return Output() | ||
} | ||
|
||
func withdrawal() { | ||
manager.withdrawl() | ||
.sink(receiveCompletion: { event in | ||
print("completion: \(event)") | ||
}, receiveValue: { _ in | ||
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.AccountInfo.completeWithdrawal) | ||
}) | ||
.store(in: &cancelBag) | ||
} | ||
} |