설정 페이지 추가

This commit is contained in:
Yu Sung
2023-08-10 22:05:14 +09:00
parent d06f4d6a36
commit dbeb15ba17
24 changed files with 1368 additions and 4 deletions

View File

@@ -0,0 +1,69 @@
//
// EventDetailView.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import SwiftUI
import Kingfisher
struct EventDetailView: View {
let event: EventItem
var body: some View {
BaseView {
GeometryReader { proxy in
VStack(spacing: 0) {
DetailNavigationBar(title: "이벤트 상세")
ScrollView(.vertical, showsIndicators: false) {
KFImage(URL(string: event.detailImageUrl!))
.resizable()
.scaledToFit()
}
Spacer()
if let link = event.link, link.count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
Text("이벤트 참여하기")
.font(.custom(Font.bold.rawValue, size: 18.3))
.foregroundColor(.white)
.padding(.vertical, 16)
.frame(width: screenSize().width - 26.7)
.background(Color(hex: "3e737c"))
.cornerRadius(10)
.padding(13.3)
.background(Color(hex: "222222"))
.cornerRadius(16.7, corners: [.topLeft, .topRight])
.onTapGesture {
UIApplication.shared.open(url)
}
}
if proxy.safeAreaInsets.bottom > 0 {
Rectangle()
.foregroundColor(Color(hex: "222222"))
.frame(width: proxy.size.width, height: 15.3)
}
}
.edgesIgnoringSafeArea(.bottom)
}
}
}
}
struct EventDetailView_Previews: PreviewProvider {
static var previews: some View {
EventDetailView(
event: EventItem(
id: 1,
thumbnailImageUrl: "",
detailImageUrl: "",
popupImageUrl: "",
link: "http://m.naver.com"
)
)
}
}

View File

@@ -0,0 +1,73 @@
//
// EventListView.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import SwiftUI
import Kingfisher
struct EventListView: View {
@ObservedObject var viewModel = EventListViewModel()
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: "이벤트")
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
ForEach(viewModel.events, id: \.self) { event in
KFImage(URL(string: event.thumbnailImageUrl))
.resizable()
.scaledToFill()
.frame(
width: screenSize().width - 26.7,
height: (screenSize().width - 26.7) * 300 / 1000
)
.contentShape(Rectangle())
.onTapGesture {
if let _ = event.detailImageUrl {
AppState.shared.setAppStep(step: .eventDetail(event: event))
} else if let link = event.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
}
}
}
.padding(.vertical, 13.3)
}
}
.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.getEvents()
}
}
}
struct EventListView_Previews: PreviewProvider {
static var previews: some View {
EventListView()
}
}

View File

@@ -0,0 +1,60 @@
//
// EventListViewModel.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
import Combine
final class EventListViewModel: ObservableObject {
private let eventRepository = EventRepository()
private var subscription = Set<AnyCancellable>()
@Published private(set) var events = [EventItem]()
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
private var page = 1
private let size = 10
func getEvents() {
isLoading = true
eventRepository.getEvents()
.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<GetEventResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.events.append(contentsOf: data.eventList)
} 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)
}
}