Files
sodalive-ios/SodaLive/Sources/Home/HomeCreatorRankingItemView.swift

98 lines
3.0 KiB
Swift

//
// HomeCreatorRankingItemView.swift
// SodaLive
//
// Created by klaus on 7/11/25.
//
import SwiftUI
import Kingfisher
struct HomeCreatorRankingItemView: View {
let rank: Int
@Binding var item: GetExplorerSectionCreatorResponse
let onClickFollow: (Int, Bool) -> Void
let crowns = ["img_rank_1", "img_rank_2", "img_rank_3"]
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
var body: some View {
VStack(spacing: 0) {
ZStack(alignment: .center) {
DownsampledKFImage(
url: URL(string: item.profileImageUrl),
size: CGSize(width: 84, height: 84)
)
.clipShape(Circle())
if rank <= 3 {
Image(crowns[rank - 1])
.resizable()
.frame(width: 108, height: 105)
}
}
.frame(width: 108, height: 105)
Spacer()
Text(item.nickname)
.font(.custom(Font.preRegular.rawValue, size: 16))
.foregroundColor(.white)
Spacer()
if item.id != UserDefaults.int(forKey: .userId) {
Text(item.follow ? "팔로잉" : "팔로우")
.font(.custom(Font.preRegular.rawValue, size: 14))
.padding(.vertical, 4)
.frame(maxWidth: .infinity)
.background(
item.follow ? Color(hex: "455a64") : Color.white
)
.cornerRadius(999)
.foregroundColor(
item.follow ? .white : Color(hex: "263238")
)
.onTapGesture {
let trimmedToken = token.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmedToken.isEmpty else {
onClickFollow(item.id, item.follow)
return
}
if item.follow {
onClickFollow(item.id, false)
} else {
item.follow = true
onClickFollow(item.id, true)
}
}
}
}
.padding(16)
.frame(width: 144, height: 204)
.background(Color(hex: "263238"))
.cornerRadius(16)
.padding(.top, 20)
}
}
#Preview {
HomeCreatorRankingItemView(
rank: 1,
item: .constant(
GetExplorerSectionCreatorResponse(
id: 1,
nickname: "유빈ASMR",
tags: "",
profileImageUrl: "https://cf.sodalive.net/profile/34806/34806-profile-49db6b45-bb1e-4dc7-917e-1a614a853f5f-4232-1752158072656",
follow: true
)
),
onClickFollow: { _, _ in }
)
}