커뮤니티 게시글 등록

- 유료 게시글 등록을 위해 가격 설정 추가
This commit is contained in:
Yu Sung 2024-05-24 15:11:40 +09:00
parent 2268b0c1bc
commit 0a96509b35
3 changed files with 129 additions and 41 deletions

View File

@ -9,6 +9,7 @@ import Foundation
struct CreateCommunityPostRequest: Encodable {
let content: String
let price: Int
let isAdult: Bool
let isCommentAvailable: Bool
}

View File

@ -27,7 +27,7 @@ struct CreatorCommunityWriteView: View {
VStack(spacing: 0) {
Text("이미지")
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color(hex: "eeeeee"))
.foregroundColor(Color.grayee)
.frame(maxWidth: .infinity, alignment: .leading)
ZStack {
@ -45,14 +45,14 @@ struct CreatorCommunityWriteView: View {
.scaledToFit()
.padding(13.3)
.frame(width: 107, height: 107)
.background(Color(hex: "13181B"))
.background(Color.bg)
.cornerRadius(8)
.clipped()
}
Image("ic_camera")
.padding(10)
.background(Color(hex: "3BB9F1"))
.background(Color.button)
.cornerRadius(30)
.offset(x: 50, y: 36)
}
@ -63,28 +63,28 @@ struct CreatorCommunityWriteView: View {
HStack(alignment: .top, spacing: 0) {
Text("")
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "777777"))
.foregroundColor(Color.gray77)
Text("등록할 이미지가 없으면 이미지 없이 게시글만 등록 하셔도 됩니다.")
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "777777"))
.foregroundColor(Color.gray77)
}
.frame(maxWidth: .infinity, alignment: .leading)
.frame(maxWidth: .infinity)
.padding(.top, 24)
HStack(spacing: 0) {
Text("내용")
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color(hex: "eeeeee"))
.foregroundColor(Color.grayee)
Spacer()
Text("\(viewModel.content.count)")
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "ff5c49")) +
.foregroundColor(Color.mainRed) +
Text(" / 최대 500자")
.font(.custom(Font.medium.rawValue, size: 13.3))
.foregroundColor(Color(hex: "777777"))
.foregroundColor(Color.gray77)
}
.padding(.top, 26.7)
@ -101,7 +101,7 @@ struct CreatorCommunityWriteView: View {
VStack(spacing: 13.3) {
Text("댓글 가능 여부")
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color(hex: "eeeeee"))
.foregroundColor(Color.grayee)
.frame(maxWidth: .infinity, alignment: .leading)
HStack(spacing: 13.3) {
@ -126,33 +126,92 @@ struct CreatorCommunityWriteView: View {
}
.padding(.top, 26.7)
VStack(spacing: 13.3) {
Text("연령 제한")
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color(hex: "eeeeee"))
.frame(maxWidth: .infinity, alignment: .leading)
HStack(spacing: 13.3) {
SelectButtonView(
title: "전체 연령",
isChecked: !viewModel.isAdult
) {
if viewModel.isAdult {
viewModel.isAdult = false
}
}
if UserDefaults.bool(forKey: .auth) {
VStack(spacing: 13.3) {
Text("연령 제한")
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color.grayee)
.frame(maxWidth: .infinity, alignment: .leading)
SelectButtonView(
title: "19세 이상",
isChecked: viewModel.isAdult
) {
if !viewModel.isAdult {
viewModel.isAdult = true
HStack(spacing: 13.3) {
SelectButtonView(
title: "전체 연령",
isChecked: !viewModel.isAdult
) {
if viewModel.isAdult {
viewModel.isAdult = false
}
}
SelectButtonView(
title: "19세 이상",
isChecked: viewModel.isAdult
) {
if !viewModel.isAdult {
viewModel.isAdult = true
}
}
}
}
.padding(.top, 26.7)
}
if let _ = viewModel.postImage {
VStack(spacing: 13.3) {
Text("가격 설정")
.font(.custom(Font.bold.rawValue, size: 16.7))
.foregroundColor(Color.grayee)
.frame(maxWidth: .infinity, alignment: .leading)
HStack(spacing: 13.3) {
SelectButtonView(
title: "무료",
isChecked: viewModel.isPriceFree
) {
if !viewModel.isPriceFree {
viewModel.isPriceFree = true
}
}
SelectButtonView(
title: "유료",
isChecked: !viewModel.isPriceFree
) {
if viewModel.isPriceFree {
viewModel.isPriceFree = false
}
}
}
if !viewModel.isPriceFree {
HStack(spacing: 0) {
TextField("", text: $viewModel.priceString)
.autocapitalization(.none)
.disableAutocorrection(true)
.multilineTextAlignment(.center)
.font(.custom(Font.bold.rawValue, size: 13.3))
.foregroundColor(Color.button)
.accentColor(Color.button)
.keyboardType(.numberPad)
Spacer()
Text("")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.button)
}
.padding(.horizontal, 13.3)
.padding(.vertical, 16.7)
.frame(maxWidth: .infinity)
.overlay(
RoundedRectangle(cornerRadius: 6.7)
.stroke(Color.gray77, lineWidth: 1)
)
.background(Color.gray23)
}
}
.padding(.top, 26.7)
}
.padding(.top, 26.7)
}
.padding(13.3)
@ -160,14 +219,14 @@ struct CreatorCommunityWriteView: View {
HStack(spacing: 13.3) {
Text("닫기")
.font(.custom(Font.bold.rawValue, size: 18.3))
.foregroundColor(Color(hex: "3BB9F1"))
.foregroundColor(Color.button)
.frame(maxWidth: .infinity)
.frame(height: 50)
.background(Color(hex: "13181B"))
.background(Color.bg)
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color(hex: "3BB9F1"), lineWidth: 1)
.stroke(Color.button, lineWidth: 1)
)
.onTapGesture {
hideKeyboard()
@ -179,7 +238,7 @@ struct CreatorCommunityWriteView: View {
.foregroundColor(Color.white)
.frame(maxWidth: .infinity)
.frame(height: 50)
.background(Color(hex: "3BB9F1"))
.background(Color.button)
.cornerRadius(10)
.onTapGesture {
hideKeyboard()
@ -194,17 +253,17 @@ struct CreatorCommunityWriteView: View {
}
.padding(13.3)
.frame(maxWidth: .infinity)
.background(Color(hex: "222222"))
.background(Color.gray22)
.cornerRadius(16.7, corners: [.topLeft, .topRight])
Rectangle()
.foregroundColor(Color(hex: "222222"))
.foregroundColor(Color.gray22)
.frame(height: keyboardHandler.keyboardHeight)
.frame(maxWidth: .infinity)
if proxy.safeAreaInsets.bottom > 0 {
Rectangle()
.foregroundColor(Color(hex: "222222"))
.foregroundColor(Color.gray22)
.frame(height: 15.3)
.frame(maxWidth: .infinity)
}
@ -232,7 +291,7 @@ struct CreatorCommunityWriteView: View {
.padding(.vertical, 13.3)
.frame(width: screenSize().width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color(hex: "9970ff"))
.background(Color.button)
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.cornerRadius(20)

View File

@ -20,16 +20,38 @@ final class CreatorCommunityWriteViewModel: ObservableObject {
@Published var content = ""
@Published var isAdult = false
@Published var isPriceFree = true {
didSet {
if isPriceFree {
priceString = "0"
}
}
}
@Published var isAvailableComment = true
@Published var postImage: UIImage? = nil
@Published var priceString = "0" {
didSet {
if priceString.count > 5 {
priceString = String(priceString.prefix(5))
} else {
if let price = Int(priceString) {
self.price = price
} else {
self.price = 0
}
}
}
}
@Published var price = 0
var placeholder = "내용을 입력하세요"
func createCommunityPost(onSuccess: @escaping () -> Void) {
if !isLoading && validateData() {
isLoading = true
let request = CreateCommunityPostRequest(content: content, isAdult: isAdult, isCommentAvailable: isAvailableComment)
let request = CreateCommunityPostRequest(content: content, price: price, isAdult: isAdult, isCommentAvailable: isAvailableComment)
var multipartData = [MultipartFormData]()
let encoder = JSONEncoder()
@ -103,6 +125,12 @@ final class CreatorCommunityWriteViewModel: ObservableObject {
return false
}
if !isPriceFree && price < 5 {
errorMessage = "최소금액은 5캔 입니다."
isShowPopup = true
return false
}
return true
}
}