feat(original): 작품별 상세 UI 변경
- 캐릭터 / 작품 정보 탭 추가 - 작품 정보 탭 구성 - 작품 소개 - 원작 보러 가기 - 상세 정보 - 작가 - 제작사 - 원작
This commit is contained in:
@@ -10,10 +10,14 @@ import Combine
|
||||
import Moya
|
||||
|
||||
final class OriginalWorkDetailViewModel: ObservableObject {
|
||||
enum CurrentTab: String {
|
||||
case character, info
|
||||
}
|
||||
|
||||
@Published var currentTab: CurrentTab = .character
|
||||
@Published var isLoading = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoadingMore: Bool = false
|
||||
|
||||
@Published private(set) var characters: [Character] = []
|
||||
@Published private(set) var totalCount: Int = 0
|
||||
@@ -21,8 +25,6 @@ final class OriginalWorkDetailViewModel: ObservableObject {
|
||||
|
||||
private let repository = OriginalWorkRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
private var currentPage: Int = 0
|
||||
private var hasMorePages: Bool = true
|
||||
|
||||
var originalId: Int = 0 {
|
||||
didSet {
|
||||
@@ -31,14 +33,6 @@ final class OriginalWorkDetailViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
func loadMoreIfNeeded(currentIndex: Int) {
|
||||
guard hasMorePages,
|
||||
!isLoading,
|
||||
!isLoadingMore,
|
||||
currentIndex >= characters.count - 3 else { return }
|
||||
fetchCharacters()
|
||||
}
|
||||
|
||||
private func fetchDetail() {
|
||||
isLoading = true
|
||||
|
||||
@@ -80,53 +74,4 @@ final class OriginalWorkDetailViewModel: ObservableObject {
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func fetchCharacters() {
|
||||
currentPage += 1
|
||||
isLoadingMore = true
|
||||
|
||||
repository.getOriginalWorkCharacters(id: originalId, page: currentPage)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] completion in
|
||||
switch completion {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self?.isLoadingMore = false
|
||||
self?.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self?.isShowPopup = true
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<OriginalWorkCharactersPageResponse>.self, from: response.data)
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.totalCount = data.totalCount
|
||||
|
||||
if !data.content.isEmpty {
|
||||
self.characters.append(contentsOf: data.content)
|
||||
} else {
|
||||
hasMorePages = false
|
||||
}
|
||||
|
||||
self.isLoadingMore = false
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
self.isShowPopup = true
|
||||
self.isLoadingMore = false
|
||||
}
|
||||
} catch {
|
||||
self.isLoading = false
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user