후원랭킹 전체보기 추가
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// GetDonationAllResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/29.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetDonationAllResponse: Decodable {
|
||||
let accumulatedCansToday: Int
|
||||
let accumulatedCansLastWeek: Int
|
||||
let accumulatedCansThisMonth: Int
|
||||
let totalCount: Int
|
||||
let userDonationRanking: [UserDonationRankingResponse]
|
||||
}
|
@@ -0,0 +1,251 @@
|
||||
//
|
||||
// UserProfileDonationAllView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/29.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct UserProfileDonationAllView: View {
|
||||
|
||||
let userId: Int
|
||||
@StateObject var viewModel = UserProfileDonationAllViewModel()
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "후원랭킹 전체보기")
|
||||
|
||||
if userId == UserDefaults.int(forKey: .userId) {
|
||||
VStack(spacing: 13.3) {
|
||||
HStack(spacing: 0) {
|
||||
Text("오늘")
|
||||
.font(.custom(Font.bold.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(viewModel.accumulatedCansToday.comma())")
|
||||
.font(.custom(Font.bold.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(" 캔")
|
||||
.font(.custom(Font.light.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
}
|
||||
|
||||
HStack(spacing: 0) {
|
||||
Text("지난주")
|
||||
.font(.custom(Font.bold.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(viewModel.accumulatedCansLastWeek.comma())")
|
||||
.font(.custom(Font.bold.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(" 캔")
|
||||
.font(.custom(Font.light.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
}
|
||||
|
||||
HStack(spacing: 0) {
|
||||
Text("이번 달 어제까지")
|
||||
.font(.custom(Font.bold.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(viewModel.accumulatedCansThisMonth.comma())")
|
||||
.font(.custom(Font.bold.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(" 캔")
|
||||
.font(.custom(Font.light.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 16.7)
|
||||
.background(Color(hex: "2b2635"))
|
||||
.cornerRadius(8)
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 13.3)
|
||||
}
|
||||
|
||||
HStack(alignment: .center, spacing: 0) {
|
||||
Text("전체")
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text("\(viewModel.totalCount)")
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "9970ff"))
|
||||
.padding(.leading, 6.7)
|
||||
|
||||
Text("개")
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 13.3)
|
||||
|
||||
Rectangle()
|
||||
.frame(width: screenSize().width - 26.7, height: 1)
|
||||
.foregroundColor(Color(hex: "909090").opacity(0.5))
|
||||
.padding(.top, 6.7)
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(0..<viewModel.userDonationRanking.count, id: \.self) { index in
|
||||
let item = viewModel.userDonationRanking[index]
|
||||
UserProfileDonationAllItemView(
|
||||
index: index,
|
||||
item: item,
|
||||
withDonationCan: userId == UserDefaults.int(forKey: .userId),
|
||||
itemCount: viewModel.userDonationRanking.count
|
||||
)
|
||||
.onAppear {
|
||||
if index == viewModel.userDonationRanking.count - 1 {
|
||||
viewModel.getCreatorProfileDonationRanking()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 16.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.userId = userId
|
||||
viewModel.getCreatorProfileDonationRanking()
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .bottom, autohideIn: 2) {
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.frame(width: screenSize().width - 66.7, alignment: .center)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.background(Color(hex: "9970ff"))
|
||||
.foregroundColor(Color.white)
|
||||
.multilineTextAlignment(.leading)
|
||||
.cornerRadius(20)
|
||||
.padding(.bottom, 66.7)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct UserProfileDonationAllItemView: View {
|
||||
|
||||
let index: Int
|
||||
let item: UserDonationRankingResponse
|
||||
let withDonationCan: Bool
|
||||
let itemCount: Int
|
||||
|
||||
let rankingCrawns = ["ic_crown_1", "ic_crown_2", "ic_crown_3"]
|
||||
let rankingColors = [
|
||||
[Color(hex: "ffdc00"), Color(hex: "ffb600")],
|
||||
[Color(hex: "ffffff"), Color(hex: "9f9f9f")],
|
||||
[Color(hex: "e6a77a"), Color(hex: "c67e4a")],
|
||||
[Color(hex: "ffffff").opacity(0), Color(hex: "ffffff").opacity(0)]
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
ZStack {
|
||||
KFImage(URL(string: item.profileImage))
|
||||
.cancelOnDisappear(true)
|
||||
.downsampling(size: CGSize(width: 60, height: 60))
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 60, height: 60, alignment: .top)
|
||||
.clipShape(Circle())
|
||||
.overlay(
|
||||
Circle()
|
||||
.stroke(
|
||||
AngularGradient(colors: rankingColors[index < 4 ? index : 3], center: .center),
|
||||
lineWidth: 3
|
||||
)
|
||||
)
|
||||
|
||||
if index < 3 {
|
||||
VStack(alignment: .trailing, spacing: 0) {
|
||||
Spacer()
|
||||
|
||||
Image(rankingCrawns[index])
|
||||
.resizable()
|
||||
.frame(width: 25, height: 25)
|
||||
}
|
||||
.frame(width: 63, height: 63, alignment: .trailing)
|
||||
}
|
||||
}
|
||||
.frame(width: 63, height: 63)
|
||||
|
||||
Text("\(index + 1)")
|
||||
.font(.custom(Font.bold.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.padding(.leading, 20)
|
||||
.padding(.trailing, 13.3)
|
||||
|
||||
let nickname = item.nickname.count > 10 ? "\(String(item.nickname.prefix(10)))..." : item.nickname
|
||||
Text(nickname)
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
if let donationCan = item.donationCan, donationCan > 0, withDonationCan {
|
||||
Text("\(donationCan) 캔")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, isTop3Index(index: index) ? 20 : 0)
|
||||
.padding(.top, getTopPadding(index: index))
|
||||
.padding(.bottom, getBottomPadding(index: index))
|
||||
.background(Color(hex: "2b2635").opacity(isTop3Index(index: index) ? 1 : 0))
|
||||
.cornerRadius(4.7, corners: cornerRadiusConers(index: index))
|
||||
.padding(.horizontal, isTop3Index(index: index) ? 0 : 6.7)
|
||||
}
|
||||
|
||||
private func isTop3Index(index: Int) -> Bool {
|
||||
return index == 0 || index == 1 || index == 2
|
||||
}
|
||||
|
||||
private func getTopPadding(index: Int) -> CGFloat {
|
||||
if index == 0 || index == 3 {
|
||||
return 20
|
||||
} else {
|
||||
return 6.7
|
||||
}
|
||||
}
|
||||
|
||||
private func getBottomPadding(index: Int) -> CGFloat {
|
||||
if (index == 0 && itemCount == 1) || (index == 1 && itemCount == 2) || index == 2 {
|
||||
return 20
|
||||
} else {
|
||||
return 6.7
|
||||
}
|
||||
}
|
||||
|
||||
private func cornerRadiusConers(index: Int) -> UIRectCorner {
|
||||
if (index == 0 && itemCount == 1) {
|
||||
return [.topLeft, .topRight, .bottomLeft, .bottomRight]
|
||||
} else if index == 0 {
|
||||
return [.topLeft, .topRight]
|
||||
} else if (index == 1 && itemCount == 2) || index == 2 {
|
||||
return [.bottomLeft, .bottomRight]
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// UserProfileDonationAllViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/29.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class UserProfileDonationAllViewModel: ObservableObject {
|
||||
private var repository = ExplorerRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var totalCount = 0
|
||||
@Published var accumulatedCansToday = 0
|
||||
@Published var accumulatedCansLastWeek = 0
|
||||
@Published var accumulatedCansThisMonth = 0
|
||||
@Published var userDonationRanking: [UserDonationRankingResponse] = []
|
||||
|
||||
var userId = 0
|
||||
var page = 1
|
||||
var isLast = false
|
||||
private let pageSize = 10
|
||||
|
||||
func getCreatorProfileDonationRanking() {
|
||||
if (!isLast && !isLoading) {
|
||||
isLoading = true
|
||||
|
||||
repository.getCreatorProfileDonationRanking(userId: userId, page: page, size: pageSize)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetDonationAllResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.accumulatedCansToday = data.accumulatedCansToday
|
||||
self.accumulatedCansLastWeek = data.accumulatedCansLastWeek
|
||||
self.accumulatedCansThisMonth = data.accumulatedCansThisMonth
|
||||
|
||||
if !data.userDonationRanking.isEmpty {
|
||||
page += 1
|
||||
self.totalCount = data.totalCount
|
||||
self.userDonationRanking.append(contentsOf: data.userDonationRanking)
|
||||
} else {
|
||||
isLast = true
|
||||
}
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,7 +32,9 @@ struct UserProfileDonationView: View {
|
||||
Text("전체보기")
|
||||
.font(.custom(Font.light.rawValue, size: 11.3))
|
||||
.foregroundColor(Color(hex: "bbbbbb"))
|
||||
.onTapGesture {}
|
||||
.onTapGesture {
|
||||
AppState.shared.setAppStep(step: .userProfileDonationAll(userId: userId))
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
|
Reference in New Issue
Block a user