오디션
- 오디션 알림 받기 설정 추가
This commit is contained in:
@@ -10,11 +10,17 @@ import SwiftUI
|
||||
struct AuditionView: View {
|
||||
|
||||
@StateObject var viewModel = AuditionViewModel()
|
||||
@AppStorage("isAuditionNotification") private var isAuditionNotification: Bool = UserDefaults.bool(forKey: .isAuditionNotification)
|
||||
|
||||
var body: some View {
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
VStack(spacing: 0) {
|
||||
HomeNavigationBar(title: "오디션") {}
|
||||
HomeNavigationBar(title: "오디션") {
|
||||
Image(isAuditionNotification ? "btn_audition_notification_selected" : "btn_audition_notification_normal")
|
||||
.onTapGesture {
|
||||
viewModel.updateNotificationSettings()
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
LazyVStack(alignment: .leading, spacing: 25) {
|
||||
|
@@ -11,6 +11,7 @@ import Combine
|
||||
final class AuditionViewModel: ObservableObject {
|
||||
|
||||
private let repository = AuditionRepository()
|
||||
private let userRepository = UserRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@@ -80,4 +81,30 @@ final class AuditionViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func updateNotificationSettings() {
|
||||
let isAuditionNotification = UserDefaults.bool(forKey: .isAuditionNotification)
|
||||
|
||||
userRepository.updateNotificationSettings(audition: !isAuditionNotification)
|
||||
.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(ApiResponseWithoutData.self, from: responseData)
|
||||
|
||||
if decoded.success {
|
||||
UserDefaults.set(!isAuditionNotification, forKey: .isAuditionNotification)
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ enum UserDefaultsKey: String, CaseIterable {
|
||||
case notShowingEventPopupId
|
||||
case isAdultContentVisible
|
||||
case contentPreference
|
||||
case isAuditionNotification
|
||||
}
|
||||
|
||||
extension UserDefaults {
|
||||
|
@@ -92,6 +92,7 @@ final class HomeViewModel: ObservableObject {
|
||||
UserDefaults.set(data.can, forKey: .can)
|
||||
UserDefaults.set(data.isAuth, forKey: .auth)
|
||||
UserDefaults.set(data.role.rawValue, forKey: .role)
|
||||
UserDefaults.set(data.auditionNotice ?? false, forKey: .isAuditionNotification)
|
||||
if data.followingChannelLiveNotice == nil && data.followingChannelUploadContentNotice == nil && data.messageNotice == nil {
|
||||
AppState.shared.isShowNotificationSettingsDialog = true
|
||||
}
|
||||
|
@@ -18,4 +18,5 @@ struct GetMemberInfoResponse: Decodable {
|
||||
let messageNotice: Bool?
|
||||
let followingChannelLiveNotice: Bool?
|
||||
let followingChannelUploadContentNotice: Bool?
|
||||
let auditionNotice: Bool?
|
||||
}
|
||||
|
@@ -11,4 +11,5 @@ struct UpdateNotificationSettingRequest: Encodable {
|
||||
var live: Bool? = nil
|
||||
var uploadContent: Bool? = nil
|
||||
var message: Bool? = nil
|
||||
var audition: Bool? = nil
|
||||
}
|
||||
|
@@ -41,13 +41,14 @@ final class UserRepository {
|
||||
return api.requestPublisher(.getMemberInfo)
|
||||
}
|
||||
|
||||
func updateNotificationSettings(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil) -> AnyPublisher<Response, MoyaError> {
|
||||
func updateNotificationSettings(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil, audition: Bool? = nil) -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(
|
||||
.notification(
|
||||
request: UpdateNotificationSettingRequest(
|
||||
live: live,
|
||||
uploadContent: uploadContent,
|
||||
message: message
|
||||
message: message,
|
||||
audition: audition
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user