feat(event): ID 기반 이벤트 상세 API를 연동한다
This commit is contained in:
@@ -9,38 +9,50 @@ import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct EventDetailView: View {
|
||||
|
||||
let event: EventItem
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@StateObject private var viewModel: EventDetailViewModel
|
||||
|
||||
init(eventId: Int) {
|
||||
_viewModel = StateObject(wrappedValue: EventDetailViewModel(eventId: eventId))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
BaseView {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
GeometryReader { proxy in
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: I18n.Settings.Event.detailTitle)
|
||||
DetailNavigationBar(title: I18n.Settings.Event.detailTitle, backAction: {
|
||||
viewModel.cancel()
|
||||
dismiss()
|
||||
})
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
KFImage(URL(string: event.detailImageUrl!))
|
||||
.cancelOnDisappear(true)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
if case .loaded(let event) = viewModel.state,
|
||||
let detailImageUrl = event.detailImageUrl {
|
||||
KFImage(URL(string: detailImageUrl))
|
||||
.cancelOnDisappear(true)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
if let link = event.link, link.count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
|
||||
Text(I18n.Settings.Event.participateButton)
|
||||
.appFont(size: 18.3, weight: .bold)
|
||||
.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 let url = viewModel.participationURL, UIApplication.shared.canOpenURL(url) {
|
||||
Button {
|
||||
UIApplication.shared.open(url)
|
||||
} label: {
|
||||
Text(I18n.Settings.Event.participateButton)
|
||||
.appFont(size: 18.3, weight: .bold)
|
||||
.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])
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
if proxy.safeAreaInsets.bottom > 0 {
|
||||
@@ -52,19 +64,23 @@ struct EventDetailView: View {
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
}
|
||||
}
|
||||
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2)
|
||||
.onAppear {
|
||||
viewModel.load()
|
||||
}
|
||||
.onDisappear {
|
||||
viewModel.cancel()
|
||||
}
|
||||
.onReceive(viewModel.$state) { state in
|
||||
if state == .unavailable, viewModel.takeUnavailableDismissal() {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct EventDetailView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EventDetailView(
|
||||
event: EventItem(
|
||||
id: 1,
|
||||
thumbnailImageUrl: "",
|
||||
detailImageUrl: "",
|
||||
popupImageUrl: "",
|
||||
link: "http://m.naver.com"
|
||||
)
|
||||
)
|
||||
EventDetailView(eventId: 0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user