룰렛 프리뷰 다이얼로그 추가
This commit is contained in:
@@ -121,6 +121,7 @@ struct RouletteSettingsView: View {
|
||||
.foregroundColor(Color(hex: "3bb9f1"))
|
||||
)
|
||||
.onTapGesture {
|
||||
viewModel.onClickPreview()
|
||||
}
|
||||
|
||||
Text("설정완료")
|
||||
@@ -143,6 +144,32 @@ struct RouletteSettingsView: View {
|
||||
.frame(width: screenSize().width, height: 15.3)
|
||||
}
|
||||
}
|
||||
|
||||
if let preview = viewModel.previewData, viewModel.isShowPreview {
|
||||
RoulettePreviewDialog(
|
||||
isShowing: $viewModel.isShowPreview,
|
||||
title: "룰렛 미리보기",
|
||||
onClickSpin: nil,
|
||||
preview: preview
|
||||
)
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowErrorPopup, type: .toast, position: .top, autohideIn: 1.3) {
|
||||
GeometryReader { geo in
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.frame(width: geo.size.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getRoulette(creatorId: UserDefaults.int(forKey: .userId))
|
||||
|
@@ -25,6 +25,15 @@ final class RouletteSettingsViewModel: ObservableObject {
|
||||
@Published var isActive = false
|
||||
@Published var options = [RouletteOption]()
|
||||
|
||||
@Published var isShowPreview = false {
|
||||
didSet {
|
||||
if !isShowPreview {
|
||||
previewData = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@Published var previewData: RoulettePreview? = nil
|
||||
|
||||
var can = 5
|
||||
|
||||
func plusWeight(index: Int) {
|
||||
@@ -118,4 +127,24 @@ final class RouletteSettingsViewModel: ObservableObject {
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func onClickPreview() {
|
||||
isLoading = true
|
||||
|
||||
var items = [RoulettePreviewItem]()
|
||||
for option in options {
|
||||
if option.title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
isLoading = false
|
||||
errorMessage = "옵션은 빈칸일 수 없습니다."
|
||||
isShowErrorPopup = true
|
||||
return
|
||||
}
|
||||
|
||||
items.append(RoulettePreviewItem(title: option.title, percent: "\(option.percentage)%"))
|
||||
}
|
||||
|
||||
previewData = RoulettePreview(can: self.can, items: items)
|
||||
isLoading = false
|
||||
isShowPreview = true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user