마이페이지 - 구매목록 추가

This commit is contained in:
Yu Sung 2023-08-24 14:30:09 +09:00
parent f0d2bda024
commit 2c8485a1cd
16 changed files with 399 additions and 3 deletions

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_heart_777.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_message_square_777.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

View File

@ -105,4 +105,6 @@ enum AppStep {
case profileUpdate(refresh: () -> Void)
case followingList
case orderListAll
}

View File

@ -148,6 +148,9 @@ struct ContentView: View {
case .followingList:
FollowCreatorView()
case .orderListAll:
OrderListAllView()
default:
EmptyView()
.frame(width: 0, height: 0, alignment: .topLeading)

View File

@ -71,7 +71,11 @@ struct CanCardView_Previews: PreviewProvider {
websiteUrl: "",
blogUrl: "",
liveReservationCount: 0,
isAuth: false
isAuth: false,
orderList: GetAudioContentOrderListResponse(
totalCount: 0,
items: []
)
),
refresh: {}
)

View File

@ -88,7 +88,11 @@ struct MyInfoCardView_Previews: PreviewProvider {
websiteUrl: "",
blogUrl: "",
liveReservationCount: 0,
isAuth: false
isAuth: false,
orderList: GetAudioContentOrderListResponse(
totalCount: 0,
items: []
)
),
refresh: {}
)

View File

@ -18,5 +18,6 @@ struct MyPageResponse: Decodable {
let blogUrl: String?
let liveReservationCount: Int
let isAuth: Bool
let orderList: GetAudioContentOrderListResponse
}

View File

@ -94,6 +94,11 @@ struct MyPageView: View {
ReservationStatusView(data: data)
.padding(.top, 33.3)
if data.orderList.totalCount > 0 {
OrderListView(items: data.orderList.items)
.padding(.top, 40)
}
ServiceCenterButtonView()
.padding(.top, 40)

View File

@ -0,0 +1,25 @@
//
// GetAudioContentOrderListResponse.swift
// SodaLive
//
// Created by klaus on 2023/08/24.
//
import Foundation
struct GetAudioContentOrderListResponse: Decodable {
let totalCount: Int
let items: [GetAudioContentOrderListItem]
}
struct GetAudioContentOrderListItem: Decodable {
let contentId: Int
let coverImageUrl: String
let title: String
let themeStr: String
let duration: String?
let isAdult: Bool
let orderType: OrderType
let likeCount: Int
let commentCount: Int
}

View File

@ -0,0 +1,82 @@
//
// OrderListAllView.swift
// SodaLive
//
// Created by klaus on 2023/08/24.
//
import SwiftUI
struct OrderListAllView: View {
@StateObject var viewModel = OrderListAllViewModel()
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
HStack(spacing: 0) {
Button {
AppState.shared.back()
} label: {
Image("ic_back")
.resizable()
.frame(width: 20, height: 20)
Text("구매목록")
.font(.custom(Font.bold.rawValue, size: 18.3))
.foregroundColor(Color(hex: "eeeeee"))
}
Spacer()
}
.padding(.horizontal, 13.3)
.frame(height: 50)
.background(Color.black)
ScrollViewReader { reader in
ScrollView(.vertical, showsIndicators: false) {
LazyVStack(spacing: 10.7) {
ScrollerToTop(reader: reader, scrollOnChange: $viewModel.scrollToTop)
ForEach(0..<viewModel.orderList.count, id: \.self) { index in
let item = viewModel.orderList[index]
OrderListItemView(item: item)
.contentShape(Rectangle())
.onTapGesture {
AppState
.shared
.setAppStep(step: .contentDetail(contentId: item.contentId))
}
.padding(.horizontal, 13.3)
.onAppear {
if index == viewModel.orderList.count - 1 {
viewModel.getOrderList()
}
}
}
}
}
}
.padding(.top, 13.3)
}
.onAppear {
viewModel.getOrderList()
}
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .bottom, autohideIn: 2) {
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(.leading)
.cornerRadius(20)
.padding(.bottom, 66.7)
Spacer()
}
}
}
}
}

View File

@ -0,0 +1,77 @@
//
// OrderListAllViewModel.swift
// SodaLive
//
// Created by klaus on 2023/08/24.
//
import Foundation
import Combine
final class OrderListAllViewModel: ObservableObject {
private let repository = ContentRepository()
private var subscription = Set<AnyCancellable>()
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
@Published var orderList = [GetAudioContentOrderListItem]()
@Published var scrollToTop = false
var page = 1
var isLast = false
private let pageSize = 10
func getOrderList() {
if (!isLast && !isLoading) {
isLoading = true
repository.getOrderList(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<GetAudioContentOrderListResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
if page == 1 {
self.orderList.removeAll()
self.scrollToTop.toggle()
}
if !data.items.isEmpty {
page += 1
self.orderList.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)
}
}
}

View File

@ -0,0 +1,101 @@
//
// OrderListItemView.swift
// SodaLive
//
// Created by klaus on 2023/08/24.
//
import SwiftUI
import Kingfisher
struct OrderListItemView: View {
let item: GetAudioContentOrderListItem
var body: some View {
VStack(spacing: 12) {
HStack(spacing: 10) {
ZStack(alignment: .topLeading) {
KFImage(URL(string: item.coverImageUrl))
.resizable()
.frame(width: 66.7, height: 66.7, alignment: .center)
.clipped()
.cornerRadius(5.3)
if item.isAdult {
Text("19")
.font(.custom(Font.bold.rawValue, size: 11.3))
.foregroundColor(Color.white)
.padding(4)
.background(Color(hex: "e53621"))
.clipShape(Circle())
.padding(.top, 4.3)
.padding(.leading, 4.3)
}
}
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 8) {
Text(item.themeStr)
.font(.custom(Font.medium.rawValue, size: 8))
.foregroundColor(Color(hex: "3bac6a"))
.padding(2.6)
.background(Color(hex: "28312b"))
.cornerRadius(2.6)
Text(item.duration!)
.font(.custom(Font.medium.rawValue, size: 8))
.foregroundColor(Color(hex: "777777"))
.padding(2.6)
.background(Color(hex: "222222"))
.cornerRadius(2.6)
}
Text(item.title)
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "d2d2d2"))
.fixedSize(horizontal: false, vertical: true)
.padding(.top, 2.6)
.padding(.bottom, 6.7)
HStack(spacing: 13.3) {
HStack(spacing: 6) {
Image("ic_heart_777")
.resizable()
.frame(width: 13.3, height: 13.3)
Text("\(item.likeCount)")
.font(.custom(Font.medium.rawValue, size: 10))
.foregroundColor(Color(hex: "777777"))
}
HStack(spacing: 6) {
Image("ic_message_square_777")
.resizable()
.frame(width: 13.3, height: 13.3)
Text("\(item.commentCount)")
.font(.custom(Font.medium.rawValue, size: 10))
.foregroundColor(Color(hex: "777777"))
}
}
}
Spacer()
Text(item.orderType == .RENTAL ? "대여중" : "소장중")
.font(.custom(Font.medium.rawValue, size: 10.3))
.foregroundColor(item.orderType == .RENTAL ? .white : .black)
.padding(.horizontal, 5.3)
.padding(.vertical, 2.7)
.background(Color(hex: item.orderType == .RENTAL ? "660fd4" : "b1ef2c"))
.cornerRadius(2.6)
}
Rectangle()
.foregroundColor(Color(hex: "595959"))
.frame(maxWidth: .infinity)
.frame(height: 0.5)
}
}
}

View File

@ -0,0 +1,46 @@
//
// OrderListView.swift
// SodaLive
//
// Created by klaus on 2023/08/24.
//
import SwiftUI
struct OrderListView: View {
let items: [GetAudioContentOrderListItem]
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 0) {
Text("구매목록")
.font(.custom(Font.bold.rawValue, size: 18))
.foregroundColor(Color(hex: "eeeeee"))
Spacer()
Text("전체보기")
.font(.custom(Font.medium.rawValue, size: 11))
.foregroundColor(Color(hex: "bbbbbb"))
.onTapGesture {
AppState.shared.setAppStep(step: .orderListAll)
}
}
VStack(spacing: 13.3) {
ForEach(0..<items.count, id: \.self) { index in
let item = items[index]
OrderListItemView(item: item)
.contentShape(Rectangle())
.onTapGesture {
AppState
.shared
.setAppStep(step: .contentDetail(contentId: item.contentId))
}
}
}
.padding(.top, 26.7)
}
.padding(.horizontal, 13.3)
}
}

View File

@ -61,7 +61,11 @@ struct ReservationStatusView_Previews: PreviewProvider {
websiteUrl: "",
blogUrl: "",
liveReservationCount: 0,
isAuth: false
isAuth: false,
orderList: GetAudioContentOrderListResponse(
totalCount: 0,
items: []
)
)
)
}