diff --git a/SodaLive/Resources/Assets.xcassets/btn_toggle_off_big.imageset/btn_toggle_off_big.png b/SodaLive/Resources/Assets.xcassets/btn_toggle_off_big.imageset/btn_toggle_off_big.png index ee6af1d..d7d6da6 100644 Binary files a/SodaLive/Resources/Assets.xcassets/btn_toggle_off_big.imageset/btn_toggle_off_big.png and b/SodaLive/Resources/Assets.xcassets/btn_toggle_off_big.imageset/btn_toggle_off_big.png differ diff --git a/SodaLive/Resources/Assets.xcassets/btn_toggle_on_big.imageset/btn_toggle_on_big.png b/SodaLive/Resources/Assets.xcassets/btn_toggle_on_big.imageset/btn_toggle_on_big.png index 6898f8d..c18306b 100644 Binary files a/SodaLive/Resources/Assets.xcassets/btn_toggle_on_big.imageset/btn_toggle_on_big.png and b/SodaLive/Resources/Assets.xcassets/btn_toggle_on_big.imageset/btn_toggle_on_big.png differ diff --git a/SodaLive/Sources/Explorer/Profile/GetDonationAllResponse.swift b/SodaLive/Sources/Explorer/Profile/GetDonationAllResponse.swift index 41b929a..5fc0348 100644 --- a/SodaLive/Sources/Explorer/Profile/GetDonationAllResponse.swift +++ b/SodaLive/Sources/Explorer/Profile/GetDonationAllResponse.swift @@ -11,6 +11,7 @@ struct GetDonationAllResponse: Decodable { let accumulatedCansToday: Int let accumulatedCansLastWeek: Int let accumulatedCansThisMonth: Int + let isVisibleDonationRank: Bool let totalCount: Int let userDonationRanking: [UserDonationRankingResponse] } diff --git a/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllView.swift b/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllView.swift index 6183c4c..090535f 100644 --- a/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllView.swift +++ b/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllView.swift @@ -19,6 +19,34 @@ struct UserProfileDonationAllView: View { DetailNavigationBar(title: "후원랭킹 전체보기") if userId == UserDefaults.int(forKey: .userId) { + VStack(spacing: 10.7) { + HStack(spacing: 10) { + Spacer() + + Text("채널에 후원랭킹 활성화") + .font(.custom(Font.bold.rawValue, size: 16)) + .foregroundColor(Color(hex: "eeeeee")) + + Image(viewModel.isVisibleDonationRank ? "btn_toggle_on_big" : "btn_toggle_off_big") + .resizable() + .frame(width: 46.7, height: 27) + .onTapGesture { + viewModel.toggleVisibleDonationRank() + } + } + + HStack(spacing: 0) { + Spacer() + + Text("※ 비활성화하면 채널 내 후원랭킹이 표시되지 않으며,\n라이브 중에도 후원랭킹에 따른 뱃지가 반영되지 않습니다.") + .font(.custom(Font.medium.rawValue, size: 12)) + .foregroundColor(Color(hex: "555555")) + .multilineTextAlignment(.trailing) + } + } + .padding(.top, 13.3) + .padding(.horizontal, 13.3) + VStack(spacing: 13.3) { HStack(spacing: 0) { Text("오늘") @@ -68,8 +96,7 @@ struct UserProfileDonationAllView: View { .foregroundColor(Color(hex: "eeeeee")) } } - .padding(.vertical, 13.3) - .padding(.horizontal, 16.7) + .padding(16.7) .background(Color(hex: "13181b")) .cornerRadius(8) .padding(.top, 13.3) @@ -83,7 +110,7 @@ struct UserProfileDonationAllView: View { Text("\(viewModel.totalCount)") .font(.custom(Font.medium.rawValue, size: 12)) - .foregroundColor(Color(hex: "9970ff")) + .foregroundColor(Color(hex: "80d8ff")) .padding(.leading, 6.7) Text("개") @@ -97,7 +124,7 @@ struct UserProfileDonationAllView: View { Rectangle() .frame(width: screenSize().width - 26.7, height: 1) - .foregroundColor(Color(hex: "909090").opacity(0.5)) + .foregroundColor(Color(hex: "595959")) .padding(.top, 6.7) ScrollView(.vertical, showsIndicators: false) { diff --git a/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllViewModel.swift b/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllViewModel.swift index 5234288..5dee166 100644 --- a/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllViewModel.swift +++ b/SodaLive/Sources/Explorer/Profile/UserProfileDonationAllViewModel.swift @@ -10,6 +10,7 @@ import Combine final class UserProfileDonationAllViewModel: ObservableObject { private var repository = ExplorerRepository() + private var memberRepository = UserRepository() private var subscription = Set() @Published var errorMessage = "" @@ -20,6 +21,7 @@ final class UserProfileDonationAllViewModel: ObservableObject { @Published var accumulatedCansToday = 0 @Published var accumulatedCansLastWeek = 0 @Published var accumulatedCansThisMonth = 0 + @Published var isVisibleDonationRank = false @Published var userDonationRanking: [UserDonationRankingResponse] = [] var userId = 0 @@ -51,6 +53,7 @@ final class UserProfileDonationAllViewModel: ObservableObject { self.accumulatedCansToday = data.accumulatedCansToday self.accumulatedCansLastWeek = data.accumulatedCansLastWeek self.accumulatedCansThisMonth = data.accumulatedCansThisMonth + self.isVisibleDonationRank = data.isVisibleDonationRank if !data.userDonationRanking.isEmpty { page += 1 @@ -76,4 +79,47 @@ final class UserProfileDonationAllViewModel: ObservableObject { .store(in: &subscription) } } + + func toggleVisibleDonationRank() { + isLoading = true + + memberRepository.profileUpdate( + request: ProfileUpdateRequest( + email: UserDefaults.string(forKey: .email), + isVisibleDonationRank: !isVisibleDonationRank + ) + ) + .sink { result in + switch result { + case .finished: + DEBUG_LOG("finish") + case .failure(let error): + ERROR_LOG(error.localizedDescription) + } + } receiveValue: { [unowned self] response in + self.isLoading = false + let responseData = response.data + + do { + let jsonDecoder = JSONDecoder() + let decoded = try jsonDecoder.decode(ApiResponse.self, from: responseData) + + if decoded.success { + isVisibleDonationRank.toggle() + } else { + if let message = decoded.message { + self.errorMessage = message + } else { + self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." + } + + self.isShowPopup = true + } + } catch { + self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." + self.isShowPopup = true + } + } + .store(in: &subscription) + } } diff --git a/SodaLive/Sources/MyPage/Profile/ProfileUpdateRequest.swift b/SodaLive/Sources/MyPage/Profile/ProfileUpdateRequest.swift index d21d2e4..6923595 100644 --- a/SodaLive/Sources/MyPage/Profile/ProfileUpdateRequest.swift +++ b/SodaLive/Sources/MyPage/Profile/ProfileUpdateRequest.swift @@ -18,6 +18,7 @@ struct ProfileUpdateRequest: Encodable { var instagramUrl: String? = nil var websiteUrl: String? = nil var blogUrl: String? = nil + var isVisibleDonationRank: Bool? = nil let container: String = "ios" var insertTags: [String]? = nil var removeTags: [String]? = nil