메인 - 회원정보 가져오기, 푸시토큰 업데이트, 이벤트 팝업 추가
This commit is contained in:
69
SodaLive/Sources/Main/EventPopupDialogView.swift
Normal file
69
SodaLive/Sources/Main/EventPopupDialogView.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// EventPopupDialogView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/11.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct EventPopupDialogView: View {
|
||||
|
||||
let eventPopup: EventItem
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 13.3) {
|
||||
KFImage(URL(string: eventPopup.popupImageUrl!))
|
||||
.resizable()
|
||||
.frame(width: screenSize().width, height: screenSize().width)
|
||||
.scaledToFill()
|
||||
.cornerRadius(16.7, corners: [.topLeft, .topRight])
|
||||
.onTapGesture {
|
||||
AppState
|
||||
.shared
|
||||
.setAppStep(
|
||||
step: .eventDetail(
|
||||
event: eventPopup
|
||||
)
|
||||
)
|
||||
AppState.shared.eventPopup = nil
|
||||
}
|
||||
|
||||
HStack(spacing: 0) {
|
||||
Text("다시보지 않기")
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.onTapGesture {
|
||||
UserDefaults.set(eventPopup.id, forKey: .notShowingEventPopupId)
|
||||
AppState.shared.eventPopup = nil
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Text("닫기")
|
||||
.font(.custom(Font.medium.rawValue, size: 14.7))
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
.onTapGesture { AppState.shared.eventPopup = nil }
|
||||
}
|
||||
.padding(.horizontal, 26.7)
|
||||
.padding(.bottom, 13.3)
|
||||
}
|
||||
.background(Color(hex: "222222"))
|
||||
.cornerRadius(16.7, corners: [.topLeft, .topRight])
|
||||
}
|
||||
}
|
||||
|
||||
struct EventPopupDialogView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EventPopupDialogView(
|
||||
eventPopup: EventItem(
|
||||
id: 1,
|
||||
thumbnailImageUrl: "",
|
||||
detailImageUrl: "",
|
||||
popupImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
|
||||
link: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@@ -58,12 +58,49 @@ struct HomeView: View {
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
pushTokenUpdate()
|
||||
viewModel.getMemberInfo()
|
||||
viewModel.getEventPopup()
|
||||
}
|
||||
|
||||
if appState.isShowNotificationSettingsDialog {
|
||||
NotificationSettingsDialog()
|
||||
}
|
||||
|
||||
if let eventItem = appState.eventPopup {
|
||||
VStack(spacing: 0) {
|
||||
Spacer()
|
||||
|
||||
EventPopupDialogView(eventPopup: eventItem)
|
||||
|
||||
if proxy.safeAreaInsets.bottom > 0 {
|
||||
Rectangle()
|
||||
.foregroundColor(Color(hex: "222222"))
|
||||
.frame(width: proxy.size.width, height: 15.3)
|
||||
}
|
||||
}
|
||||
.background(Color(hex: "222222").opacity(0.7))
|
||||
.onTapGesture {
|
||||
AppState.shared.eventPopup = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
}
|
||||
}
|
||||
|
||||
private func pushTokenUpdate() {
|
||||
Messaging.messaging().token { token, error in
|
||||
if let error = error {
|
||||
DEBUG_LOG(error.localizedDescription)
|
||||
} else {
|
||||
if let token = token {
|
||||
UserDefaults.set(token, forKey: .pushToken)
|
||||
self.viewModel.pushTokenUpdate(pushToken: token)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeView_Previews: PreviewProvider {
|
||||
|
@@ -13,10 +13,83 @@ final class HomeViewModel: ObservableObject {
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
private let userRepository = UserRepository()
|
||||
private let eventRepository = EventRepository()
|
||||
|
||||
enum CurrentTab: String {
|
||||
case content, live, explorer, message, mypage
|
||||
}
|
||||
|
||||
@Published var currentTab: CurrentTab = .live
|
||||
|
||||
func pushTokenUpdate(pushToken: String) {
|
||||
userRepository.updatePushToken(pushToken: pushToken)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { _ in
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func getMemberInfo() {
|
||||
userRepository.getMemberInfo()
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { response in
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetMemberInfoResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
UserDefaults.set(data.can, forKey: .can)
|
||||
UserDefaults.set(data.isAuth, forKey: .auth)
|
||||
UserDefaults.set(data.role.rawValue, forKey: .role)
|
||||
if data.followingChannelLiveNotice == nil && data.followingChannelUploadContentNotice == nil && data.messageNotice == nil {
|
||||
AppState.shared.isShowNotificationSettingsDialog = true
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func getEventPopup() {
|
||||
eventRepository.getEventPopup()
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { response in
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<EventItem>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
if data.id != UserDefaults.int(forKey: .notShowingEventPopupId) {
|
||||
AppState.shared.eventPopup = data
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user