콘텐츠 추가

This commit is contained in:
Yu Sung
2023-08-13 20:59:49 +09:00
parent a8338e6fea
commit cf0607334a
63 changed files with 3935 additions and 10 deletions

View File

@@ -0,0 +1,89 @@
//
// AudioContentCommentItemView.swift
// SodaLive
//
// Created by klaus on 2023/08/13.
//
import SwiftUI
import Kingfisher
struct AudioContentCommentItemView: View {
let comment: GetAudioContentCommentListItem
let isReplyComment: Bool
var body: some View {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 6.7) {
KFImage(URL(string: comment.profileUrl))
.resizable()
.frame(width: 40, height: 40)
.clipShape(Circle())
VStack(alignment: .leading, spacing: 0) {
Text(comment.nickname)
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "eeeeee"))
Text(comment.date)
.font(.custom(Font.medium.rawValue, size: 10.3))
.foregroundColor(Color(hex: "525252"))
.padding(.top, 4)
}
Spacer()
}
if comment.donationCan > 0 {
HStack(spacing: 3) {
Image("ic_can")
.resizable()
.frame(width: 13.3, height: 13.3)
Text("\(comment.donationCan)")
.font(.custom(Font.bold.rawValue, size: 12))
.foregroundColor(.white)
}
.padding(.horizontal, 6.7)
.padding(.vertical, 2.7)
.background(
comment.donationCan >= 100000 ? Color(hex: "973a3a") :
comment.donationCan >= 50000 ? Color(hex: "d85e37") :
comment.donationCan >= 10000 ? Color(hex: "d38c38") :
comment.donationCan >= 5000 ? Color(hex: "59548f") :
comment.donationCan >= 1000 ? Color(hex: "4d6aa4") :
comment.donationCan >= 500 ? Color(hex: "2d7390") :
Color(hex: "548f7d")
)
.cornerRadius(10.7)
.padding(.leading, 46.7)
.padding(.bottom, 5)
}
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 13.3) {
Text(comment.comment)
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "777777"))
.fixedSize(horizontal: false, vertical: true)
.padding(.top, comment.donationCan > 0 ? 0 : 13.3)
if !isReplyComment {
Text(comment.replyCount > 0 ? "답글 \(comment.replyCount)" : "답글 쓰기")
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "9970ff"))
}
}
Spacer()
}
.padding(.leading, 46.7)
Rectangle()
.foregroundColor(Color(hex: "595959"))
.frame(height: 0.5)
.padding(.top, 16.7)
}
}
}

View File

@@ -0,0 +1,146 @@
//
// AudioContentCommentListView.swift
// SodaLive
//
// Created by klaus on 2023/08/13.
//
import SwiftUI
import Kingfisher
struct AudioContentCommentListView: View {
@Binding var isPresented: Bool
let audioContentId: Int
@StateObject var viewModel = AudioContentCommentListViewModel()
var body: some View {
NavigationView {
ZStack {
VStack(spacing: 0) {
HStack(spacing: 0) {
Text("댓글")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(.white)
.padding(.leading, 13.3)
Text("\(viewModel.totalCommentCount)")
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "909090"))
.padding(.leading, 6.7)
Spacer()
Image("ic_close_white")
.onTapGesture { isPresented = false}
}
.padding(.horizontal, 13.3)
.padding(.top, 12)
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: "9970ff"))
.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: "9970ff"))
)
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)
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(spacing: 13.3) {
ForEach(0..<viewModel.commentList.count, id: \.self) { index in
let comment = viewModel.commentList[index]
NavigationLink {
AudioContentListReplyView(
audioContentId: audioContentId,
parentComment: comment
)
} label: {
AudioContentCommentItemView(comment: comment, isReplyComment: false)
.padding(.horizontal, 26.7)
.onAppear {
if index == viewModel.commentList.count - 1 {
viewModel.getCommentList()
}
}
}
}
}
}
}
if viewModel.isLoading {
LoadingView()
}
}
.onAppear {
viewModel.audioContentId = audioContentId
viewModel.getCommentList()
}
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
GeometryReader { geo in
HStack {
Spacer()
Text(viewModel.errorMessage)
.padding(.vertical, 13.3)
.frame(width: screenSize().width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color(hex: "9970ff"))
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.cornerRadius(20)
.padding(.top, 66.7)
Spacer()
}
}
}
}
}
}

View File

@@ -0,0 +1,124 @@
//
// AudioContentCommentListViewModel.swift
// SodaLive
//
// Created by klaus on 2023/08/13.
//
import Foundation
import Moya
import Combine
class AudioContentCommentListViewModel: ObservableObject {
private let repository = ContentRepository()
private var subscription = Set<AnyCancellable>()
@Published var isLoading = false
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var comment = ""
@Published var totalCommentCount = 0
@Published var commentList = [GetAudioContentCommentListItem]()
var audioContentId = 0
var page = 1
var isLast = false
private let pageSize = 10
func getCommentList() {
if (!isLast && !isLoading) {
repository
.getAudioContentCommentList(audioContentId: audioContentId, page: page, size: pageSize)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<GetAudioContentCommentListResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
if page == 1 {
commentList.removeAll()
}
if !data.items.isEmpty {
page += 1
self.totalCommentCount = data.totalCount
self.commentList.append(contentsOf: data.items)
} else {
isLast = true
}
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
}
func registerComment() {
if comment.trimmingCharacters(in: .whitespaces).isEmpty {
return
}
isLoading = true
repository.registerComment(audioContentId: audioContentId, comment: comment)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.comment = ""
self.page = 1
self.isLast = false
self.getCommentList()
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
}

View File

@@ -0,0 +1,118 @@
//
// AudioContentListReplyView.swift
// SodaLive
//
// Created by klaus on 2023/08/13.
//
import SwiftUI
import Kingfisher
struct AudioContentListReplyView: View {
let audioContentId: Int
let parentComment: GetAudioContentCommentListItem
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@StateObject var viewModel = AudioContentListReplyViewModel()
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: "9970ff"))
.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: "9970ff"))
)
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(comment: parentComment, isReplyComment: true)
.padding(.horizontal, 26.7)
.padding(.bottom, 13.3)
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(spacing: 13.3) {
ForEach(0..<viewModel.commentList.count, id: \.self) { index in
let comment = viewModel.commentList[index]
AudioContentCommentItemView(comment: comment, isReplyComment: true)
.padding(.horizontal, 40)
.onAppear {
if index == viewModel.commentList.count - 1 {
viewModel.getCommentList()
}
}
}
}
}
}
.navigationTitle("")
.navigationBarBackButtonHidden()
}
.onAppear {
viewModel.audioContentId = audioContentId
viewModel.commentId = parentComment.id
viewModel.getCommentList()
}
}
}

View File

@@ -0,0 +1,124 @@
//
// AudioContentListReplyViewModel.swift
// SodaLive
//
// Created by klaus on 2023/08/13.
//
import Foundation
import Combine
final class AudioContentListReplyViewModel: ObservableObject {
private let repository = ContentRepository()
private var subscription = Set<AnyCancellable>()
@Published var isLoading = false
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var comment = ""
@Published var totalCommentCount = 0
@Published var commentList = [GetAudioContentCommentListItem]()
var audioContentId = 0
var commentId = 0
var page = 1
var isLast = false
private let pageSize = 10
func getCommentList() {
if (!isLast && !isLoading) {
repository
.getAudioContentCommentReplyList(commentId: commentId, page: page, size: pageSize)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<GetAudioContentCommentListResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
if page == 1 {
commentList.removeAll()
}
if !data.items.isEmpty {
page += 1
self.totalCommentCount = data.totalCount
self.commentList.append(contentsOf: data.items)
} else {
isLast = true
}
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
}
func registerComment() {
if comment.trimmingCharacters(in: .whitespaces).isEmpty {
return
}
isLoading = true
repository.registerComment(audioContentId: audioContentId, comment: comment, parentId: commentId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.comment = ""
self.page = 1
self.isLast = false
self.getCommentList()
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
}

View File

@@ -0,0 +1,89 @@
//
// ContentDetailCommentView.swift
// SodaLive
//
// Created by klaus on 2023/08/13.
//
import SwiftUI
import Kingfisher
struct ContentDetailCommentView: View {
let commentCount: Int
let commentList: [GetAudioContentCommentListItem]
let registerComment: (String) -> Void
@State private var comment = ""
var body: some View {
VStack(alignment: .leading, spacing: 10.3) {
HStack(spacing: 5.3) {
Text("댓글")
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(.white)
Text("\(commentCount)")
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "909090"))
Spacer()
}
HStack(spacing: 8) {
KFImage(
URL(
string: commentCount > 0 ?
commentList[0].profileUrl :
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())
if commentCount > 0 {
Text(commentList[0].comment)
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "bbbbbb"))
.lineLimit(1)
.padding(.leading, 3)
} else {
HStack(spacing: 0) {
TextField("댓글을 입력해 보세요.", text: $comment)
.autocapitalization(.none)
.disableAutocorrection(true)
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "eeeeee"))
.accentColor(Color(hex: "9970ff"))
.keyboardType(.default)
.padding(.horizontal, 13.3)
Spacer()
Image("btn_message_send")
.resizable()
.frame(width: 35, height: 35)
.padding(6.7)
.onTapGesture {
hideKeyboard()
registerComment(comment)
}
}
.background(Color(hex: "232323"))
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 10)
.strokeBorder(lineWidth: 1)
.foregroundColor(Color(hex: "9970ff"))
)
}
Spacer()
}
}
}
}

View File

@@ -18,7 +18,7 @@ struct GetAudioContentCommentListItem: Decodable {
let nickname: String
let profileUrl: String
let comment: String
let donationCoin: Int
let donationCan: Int
let date: String
let replyCount: Int
}

View File

@@ -9,6 +9,6 @@ import Foundation
struct RegisterAudioContentCommentRequest: Encodable {
let comment: String
let audioContentId: Int
let contentId: Int
let parentId: Int?
}