-
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
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
Projects/Features/MemeDetail/Sources/Presentation/MemeDetailViewModel.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,90 @@ | ||
// | ||
// MemeDetailViewModel.swift | ||
// MemeDetail | ||
// | ||
// Created by kimchansoo on 6/29/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Dependencies | ||
|
||
import PPACUtil | ||
import PPACModels | ||
import UIKit | ||
|
||
protocol MemeDetailRouting: AnyObject { | ||
func popView() | ||
func showShareView() | ||
} | ||
|
||
final class MemeDetailViewModel: ViewModelType, ObservableObject { | ||
|
||
enum Action { | ||
case likeButtonTapped | ||
case copyButtonTapped | ||
case shreButtonTapped | ||
case farmemeButtonTapped | ||
case naviBackButtonTapped | ||
} | ||
|
||
struct State { | ||
var meme: MemeDetail | ||
} | ||
|
||
// MARK: - Properties | ||
|
||
weak var router: MemeDetailRouting? | ||
@Published var state: State | ||
|
||
private let copyImageUseCase: CopyImageUseCase | ||
private let postLikeUseCase: PostLikeUseCase | ||
|
||
|
||
// MARK: - Initializers | ||
|
||
init( | ||
meme: MemeDetail, | ||
router: MemeDetailRouting?, | ||
copyImageUseCase: CopyImageUseCase, | ||
postLikeUseCase: PostLikeUseCase | ||
) { | ||
self.router = router | ||
self.state = State(meme: meme) | ||
self.copyImageUseCase = copyImageUseCase | ||
self.postLikeUseCase = postLikeUseCase | ||
} | ||
|
||
// MARK: - Methods | ||
|
||
func dispatch(type: Action) { | ||
switch type { | ||
case .likeButtonTapped: | ||
postLike() | ||
case .copyButtonTapped: | ||
copyImage() | ||
case .shreButtonTapped: | ||
router?.showShareView() | ||
case .farmemeButtonTapped: | ||
postSavedFarmeme() | ||
case .naviBackButtonTapped: | ||
router?.popView() | ||
} | ||
} | ||
} | ||
|
||
private extension MemeDetailViewModel { | ||
func postLike() { | ||
|
||
} | ||
|
||
func copyImage() { | ||
// TODO: - 이미지 viewmodel이 알지 못하도록 수정 | ||
let imageData: Data = try! Data(contentsOf: URL(string: state.meme.imageUrlString)!) | ||
copyImageUseCase.execute(data: imageData) | ||
} | ||
|
||
func postSavedFarmeme() { | ||
|
||
} | ||
} |