88 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  HomeCreatorRankingItemView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 7/11/25.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
import Kingfisher
 | 
						|
 | 
						|
struct HomeCreatorRankingItemView: View {
 | 
						|
    
 | 
						|
    let rank: Int
 | 
						|
    @State var item: GetExplorerSectionCreatorResponse
 | 
						|
    
 | 
						|
    let onClickFollow: (Int, Bool) -> Void
 | 
						|
    
 | 
						|
    let crowns = ["rank_1", "rank_2", "rank_3"]
 | 
						|
    
 | 
						|
    @AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        ZStack(alignment: .topLeading) {
 | 
						|
            VStack(spacing: 0) {
 | 
						|
                KFImage(URL(string: item.profileImageUrl))
 | 
						|
                    .cancelOnDisappear(true)
 | 
						|
                    .resizable()
 | 
						|
                    .frame(width: 84, height: 84)
 | 
						|
                    .clipShape(Circle())
 | 
						|
                               
 | 
						|
                Text(item.nickname)
 | 
						|
                    .font(.custom(Font.preRegular.rawValue, size: 16))
 | 
						|
                    .foregroundColor(.white)
 | 
						|
                    .padding(.top, 20)
 | 
						|
                
 | 
						|
                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 {
 | 
						|
                            if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
 | 
						|
                                item.follow = !item.follow
 | 
						|
                            }
 | 
						|
                            
 | 
						|
                            onClickFollow(item.id, item.follow)
 | 
						|
                        }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .padding(16)
 | 
						|
            .frame(width: 144, height: 204)
 | 
						|
            .background(Color(hex: "263238"))
 | 
						|
            .cornerRadius(16)
 | 
						|
            .padding(.top, 20)
 | 
						|
            
 | 
						|
            if rank <= 3 {
 | 
						|
                Image(crowns[rank - 1])
 | 
						|
                    .resizable()
 | 
						|
                    .frame(width: 40, height: 40)
 | 
						|
                    .padding(.leading, 10)
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#Preview {
 | 
						|
    HomeCreatorRankingItemView(
 | 
						|
        rank: 1,
 | 
						|
        item: 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 }
 | 
						|
    )
 | 
						|
}
 |