캔 내역, 캔 충전 페이지 추가
This commit is contained in:
67
SodaLive/Sources/MyPage/Can/Status/CanChargeStatusView.swift
Normal file
67
SodaLive/Sources/MyPage/Can/Status/CanChargeStatusView.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// CanChargeStatusView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CanChargeStatusView: View {
|
||||
|
||||
@StateObject var viewModel = CanStatusViewModel()
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
VStack(spacing: 13.3) {
|
||||
ForEach(viewModel.chargeStatusItems, id: \.self) { item in
|
||||
CanChargeStatusItemView(item: item)
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
LoadingView()
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getCanChargeStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CanChargeStatusItemView: View {
|
||||
|
||||
let item: GetCanChargeStatusResponseItem
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
VStack(alignment: .leading, spacing: 6.7) {
|
||||
Text(item.canTitle)
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(item.date)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Text(item.chargeMethod)
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
.padding(.vertical, 16)
|
||||
.background(Color(hex: "111111"))
|
||||
.cornerRadius(16.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
.frame(width: screenSize().width)
|
||||
}
|
||||
}
|
||||
|
||||
struct CanChargeStatusView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CanChargeStatusView()
|
||||
}
|
||||
}
|
199
SodaLive/Sources/MyPage/Can/Status/CanStatusView.swift
Normal file
199
SodaLive/Sources/MyPage/Can/Status/CanStatusView.swift
Normal file
@@ -0,0 +1,199 @@
|
||||
//
|
||||
// CanStatusView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CanStatusView: View {
|
||||
|
||||
@StateObject var viewModel = CanStatusViewModel()
|
||||
|
||||
let refresh: () -> Void
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
GeometryReader { proxy in
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "캔내역") {
|
||||
AppState.shared.setAppStep(step: .main)
|
||||
}
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
VStack(spacing: 26.7) {
|
||||
HStack(spacing: 6.7) {
|
||||
Image("ic_can")
|
||||
.resizable()
|
||||
.frame(width: 26.7, height: 26.7)
|
||||
|
||||
Text("\(viewModel.totalCan) 캔")
|
||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
}
|
||||
|
||||
HStack(spacing: 26.7) {
|
||||
VStack(spacing: 10) {
|
||||
Text("결제 캔")
|
||||
.font(.custom(Font.light.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
|
||||
HStack(alignment: .bottom, spacing: 3.3) {
|
||||
Text("\(viewModel.chargeCan)")
|
||||
.font(.custom(Font.bold.rawValue, size: 16.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(" 캔")
|
||||
.font(.custom(Font.medium.rawValue, size: 10.7))
|
||||
.foregroundColor(Color(hex: "bbbbbb"))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 6.7)
|
||||
|
||||
Rectangle()
|
||||
.frame(width: 1, height: 26.7)
|
||||
.foregroundColor(Color(hex: "909090").opacity(0.5))
|
||||
|
||||
VStack(spacing: 10) {
|
||||
Text("리워드 캔")
|
||||
.font(.custom(Font.light.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
|
||||
HStack(alignment: .bottom, spacing: 3.3) {
|
||||
Text("\(viewModel.rewardCan)")
|
||||
.font(.custom(Font.bold.rawValue, size: 16.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(" 캔")
|
||||
.font(.custom(Font.medium.rawValue, size: 10.7))
|
||||
.foregroundColor(Color(hex: "bbbbbb"))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 6.7)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 13.3)
|
||||
.frame(width: screenSize().width - 26.7)
|
||||
.background(Color(hex: "222222"))
|
||||
.cornerRadius(16.7)
|
||||
.padding(.top, 13.3)
|
||||
|
||||
HStack(spacing: 0) {
|
||||
VStack(spacing: 0) {
|
||||
Spacer()
|
||||
Text("충전내역")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(
|
||||
Color(hex: viewModel.currentTab == .charge ? "eeeeee" : "777777")
|
||||
)
|
||||
Spacer()
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(
|
||||
Color(hex: "fdca2f")
|
||||
.opacity(viewModel.currentTab == .charge ? 1 : 0)
|
||||
)
|
||||
}
|
||||
.frame(width: screenSize().width / 2, height: 50)
|
||||
.onTapGesture {
|
||||
if viewModel.currentTab != .charge {
|
||||
viewModel.currentTab = .charge
|
||||
}
|
||||
}
|
||||
|
||||
VStack(spacing: 0) {
|
||||
Spacer()
|
||||
Text("사용내역")
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(
|
||||
Color(hex: viewModel.currentTab == .use ? "eeeeee" : "777777")
|
||||
)
|
||||
Spacer()
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(
|
||||
Color(hex: "fdca2f")
|
||||
.opacity(viewModel.currentTab == .use ? 1 : 0)
|
||||
)
|
||||
}
|
||||
.frame(width: screenSize().width / 2, height: 50)
|
||||
.onTapGesture {
|
||||
if viewModel.currentTab != .use {
|
||||
viewModel.currentTab = .use
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.top, 13.3)
|
||||
|
||||
switch viewModel.currentTab {
|
||||
case .charge:
|
||||
CanChargeStatusView()
|
||||
|
||||
case .use:
|
||||
CanUseStatusView()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 6.7) {
|
||||
Image("ic_can")
|
||||
.resizable()
|
||||
.frame(width: 26.7, height: 26.7)
|
||||
|
||||
Text("충전하기")
|
||||
.font(.custom(Font.bold.rawValue, size: 18.3))
|
||||
.foregroundColor(Color.black)
|
||||
}
|
||||
.padding(.vertical, 16)
|
||||
.frame(width: screenSize().width - 26.7)
|
||||
.background(Color(hex: "fdca2f"))
|
||||
.cornerRadius(10)
|
||||
.padding(.vertical, 13.7)
|
||||
.frame(width: screenSize().width)
|
||||
.background(Color(hex: "222222"))
|
||||
.cornerRadius(16.7, corners: [.topLeft, .topRight])
|
||||
.onTapGesture {
|
||||
AppState.shared.setAppStep(step: .canCharge(refresh: refresh))
|
||||
}
|
||||
|
||||
if proxy.safeAreaInsets.bottom > 0 {
|
||||
Rectangle()
|
||||
.foregroundColor(Color(hex: "222222"))
|
||||
.frame(width: proxy.size.width, height: 15.3)
|
||||
}
|
||||
}
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
}
|
||||
}
|
||||
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
|
||||
GeometryReader { geo in
|
||||
HStack {
|
||||
Spacer()
|
||||
Text(viewModel.errorMessage)
|
||||
.padding(.vertical, 13.3)
|
||||
.padding(.horizontal, 6.7)
|
||||
.frame(width: geo.size.width - 66.7, alignment: .center)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.background(Color(hex: "9970ff"))
|
||||
.foregroundColor(Color.white)
|
||||
.multilineTextAlignment(.leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
.cornerRadius(20)
|
||||
.padding(.top, 66.7)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getCanStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CanStatusView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CanStatusView {}
|
||||
}
|
||||
}
|
147
SodaLive/Sources/MyPage/Can/Status/CanStatusViewModel.swift
Normal file
147
SodaLive/Sources/MyPage/Can/Status/CanStatusViewModel.swift
Normal file
@@ -0,0 +1,147 @@
|
||||
//
|
||||
// CanStatusViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/10.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class CanStatusViewModel: ObservableObject {
|
||||
private let repository = CanRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var currentTab: CurrentTab = .charge
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var totalCan: Int = 0
|
||||
@Published var rewardCan: Int = 0
|
||||
@Published var chargeCan: Int = 0
|
||||
|
||||
@Published var useStatusItems: [GetCanUseStatusResponseItem] = []
|
||||
@Published var chargeStatusItems: [GetCanChargeStatusResponseItem] = []
|
||||
|
||||
func getCanStatus() {
|
||||
isLoading = true
|
||||
|
||||
repository.getCanStatus()
|
||||
.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(ApiResponse<GetCanStatusResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.chargeCan = data.chargeCan
|
||||
self.rewardCan = data.rewardCan
|
||||
self.totalCan = data.chargeCan + data.rewardCan
|
||||
} 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)
|
||||
}
|
||||
|
||||
func getCanChargeStatus() {
|
||||
isLoading = true
|
||||
|
||||
repository.getCanChargeStatus()
|
||||
.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(ApiResponse<[GetCanChargeStatusResponseItem]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.chargeStatusItems.append(contentsOf: data)
|
||||
} 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)
|
||||
}
|
||||
|
||||
func getCanUseStatus() {
|
||||
isLoading = true
|
||||
|
||||
repository.getCanUseStatus()
|
||||
.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(ApiResponse<[GetCanUseStatusResponseItem]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.useStatusItems.append(contentsOf: data)
|
||||
} 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)
|
||||
}
|
||||
|
||||
enum CurrentTab: String {
|
||||
case charge, use
|
||||
}
|
||||
}
|
72
SodaLive/Sources/MyPage/Can/Status/CanUseStatusView.swift
Normal file
72
SodaLive/Sources/MyPage/Can/Status/CanUseStatusView.swift
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// CanUseStatusView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CanUseStatusView: View {
|
||||
|
||||
@StateObject var viewModel = CanStatusViewModel()
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
VStack(spacing: 13.3) {
|
||||
ForEach(viewModel.useStatusItems, id: \.self) { item in
|
||||
CanUseStatusItemView(item: item)
|
||||
}
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
LoadingView()
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.getCanUseStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CanUseStatusItemView: View {
|
||||
|
||||
let item: GetCanUseStatusResponseItem
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
VStack(alignment: .leading, spacing: 6.7) {
|
||||
Text(item.title)
|
||||
.font(.custom(Font.medium.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Text(item.date)
|
||||
.font(.custom(Font.medium.rawValue, size: 12))
|
||||
.foregroundColor(Color(hex: "777777"))
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("\(item.can)")
|
||||
.font(.custom(Font.bold.rawValue, size: 13.3))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Image("ic_can")
|
||||
.resizable()
|
||||
.frame(width: 26.7, height: 26.7)
|
||||
.padding(.leading, 6.7)
|
||||
}
|
||||
.padding(.horizontal, 13.3)
|
||||
.padding(.vertical, 16)
|
||||
.background(Color(hex: "111111"))
|
||||
.cornerRadius(16.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
.frame(width: screenSize().width)
|
||||
}
|
||||
}
|
||||
|
||||
struct CanUseStatusView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CanUseStatusView()
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// GetCanChargeStatusResponseItem.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetCanChargeStatusResponseItem: Decodable, Hashable {
|
||||
let canTitle: String
|
||||
let date: String
|
||||
let chargeMethod: String
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// GetCanStatusResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetCanStatusResponse: Decodable {
|
||||
let chargeCan: Int
|
||||
let rewardCan: Int
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// GetCanUseStatusResponseItem.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetCanUseStatusResponseItem: Decodable, Hashable {
|
||||
let title: String
|
||||
let date: String
|
||||
let can: Int
|
||||
}
|
Reference in New Issue
Block a user