오디션

- 오디션 알림 받기 설정 추가
This commit is contained in:
Yu Sung 2025-01-09 01:02:08 +09:00
parent 7481637fbb
commit 6d5257e1c0
11 changed files with 83 additions and 3 deletions

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "btn_audition_notification_normal.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "btn_audition_notification_selected.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -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) {

View File

@ -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)
}
}

View File

@ -25,6 +25,7 @@ enum UserDefaultsKey: String, CaseIterable {
case notShowingEventPopupId
case isAdultContentVisible
case contentPreference
case isAuditionNotification
}
extension UserDefaults {

View File

@ -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
}

View File

@ -18,4 +18,5 @@ struct GetMemberInfoResponse: Decodable {
let messageNotice: Bool?
let followingChannelLiveNotice: Bool?
let followingChannelUploadContentNotice: Bool?
let auditionNotice: Bool?
}

View File

@ -11,4 +11,5 @@ struct UpdateNotificationSettingRequest: Encodable {
var live: Bool? = nil
var uploadContent: Bool? = nil
var message: Bool? = nil
var audition: Bool? = nil
}

View File

@ -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
)
)
)