- 댓글 수정 모드 상태에서 다른 댓글 쓰기 혹은 삭제 등의 액션을 해서 댓글 수의 변화가 있을 때 내 글이 아닌 다른 사람의 글이 수정 모드로 보이는 버그 수정
		
			
				
	
	
		
			184 lines
		
	
	
		
			7.3 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			7.3 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  AudioContentListReplyView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 2023/08/13.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
import Kingfisher
 | 
						|
 | 
						|
struct AudioContentListReplyView: View {
 | 
						|
    
 | 
						|
    let creatorId: Int
 | 
						|
    let audioContentId: Int
 | 
						|
    let parentComment: GetAudioContentCommentListItem
 | 
						|
    
 | 
						|
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
 | 
						|
    @StateObject var viewModel = AudioContentListReplyViewModel()
 | 
						|
    
 | 
						|
    @State private var commentId: Int = 0
 | 
						|
    @State private var isShowDeletePopup: Bool = false
 | 
						|
    
 | 
						|
    @State private var memberId: Int = 0
 | 
						|
    @State private var isShowMemberProfilePopup: Bool = false
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        ZStack {
 | 
						|
            VStack(spacing: 0) {
 | 
						|
                HStack(spacing: 6.7) {
 | 
						|
                    Image("ic_back")
 | 
						|
                    
 | 
						|
                    Text("답글")
 | 
						|
                        .font(.custom(Font.medium.rawValue, size: 14.7))
 | 
						|
                        .foregroundColor(.white)
 | 
						|
                    
 | 
						|
                    Spacer()
 | 
						|
                }
 | 
						|
                .padding(.horizontal, 13.3)
 | 
						|
                .padding(.top, 12)
 | 
						|
                .onTapGesture { presentationMode.wrappedValue.dismiss() }
 | 
						|
                
 | 
						|
                Rectangle()
 | 
						|
                    .foregroundColor(Color(hex: "595959"))
 | 
						|
                    .frame(height: 0.5)
 | 
						|
                    .padding(.top, 12)
 | 
						|
                    .padding(.bottom, 13.3)
 | 
						|
                    .padding(.horizontal, 13.3)
 | 
						|
                
 | 
						|
                HStack(spacing: 8) {
 | 
						|
                    KFImage(URL(string: UserDefaults.string(forKey: .profileImage)))
 | 
						|
                        .cancelOnDisappear(true)
 | 
						|
                        .downsampling(size: CGSize(width: 33.3, height: 33.3))
 | 
						|
                        .resizable()
 | 
						|
                        .frame(width: 33.3, height: 33.3)
 | 
						|
                        .clipShape(Circle())
 | 
						|
                    
 | 
						|
                    HStack(spacing: 0) {
 | 
						|
                        TextField("댓글을 입력해 보세요.", text: $viewModel.comment)
 | 
						|
                            .autocapitalization(.none)
 | 
						|
                            .disableAutocorrection(true)
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                            .foregroundColor(Color(hex: "eeeeee"))
 | 
						|
                            .accentColor(Color(hex: "3bb9f1"))
 | 
						|
                            .keyboardType(.default)
 | 
						|
                            .padding(.horizontal, 13.3)
 | 
						|
                        
 | 
						|
                        Spacer()
 | 
						|
                        
 | 
						|
                        Image("btn_message_send")
 | 
						|
                            .resizable()
 | 
						|
                            .frame(width: 35, height: 35)
 | 
						|
                            .padding(6.7)
 | 
						|
                            .onTapGesture {
 | 
						|
                                hideKeyboard()
 | 
						|
                                viewModel.registerComment()
 | 
						|
                            }
 | 
						|
                    }
 | 
						|
                    .background(Color(hex: "232323"))
 | 
						|
                    .cornerRadius(10)
 | 
						|
                    .overlay(
 | 
						|
                        RoundedRectangle(cornerRadius: 10)
 | 
						|
                            .strokeBorder(lineWidth: 1)
 | 
						|
                            .foregroundColor(Color(hex: "3bb9f1"))
 | 
						|
                    )
 | 
						|
                    
 | 
						|
                    Spacer()
 | 
						|
                }
 | 
						|
                .padding(.horizontal, 13.3)
 | 
						|
                
 | 
						|
                Rectangle()
 | 
						|
                    .foregroundColor(Color(hex: "595959"))
 | 
						|
                    .frame(height: 0.5)
 | 
						|
                    .padding(.top, 12)
 | 
						|
                    .padding(.bottom, 13.3)
 | 
						|
                    .padding(.horizontal, 13.3)
 | 
						|
                
 | 
						|
                AudioContentCommentItemView(
 | 
						|
                    contentCreatorId: creatorId,
 | 
						|
                    audioContentId: audioContentId,
 | 
						|
                    commentItem: parentComment,
 | 
						|
                    isReplyComment: true,
 | 
						|
                    isShowPopupMenuButton: false,
 | 
						|
                    modifyComment: { _, _ in },
 | 
						|
                    onClickDelete: { _ in },
 | 
						|
                    onClickProfile: {
 | 
						|
                        memberId = $0
 | 
						|
                        isShowMemberProfilePopup = true
 | 
						|
                    }
 | 
						|
                )
 | 
						|
                    .padding(.horizontal, 26.7)
 | 
						|
                    .padding(.bottom, 13.3)
 | 
						|
                
 | 
						|
                if !viewModel.isRegisterComment {
 | 
						|
                    ScrollView(.vertical, showsIndicators: false) {
 | 
						|
                        LazyVStack(spacing: 13.3) {
 | 
						|
                            ForEach(0..<viewModel.commentList.count, id: \.self) { index in
 | 
						|
                                let comment = viewModel.commentList[index]
 | 
						|
                                AudioContentCommentItemView(
 | 
						|
                                    contentCreatorId: creatorId,
 | 
						|
                                    audioContentId: audioContentId,
 | 
						|
                                    commentItem: comment,
 | 
						|
                                    isReplyComment: true,
 | 
						|
                                    isShowPopupMenuButton: true,
 | 
						|
                                    modifyComment: { commentId, comment in
 | 
						|
                                        hideKeyboard()
 | 
						|
                                        viewModel.modifyComment(commentId: commentId, audioContentId: audioContentId, comment: comment)
 | 
						|
                                    },
 | 
						|
                                    onClickDelete: {
 | 
						|
                                        commentId = $0
 | 
						|
                                        isShowDeletePopup = true
 | 
						|
                                    },
 | 
						|
                                    onClickProfile: {
 | 
						|
                                        memberId = $0
 | 
						|
                                        isShowMemberProfilePopup = true
 | 
						|
                                    }
 | 
						|
                                )
 | 
						|
                                .padding(.horizontal, 40)
 | 
						|
                                .onAppear {
 | 
						|
                                    if index == viewModel.commentList.count - 1 {
 | 
						|
                                        viewModel.getCommentList()
 | 
						|
                                    }
 | 
						|
                                }
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .navigationTitle("")
 | 
						|
            .navigationBarBackButtonHidden()
 | 
						|
            
 | 
						|
            if isShowDeletePopup && commentId > 0 {
 | 
						|
                SodaDialog(
 | 
						|
                    title: "댓글 삭제",
 | 
						|
                    desc: "삭제하시겠습니까?",
 | 
						|
                    confirmButtonTitle: "삭제",
 | 
						|
                    confirmButtonAction: {
 | 
						|
                        viewModel.modifyComment(commentId: commentId, audioContentId: audioContentId, isActive: false)
 | 
						|
                        commentId = 0
 | 
						|
                        isShowDeletePopup = false
 | 
						|
                    },
 | 
						|
                    cancelButtonTitle: "취소",
 | 
						|
                    cancelButtonAction: {
 | 
						|
                        commentId = 0
 | 
						|
                        isShowDeletePopup = false
 | 
						|
                    }
 | 
						|
                )
 | 
						|
            }
 | 
						|
            
 | 
						|
            if isShowMemberProfilePopup {
 | 
						|
                MemberProfileDialog(isShowing: $isShowMemberProfilePopup, memberId: memberId)
 | 
						|
            }
 | 
						|
            
 | 
						|
            if viewModel.isLoading {
 | 
						|
                LoadingView()
 | 
						|
            }
 | 
						|
        }
 | 
						|
        .onAppear {
 | 
						|
            viewModel.audioContentId = audioContentId
 | 
						|
            viewModel.commentId = parentComment.id
 | 
						|
            viewModel.getCommentList()
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |