설정 페이지 추가

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,115 @@
//
// NotificationSettingsView.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import SwiftUI
struct NotificationSettingsView: View {
@StateObject var viewModel = NotificationSettingsViewModel()
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: "알림 설정")
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
HStack(spacing: 0) {
Text("라이브 알림")
.font(.custom(Font.bold.rawValue, size: 15))
.foregroundColor(Color(hex: "eeeeee"))
Spacer()
Image(viewModel.followingChannelLive ? "btn_toggle_on_big" : "btn_toggle_off_big")
.resizable()
.frame(width: 44, height: 27)
.onTapGesture {
viewModel.followingChannelLive.toggle()
}
}
.frame(height: 50)
Rectangle()
.frame(height: 1)
.foregroundColor(Color(hex: "909090").opacity(0.3))
HStack(spacing: 0) {
Text("콘텐츠 업로드 알림")
.font(.custom(Font.bold.rawValue, size: 15))
.foregroundColor(Color(hex: "eeeeee"))
Spacer()
Image(viewModel.followingChannelUploadContent ? "btn_toggle_on_big" : "btn_toggle_off_big")
.resizable()
.frame(width: 44, height: 27)
.onTapGesture {
viewModel.followingChannelUploadContent.toggle()
}
}
.frame(height: 50)
Rectangle()
.frame(height: 1)
.foregroundColor(Color(hex: "909090").opacity(0.3))
HStack(spacing: 0) {
Text("메시지 알림")
.font(.custom(Font.bold.rawValue, size: 15))
.foregroundColor(Color(hex: "eeeeee"))
Spacer()
Image(viewModel.message ? "btn_toggle_on_big" : "btn_toggle_off_big")
.resizable()
.frame(width: 44, height: 27)
.onTapGesture {
viewModel.message.toggle()
}
}
.frame(height: 50)
}
.padding(.vertical, 6.7)
.padding(.horizontal, 13.3)
.background(Color(hex: "222222"))
.cornerRadius(10)
.padding(.top, 26.7)
.padding(.horizontal, 13.3)
}
}
.onAppear {
viewModel.getMemberInfo()
}
}
.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()
}
}
}
}
}
struct NotificationSettingsView_Previews: PreviewProvider {
static var previews: some View {
NotificationSettingsView()
}
}

View File

@@ -0,0 +1,93 @@
//
// NotificationSettingsViewModel.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
import Combine
final class NotificationSettingsViewModel: ObservableObject {
private let userRepository = UserRepository()
private var subscription = Set<AnyCancellable>()
@Published var followingChannelLive = false {
didSet {
submit(live: followingChannelLive)
}
}
@Published var followingChannelUploadContent = false {
didSet {
submit(uploadContent: followingChannelUploadContent)
}
}
@Published var message = false {
didSet {
submit(message: message)
}
}
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isLoading = false
func getMemberInfo() {
isLoading = true
userRepository.getMemberInfo()
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] 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 {
self.followingChannelLive = data.followingChannelLiveNotice ?? false
self.followingChannelUploadContent = data.followingChannelUploadContentNotice ?? false
self.message = data.messageNotice ?? false
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
func submit(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil) {
if !isLoading && (live != nil || uploadContent != nil || message != nil) {
userRepository
.updateNotificationSettings(live: live, uploadContent: uploadContent, message: message)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { _ in
}
.store(in: &subscription)
}
}
}

View File

@@ -0,0 +1,14 @@
//
// UpdateNotificationSettingRequest.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import Foundation
struct UpdateNotificationSettingRequest: Encodable {
var live: Bool? = nil
var uploadContent: Bool? = nil
var message: Bool? = nil
}