108 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  AuditionApplicantItemView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 1/7/25.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
import Kingfisher
 | 
						|
 | 
						|
struct AuditionApplicantItemView: View {
 | 
						|
    
 | 
						|
    let item: GetAuditionRoleApplicantItem
 | 
						|
    let onClickVote: (Int) -> Void
 | 
						|
    
 | 
						|
    @StateObject var soundManager = AuditionSoundManager.shared
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        VStack(spacing: 5.3) {
 | 
						|
            HStack(spacing: 13.3) {
 | 
						|
                ZStack {
 | 
						|
                    KFImage(URL(string: item.profileImageUrl))
 | 
						|
                        .cancelOnDisappear(true)
 | 
						|
                        .downsampling(size: CGSize(width: 40, height: 40))
 | 
						|
                        .resizable()
 | 
						|
                        .aspectRatio(1, contentMode: .fit)
 | 
						|
                        .scaledToFill()
 | 
						|
                        .frame(width: 40, height: 40)
 | 
						|
                        .clipShape(Circle())
 | 
						|
                    
 | 
						|
                    Image(soundManager.applicantId == item.applicantId && soundManager.isPlaying ? "ic_audition_pause" : "ic_audition_play")
 | 
						|
                        .onTapGesture {
 | 
						|
                            soundManager.playOrPause(
 | 
						|
                                applicantId: item.applicantId,
 | 
						|
                                url: item.voiceUrl
 | 
						|
                            )
 | 
						|
                        }
 | 
						|
                }
 | 
						|
                .onTapGesture {
 | 
						|
                    AppState.shared.setAppStep(step: .creatorDetail(userId: item.memberId))
 | 
						|
                }
 | 
						|
                
 | 
						|
                VStack(spacing: 8) {
 | 
						|
                    HStack(spacing: 0) {
 | 
						|
                        Text(item.nickname.count > 9 ? "\(item.nickname.prefix(9))..." : item.nickname)
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 12))
 | 
						|
                            .foregroundColor(Color.white)
 | 
						|
                            .onTapGesture {
 | 
						|
                                AppState.shared.setAppStep(step: .creatorDetail(userId: item.memberId))
 | 
						|
                            }
 | 
						|
                        
 | 
						|
                        Spacer()
 | 
						|
                        
 | 
						|
                        if soundManager.applicantId == item.applicantId {
 | 
						|
                            Text("\(secondsToMinutesSeconds(Int(soundManager.currentTime)))/\(secondsToMinutesSeconds(Int(soundManager.duration)))")
 | 
						|
                                .font(.custom(Font.medium.rawValue, size: 12))
 | 
						|
                                .foregroundColor(Color.gray77)
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    
 | 
						|
                    if soundManager.applicantId == item.applicantId {
 | 
						|
                        ProgressView(value: soundManager.currentTime, total: soundManager.duration)
 | 
						|
                            .progressViewStyle(LinearProgressViewStyle(tint: Color.button))
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                
 | 
						|
                VStack(spacing: 2.3) {
 | 
						|
                    Image("ic_heart_vote")
 | 
						|
                    
 | 
						|
                    Text("\(item.voteCount)")
 | 
						|
                        .font(.custom(Font.medium.rawValue, size: 12))
 | 
						|
                        .foregroundColor(Color.gray77)
 | 
						|
                }
 | 
						|
                .onTapGesture {
 | 
						|
                    onClickVote(item.applicantId)
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .padding(.vertical, 18.7)
 | 
						|
            
 | 
						|
            Color.gray55
 | 
						|
                .frame(maxWidth: .infinity)
 | 
						|
                .frame(height: 1)
 | 
						|
        }
 | 
						|
        .padding(.horizontal, 13.3)
 | 
						|
    }
 | 
						|
    
 | 
						|
    private func secondsToMinutesSeconds(_ seconds: Int) -> String {
 | 
						|
        let minute = String(format: "%02d", seconds / 60)
 | 
						|
        let second = String(format: "%02d", seconds % 60)
 | 
						|
        
 | 
						|
        return "\(minute):\(second)"
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#Preview {
 | 
						|
    AuditionApplicantItemView(
 | 
						|
        item: GetAuditionRoleApplicantItem(
 | 
						|
            applicantId: 1,
 | 
						|
            memberId: 2,
 | 
						|
            nickname: "유저일유저일유저일유저일",
 | 
						|
            profileImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
 | 
						|
            voiceUrl: "",
 | 
						|
            voteCount: 777
 | 
						|
        ),
 | 
						|
        onClickVote: { _ in }
 | 
						|
    )
 | 
						|
}
 |