Skip to content

Commit

Permalink
[Feat] #222 - DetailClipVC Skeleton 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
mini-min committed Oct 18, 2024
1 parent 1874041 commit 6555e63
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit

import Kingfisher
import SkeletonView
import SnapKit
import Then

Expand Down Expand Up @@ -59,6 +60,7 @@ final class DetailClipListCollectionViewCell: UICollectionViewCell {
setupHierarchy()
setupLayout()
setupAddTarget()
setupSkeleton()
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -227,6 +229,13 @@ private extension DetailClipListCollectionViewCell {
modifiedButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

func setupSkeleton() {
isSkeletonable = true
[linkImage, linkTitleLabel, linkLabel, clipNameLabel, modifiedButton].forEach {
$0.isSkeletonable = true
}
}

@objc
func buttonTapped() {
buttonAction?()
Expand Down
20 changes: 17 additions & 3 deletions TOASTER-iOS/Present/DetailClip/View/DetailClipViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit

import SkeletonView
import SnapKit

final class DetailClipViewController: UIViewController {
Expand Down Expand Up @@ -66,9 +67,7 @@ private extension DetailClipViewController {
func setupStyle() {
view.backgroundColor = .toasterBackground
detailClipListCollectionView.backgroundColor = .toasterBackground
detailClipEmptyView.isHidden = false
editLinkBottomSheetView.editLinkBottomSheetViewDelegate = self

}

func setupHierarchy() {
Expand Down Expand Up @@ -108,6 +107,7 @@ private extension DetailClipViewController {

func setupViewModel() {
viewModel.setupDataChangeAction(changeAction: reloadCollectionView,
loadingAction: setupSkeleton,
forUnAuthorizedAction: unAuthorizedAction,
editNameAction: editLinkTitleAction)
}
Expand All @@ -117,6 +117,16 @@ private extension DetailClipViewController {
detailClipEmptyView.isHidden = isHidden
}

func setupSkeleton(isLoading: Bool) {
detailClipListCollectionView.isSkeletonable = true
if isLoading {
detailClipEmptyView.isHidden = true
detailClipListCollectionView.showAnimatedGradientSkeleton()
} else {
detailClipListCollectionView.hideSkeleton()
}
}

func unAuthorizedAction() {
changeViewController(viewController: LoginViewController())
}
Expand All @@ -139,7 +149,11 @@ private extension DetailClipViewController {

// MARK: - CollectionView DataSource

extension DetailClipViewController: UICollectionViewDataSource {
extension DetailClipViewController: SkeletonCollectionViewDataSource {
func collectionSkeletonView(_ skeletonView: UICollectionView, cellIdentifierForItemAt indexPath: IndexPath) -> SkeletonView.ReusableCellIdentifier {
return DetailClipListCollectionViewCell.className
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return viewModel.toastList.toastList.count
}
Expand Down
29 changes: 18 additions & 11 deletions TOASTER-iOS/Present/DetailClip/ViewModel/DetailClipViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class DetailClipViewModel: NSObject {

typealias DataChangeAction = (Bool) -> Void
private var dataChangeAction: DataChangeAction?
private var loadingStatusAction: DataChangeAction?

typealias NormalChangeAction = () -> Void
private var unAuthorizedAction: NormalChangeAction?
Expand All @@ -43,9 +44,11 @@ final class DetailClipViewModel: NSObject {

extension DetailClipViewModel {
func setupDataChangeAction(changeAction: @escaping DataChangeAction,
loadingAction: @escaping DataChangeAction,
forUnAuthorizedAction: @escaping NormalChangeAction,
editNameAction: @escaping NormalChangeAction) {
dataChangeAction = changeAction
loadingStatusAction = loadingAction
unAuthorizedAction = forUnAuthorizedAction
editLinkTitleAction = editNameAction
}
Expand All @@ -66,17 +69,19 @@ extension DetailClipViewModel {
}

func getDetailAllCategoryAPI(filter: DetailCategoryFilter) {
loadingStatusAction?(true)
NetworkService.shared.clipService.getDetailAllCategory(filter: filter) { result in
self.loadingStatusAction?(false)
switch result {
case .success(let response):
let allToastCount = response?.data.allToastNum
let toasts = response?.data.toastListDto.map {
ToastListModel(id: $0.toastId,
title: $0.toastTitle,
url: $0.linkUrl,
isRead: $0.isRead,
clipTitle: $0.categoryTitle,
imageURL: $0.thumbnailUrl)
title: $0.toastTitle,
url: $0.linkUrl,
isRead: $0.isRead,
clipTitle: $0.categoryTitle,
imageURL: $0.thumbnailUrl)
}
self.toastList = DetailClipModel(allToastCount: allToastCount ?? 0,
toastList: toasts ?? [])
Expand All @@ -87,20 +92,22 @@ extension DetailClipViewModel {
}
}

func getDetailCategoryAPI(categoryID: Int,
func getDetailCategoryAPI(categoryID: Int,
filter: DetailCategoryFilter,
completion: (() -> Void)? = nil) {
loadingStatusAction?(true)
NetworkService.shared.clipService.getDetailCategory(categoryID: categoryID, filter: filter) { result in
self.loadingStatusAction?(false)
switch result {
case .success(let response):
let allToastCount = response?.data.allToastNum
let toasts = response?.data.toastListDto.map {
ToastListModel(id: $0.toastId,
title: $0.toastTitle,
url: $0.linkUrl,
isRead: $0.isRead,
clipTitle: $0.categoryTitle,
imageURL: $0.thumbnailUrl)
title: $0.toastTitle,
url: $0.linkUrl,
isRead: $0.isRead,
clipTitle: $0.categoryTitle,
imageURL: $0.thumbnailUrl)
}
self.toastList = DetailClipModel(allToastCount: allToastCount ?? 0,
toastList: toasts ?? [])
Expand Down

0 comments on commit 6555e63

Please sign in to comment.