Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MarketPlace/Model/CouponBasicModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct CouponBasicModel: Codable, Identifiable {
var thumbnail: String
var isAvailable: Bool
var isMemberIssued: Bool
var couponType: String

var id: Int { couponId }
}
Expand Down
2 changes: 1 addition & 1 deletion MarketPlace/Model/CouponModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct CouponNewModel: Codable, Identifiable {
}

struct CouponValidModel: Codable, Identifiable {
let couponId: Int
var couponId: Int
let couponName: String
let couponDescription: String
let deadLine: String?
Expand Down
44 changes: 23 additions & 21 deletions MarketPlace/View/Components/CouponInfoCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ import SwiftUI

struct CouponInfoCell: View {
@ObservedObject var viewModel: CouponInfoCellViewModel
@EnvironmentObject var loginViewModel: LoginViewModel

@Binding var isLoginRequiredPopupVisible: Bool
@Binding var isPopupVisible: Bool
@Binding var coupon: CouponBasicModel

var isMemberIssued: Bool { return viewModel.coupon.isMemberIssued }

init(viewModel: CouponInfoCellViewModel) {
init(
viewModel: CouponInfoCellViewModel,
isLoginRequiredPopupVisible: Binding<Bool>,
isPopupVisible: Binding<Bool>,
coupon: Binding<CouponBasicModel>
) {
self.viewModel = viewModel
self._isLoginRequiredPopupVisible = isLoginRequiredPopupVisible
self._isPopupVisible = isPopupVisible
self._coupon = coupon
}

@State private var showDownloadSuccess = false

var body: some View {
HStack(alignment: .top) {
ShimmeringAsyncImage(
Expand All @@ -26,6 +37,7 @@ struct CouponInfoCell: View {
Text(viewModel.coupon.marketName)
.pretendardFont(size: 14, weight: .semibold)
.foregroundColor(Color(hex: "333333"))
.padding(.bottom, 3)

Text(viewModel.coupon.couponName)
.pretendardFont(size: 18, weight: .bold)
Expand All @@ -42,16 +54,17 @@ struct CouponInfoCell: View {
Text(viewModel.coupon.address)
.pretendardFont(size: 13, weight: .medium)
.foregroundColor(Color(hex: "333333"))

Spacer()

Button(action: {
if !isMemberIssued {
Task {
let result = await viewModel.downloadCoupon(couponId: viewModel.coupon.couponId)
await MainActor.run {
showDownloadSuccess = result
}
}
if !loginViewModel.isLoggedIn {
isLoginRequiredPopupVisible = true
}

else if !isMemberIssued && loginViewModel.isLoggedIn {
coupon = viewModel.coupon
isPopupVisible = true
}
}, label: {
Image(isMemberIssued ? "download_used" : "download")
Expand All @@ -64,18 +77,7 @@ struct CouponInfoCell: View {
}
.padding(.leading, 10)
.padding(5)
.frame(maxHeight: 110)
}
.padding(15)
.alert("쿠폰 다운로드 완료", isPresented: $showDownloadSuccess) {
Button("확인", role: .cancel) { }
} message: {
Text("쿠폰이 성공적으로 발급되었습니다.")
}
.alert(viewModel.errorMessage ?? "오류", isPresented: .constant(viewModel.errorMessage != nil)) {
Button("확인", role: .cancel) {
viewModel.errorMessage = nil
}
}
}
}
30 changes: 18 additions & 12 deletions MarketPlace/View/Components/MarketInfoCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI

struct MarketInfoCell: View {
@ObservedObject var viewModel: MarketInfoCellViewModel
@EnvironmentObject var loginViewModel: LoginViewModel
@State var isBookmarked: Bool

init(isBookmarked: Bool, viewModel: MarketInfoCellViewModel) {
Expand All @@ -19,19 +20,22 @@ struct MarketInfoCell: View {
width: 110,
height: 110
)

.frame(width: 110, height: .infinity)
.clipShape(RoundedRectangle(cornerRadius: 4))

VStack(alignment: .leading) {
Text(viewModel.marketData.marketName)
.lineLimit(1)
.pretendardFont(size: 16, weight: .semibold)
.foregroundColor(Color(hex: "333333"))
.padding(.bottom, 3)

Text(viewModel.marketData.marketDescription)
.multilineTextAlignment(.leading)
.lineLimit(2)
.pretendardFont(size: 13, weight: .medium)
.foregroundColor(Color(hex: "7D7D7D"))
.multilineTextAlignment(.leading)
.padding(.bottom, 10)

Spacer()

Expand All @@ -43,23 +47,25 @@ struct MarketInfoCell: View {
Text(viewModel.marketData.address)
.pretendardFont(size: 13, weight: .medium)
.foregroundColor(Color(hex: "333333"))

Spacer()

Button(action: {
Task {
await viewModel.postFavoriteMarket(marketId: viewModel.marketData.id)
if loginViewModel.isLoggedIn {
Button(action: {
Task {
await viewModel.postFavoriteMarket(marketId: viewModel.marketData.id)
}
}) {
Image(systemName: viewModel.marketData.isFavorite ? "bookmark.fill" : "bookmark")
.resizable()
.frame(width: 14, height: 20)
.foregroundColor(Color(hex: "#4B4B4B"))
}
}) {
Image(systemName: viewModel.marketData.isFavorite ? "bookmark.fill" : "bookmark")
.resizable()
.frame(width: 14, height: 20)
.foregroundColor(Color(hex: "#4B4B4B"))
}
}
}
.padding(.leading, 10)
.padding([.leading, .trailing], 10)
.padding(5)
.frame(maxHeight: 110)
}
.padding(15)
}
Expand Down
13 changes: 7 additions & 6 deletions MarketPlace/View/Main/View/CouponGetPopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import SwiftUI

struct CouponGetPopupView: View {
@Binding var isPopupVisible: Bool
@Binding var coupon: CouponValidModel
@Binding var couponId: Int
@Binding var couponType: String
@Binding var isMemberIssued: Bool

@ObservedObject var viewModel = CouponPopupViewModel()

Expand Down Expand Up @@ -62,22 +64,21 @@ struct CouponGetPopupView: View {
.padding(.vertical, 32)
.background(Color.white)
.cornerRadius(8)
// .shadow(radius: 10)
}
}

private func onConfirm() {
coupon.isMemberIssued = true
isMemberIssued = true
isPopupVisible = false

switch coupon.couponType {
switch couponType {
case "PAYBACK":
Task {
await viewModel.downloadPaybackCoupons(couponId: coupon.couponId)
await viewModel.downloadPaybackCoupons(couponId: couponId)
}
case "GIFT":
Task {
await viewModel.downloadCoupons(couponId: coupon.couponId)
await viewModel.downloadCoupons(couponId: couponId)
}

default:
Expand Down
46 changes: 26 additions & 20 deletions MarketPlace/View/Main/View/MarketDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,29 @@ struct MarketDetailView: View {
.foregroundColor(.black)
.frame(maxWidth: .infinity, alignment: .topLeading)
Spacer()
Button(action: {
isBookmarked.toggle()

Task {
await viewModel.postFavoriteMarket(marketId: viewModel.id)
}
}) {
if let isFavorite = shop.isFavorite {
Image(systemName: isFavorite ? "bookmark.fill" : "bookmark")
.resizable()
.scaledToFit()
.foregroundColor(.black)
.frame(width: 16)
} else {
Image(systemName: "bookmark")
.resizable()
.scaledToFit()
.foregroundColor(.black)
.frame(width: 16)

if loginViewModel.isLoggedIn {
Button(action: {
isBookmarked.toggle()

Task {
await viewModel.postFavoriteMarket(marketId: viewModel.id)
}

}) {
if let isFavorite = shop.isFavorite {
Image(systemName: isFavorite ? "bookmark.fill" : "bookmark")
.resizable()
.scaledToFit()
.foregroundColor(.black)
.frame(width: 16)
} else {
Image(systemName: "bookmark")
.resizable()
.scaledToFit()
.foregroundColor(.black)
.frame(width: 16)
}
}
}
}
Expand Down Expand Up @@ -157,7 +161,9 @@ struct MarketDetailView: View {
) {
CouponGetPopupView(
isPopupVisible: $isPopupVisible,
coupon: couponBinding
couponId: couponBinding.couponId,
couponType: couponBinding.couponType,
isMemberIssued: couponBinding.isMemberIssued
).transition(.scale)
}

Expand Down
Loading