136 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			136 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  SectionLiveReservationView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 2023/08/09.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
 | 
						|
struct SectionLiveReservationView: View {
 | 
						|
    
 | 
						|
    let items: [GetRoomListResponse]
 | 
						|
    
 | 
						|
    let onClickCancel: () -> Void
 | 
						|
    let onClickStart: (Int) -> Void
 | 
						|
    let onClickReservation: (Int) -> Void
 | 
						|
    let onTapCreateLive: () -> Void
 | 
						|
    @AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        VStack(spacing: 13.3) {
 | 
						|
            HStack(spacing: 0) {
 | 
						|
                Text("라이브 ")
 | 
						|
                    .font(.custom(Font.preBold.rawValue, size: 24))
 | 
						|
                    .foregroundColor(.button)
 | 
						|
                
 | 
						|
                Text("예약중")
 | 
						|
                    .font(.custom(Font.preBold.rawValue, size: 24))
 | 
						|
                    .foregroundColor(.white)
 | 
						|
                
 | 
						|
                Spacer()
 | 
						|
                
 | 
						|
                if items.count > 0 {
 | 
						|
                    Text("전체보기")
 | 
						|
                        .font(.custom(Font.preRegular.rawValue, size: 14))
 | 
						|
                        .foregroundColor(Color(hex: "78909C"))
 | 
						|
                        .onTapGesture {
 | 
						|
                            if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
 | 
						|
                                AppState.shared.setAppStep(
 | 
						|
                                    step: .liveReservationAll(
 | 
						|
                                        onClickReservation: onClickReservation,
 | 
						|
                                        onClickStart: onClickStart,
 | 
						|
                                        onClickCancel: onClickCancel,
 | 
						|
                                        onTapCreateLive: onTapCreateLive
 | 
						|
                                    )
 | 
						|
                                )
 | 
						|
                            } else {
 | 
						|
                                AppState.shared.setAppStep(step: .login)
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .padding(.horizontal, 24)
 | 
						|
            .frame(maxWidth: .infinity)
 | 
						|
            
 | 
						|
            if items.count > 0 {
 | 
						|
                VStack(spacing: 14) {
 | 
						|
                    ForEach(0..<items.count, id: \.self) { index in
 | 
						|
                        let item = items[index]
 | 
						|
                        
 | 
						|
                        if item.creatorId == UserDefaults.int(forKey: .userId) {
 | 
						|
                            MyLiveReservationItemView(item: item, index: index)
 | 
						|
                                .contentShape(Rectangle())
 | 
						|
                                .onTapGesture {
 | 
						|
                                    if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
 | 
						|
                                        AppState.shared.setAppStep(
 | 
						|
                                            step: .liveDetail(
 | 
						|
                                                roomId: item.roomId,
 | 
						|
                                                onClickParticipant: {},
 | 
						|
                                                onClickReservation: {},
 | 
						|
                                                onClickStart: { onClickStart(item.roomId) },
 | 
						|
                                                onClickCancel: onClickCancel
 | 
						|
                                            )
 | 
						|
                                        )
 | 
						|
                                    } else {
 | 
						|
                                        AppState.shared.setAppStep(step: .login)
 | 
						|
                                    }
 | 
						|
                                }
 | 
						|
                        } else {
 | 
						|
                            LiveReservationItemView(item: item)
 | 
						|
                                .contentShape(Rectangle())
 | 
						|
                                .onTapGesture {
 | 
						|
                                    if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
 | 
						|
                                        AppState.shared.setAppStep(
 | 
						|
                                            step: .liveDetail(
 | 
						|
                                                roomId: item.roomId,
 | 
						|
                                                onClickParticipant: {},
 | 
						|
                                                onClickReservation: { onClickReservation(item.roomId) },
 | 
						|
                                                onClickStart: { onClickStart(item.roomId) },
 | 
						|
                                                onClickCancel: onClickCancel
 | 
						|
                                            )
 | 
						|
                                        )
 | 
						|
                                    } else {
 | 
						|
                                        AppState.shared.setAppStep(step: .login)
 | 
						|
                                    }
 | 
						|
                                }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                .padding(.horizontal, 24)
 | 
						|
                .frame(maxWidth: .infinity)
 | 
						|
            } else {
 | 
						|
                VStack(spacing: 0) {
 | 
						|
                    Image("ic_no_item")
 | 
						|
                        .resizable()
 | 
						|
                        .frame(width: 60, height: 60)
 | 
						|
                    
 | 
						|
                    Text("지금 예약중인 라이브가 없습니다.\n채널을 팔로잉 하고 라이브 알림을 받아 보세요.")
 | 
						|
                        .font(.custom(Font.medium.rawValue, size: 13))
 | 
						|
                        .foregroundColor(Color(hex: "bbbbbb"))
 | 
						|
                        .fixedSize(horizontal: false, vertical: true)
 | 
						|
                        .multilineTextAlignment(.center)
 | 
						|
                        .lineSpacing(8)
 | 
						|
                        .padding(.vertical, 8)
 | 
						|
                }
 | 
						|
                .padding(.vertical, 16.7)
 | 
						|
                .frame(width: screenSize().width - 26.7)
 | 
						|
                .background(Color(hex: "13181b"))
 | 
						|
                .cornerRadius(4.7)
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
struct SectionLiveReservationView_Previews: PreviewProvider {
 | 
						|
    static var previews: some View {
 | 
						|
        SectionLiveReservationView(
 | 
						|
            items: [],
 | 
						|
            onClickCancel: {},
 | 
						|
            onClickStart: { _ in },
 | 
						|
            onClickReservation: { _ in },
 | 
						|
            onTapCreateLive: {}
 | 
						|
        )
 | 
						|
    }
 | 
						|
}
 |