콘텐츠 메인 - 인기 콘텐츠 정렬 추가
This commit is contained in:
		| @@ -29,7 +29,7 @@ enum ContentApi { | ||||
|     case getNewContentThemeList | ||||
|     case getNewContentAllOfTheme(theme: String, page: Int, size: Int) | ||||
|     case getAudioContentListByCurationId(curationId: Int, page: Int, size: Int, sort: ContentCurationViewModel.Sort) | ||||
|     case getContentRanking(page: Int, size: Int) | ||||
|     case getContentRanking(page: Int, size: Int, sortType: String) | ||||
| } | ||||
|  | ||||
| extension ContentApi: TargetType { | ||||
| @@ -220,10 +220,11 @@ extension ContentApi: TargetType { | ||||
|              | ||||
|             return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) | ||||
|              | ||||
|         case .getContentRanking(let page, let size): | ||||
|         case .getContentRanking(let page, let size, let sortType): | ||||
|             let parameters = [ | ||||
|                 "page": page - 1, | ||||
|                 "size": size, | ||||
|                 "sort-type": sortType | ||||
|             ] as [String : Any] | ||||
|              | ||||
|             return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) | ||||
|   | ||||
| @@ -93,7 +93,7 @@ final class ContentRepository { | ||||
|         return api.requestPublisher(.getAudioContentListByCurationId(curationId: curationId, page: page, size: size, sort: sort)) | ||||
|     } | ||||
|      | ||||
|     func getContentRanking(page: Int, size: Int) -> AnyPublisher<Response, MoyaError> { | ||||
|         return api.requestPublisher(.getContentRanking(page: page, size: size)) | ||||
|     func getContentRanking(page: Int, size: Int, sortType: String = "매출") -> AnyPublisher<Response, MoyaError> { | ||||
|         return api.requestPublisher(.getContentRanking(page: page, size: size, sortType: sortType)) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,55 @@ | ||||
| // | ||||
| //  ContentMainRankingSortView.swift | ||||
| //  SodaLive | ||||
| // | ||||
| //  Created by klaus on 2023/11/03. | ||||
| // | ||||
|  | ||||
| import SwiftUI | ||||
|  | ||||
| struct ContentMainRankingSortView: View { | ||||
|     let sorts: [String] | ||||
|     let selectSort: (String) -> Void | ||||
|      | ||||
|     @Binding var selectedSort: String | ||||
|      | ||||
|     var body: some View { | ||||
|         ScrollView(.horizontal, showsIndicators: false) { | ||||
|             HStack(alignment: .top, spacing: 8) { | ||||
|                 ForEach(0..<sorts.count, id: \.self) { index in | ||||
|                     let sort = sorts[index] | ||||
|                     Text(sort) | ||||
|                         .font(.custom(Font.medium.rawValue, size: 14.7)) | ||||
|                         .foregroundColor(Color(hex: selectedSort == sort ? "9970ff" : "777777")) | ||||
|                         .padding(.horizontal, 13.3) | ||||
|                         .padding(.vertical, 9.3) | ||||
|                         .border( | ||||
|                             Color(hex: selectedSort == sort ? "9970ff" : "eeeeee"), | ||||
|                             width: 0.5 | ||||
|                         ) | ||||
|                         .cornerRadius(16.7) | ||||
|                         .overlay( | ||||
|                             RoundedRectangle(cornerRadius: CGFloat(16.7)) | ||||
|                                 .stroke(lineWidth: 0.5) | ||||
|                                 .foregroundColor(Color(hex: selectedSort == sort ? "9970ff" : "eeeeee")) | ||||
|                         ) | ||||
|                         .onTapGesture { | ||||
|                             if selectedSort != sort { | ||||
|                                 selectSort(sort) | ||||
|                             } | ||||
|                         } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| struct ContentMainRankingSortView_Previews: PreviewProvider { | ||||
|     static var previews: some View { | ||||
|         ContentMainRankingSortView( | ||||
|             sorts: ["전체", "테마1", "테마2"], | ||||
|             selectSort: { _ in }, | ||||
|             selectedSort: .constant("전체") | ||||
|         ) | ||||
|     } | ||||
| } | ||||
| @@ -10,8 +10,12 @@ import Kingfisher | ||||
|  | ||||
| struct ContentMainRankingView: View { | ||||
|      | ||||
|     let sorts: [String] | ||||
|     let item: GetAudioContentRanking | ||||
|      | ||||
|     let selectSort: (String) -> Void | ||||
|     @Binding var selectedSort: String | ||||
|      | ||||
|     let rows = [ | ||||
|         GridItem(.fixed(60), alignment: .leading), | ||||
|         GridItem(.fixed(60), alignment: .leading), | ||||
| @@ -47,6 +51,9 @@ struct ContentMainRankingView: View { | ||||
|             .background(Color(hex: "222222")) | ||||
|             .padding(.top, 13.3) | ||||
|              | ||||
|             ContentMainRankingSortView(sorts: sorts, selectSort: selectSort, selectedSort: $selectedSort) | ||||
|                 .padding(.vertical, 16.7) | ||||
|              | ||||
|             ScrollView(.horizontal, showsIndicators: false) { | ||||
|                 LazyHGrid(rows: rows, spacing: 13.3) { | ||||
|                     ForEach(0..<item.items.count, id: \.self) { index in | ||||
| @@ -92,6 +99,7 @@ struct ContentMainRankingView: View { | ||||
| struct ContentMainRankingView_Previews: PreviewProvider { | ||||
|     static var previews: some View { | ||||
|         ContentMainRankingView( | ||||
|             sorts: ["매출", "후원", "댓글"], | ||||
|             item: GetAudioContentRanking( | ||||
|                 startDate: "2023년 10월 2일", | ||||
|                 endDate: "10월 9일", | ||||
| @@ -137,7 +145,9 @@ struct ContentMainRankingView_Previews: PreviewProvider { | ||||
|                         creatorNickname: "ㄹㄴ어ㅏㅣㅇㄴ런아ㅣ" | ||||
|                     ), | ||||
|                 ] | ||||
|             ) | ||||
|             ), | ||||
|             selectSort: { _ in }, | ||||
|             selectedSort: .constant("매출") | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -56,9 +56,15 @@ struct ContentMainView: View { | ||||
|                     .padding(.horizontal, 13.3) | ||||
|                      | ||||
|                     if let contentRanking = viewModel.contentRanking { | ||||
|                         ContentMainRankingView(item: contentRanking) | ||||
|                         ContentMainRankingView( | ||||
|                             sorts: viewModel.contentRankingSortList, | ||||
|                             item: contentRanking, | ||||
|                             selectSort: { viewModel.selectedContentRankingSort = $0 }, | ||||
|                             selectedSort: $viewModel.selectedContentRankingSort | ||||
|                         ) | ||||
|                             .padding(.top, 40) | ||||
|                             .padding(.horizontal, 13.3) | ||||
|                             .animation(nil) | ||||
|                     } | ||||
|                      | ||||
|                     if viewModel.curationList.count > 0 { | ||||
|   | ||||
| @@ -24,6 +24,7 @@ final class ContentMainViewModel: ObservableObject { | ||||
|     @Published var orderList = [GetAudioContentMainItem]() | ||||
|     @Published var themeList = [String]() | ||||
|     @Published var curationList = [GetAudioContentCurationResponse]() | ||||
|     @Published var contentRankingSortList = [String]() | ||||
|     @Published var contentRanking: GetAudioContentRanking? = nil | ||||
|      | ||||
|     @Published var selectedTheme = "전체" { | ||||
| @@ -32,6 +33,12 @@ final class ContentMainViewModel: ObservableObject { | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     @Published var selectedContentRankingSort = "매출" { | ||||
|         didSet { | ||||
|             getContentRanking() | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     func getMain() { | ||||
|         isLoading = true | ||||
|          | ||||
| @@ -66,6 +73,7 @@ final class ContentMainViewModel: ObservableObject { | ||||
|                         self.orderList.append(contentsOf: data.orderList) | ||||
|                         self.curationList.append(contentsOf: data.curationList) | ||||
|                         self.contentRanking = data.contentRanking | ||||
|                         self.contentRankingSortList.append(contentsOf: data.contentRankingSortTypeList) | ||||
|                          | ||||
|                         self.themeList.append("전체") | ||||
|                         self.themeList.append(contentsOf: data.themeList) | ||||
| @@ -124,4 +132,42 @@ final class ContentMainViewModel: ObservableObject { | ||||
|             } | ||||
|             .store(in: &subscription) | ||||
|     } | ||||
|      | ||||
|     func getContentRanking() { | ||||
|         isLoading = true | ||||
|          | ||||
|         repository.getContentRanking(page: 1, size: 12, sortType: selectedContentRankingSort) | ||||
|             .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<GetAudioContentRanking>.self, from: responseData) | ||||
|                      | ||||
|                     if let data = decoded.data, decoded.success { | ||||
|                         self.contentRanking = data | ||||
|                     } 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) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -14,6 +14,7 @@ struct GetAudioContentMainResponse: Decodable { | ||||
|     let themeList: [String] | ||||
|     let newContentList: [GetAudioContentMainItem] | ||||
|     let curationList: [GetAudioContentCurationResponse] | ||||
|     let contentRankingSortTypeList: [String] | ||||
|     let contentRanking: GetAudioContentRanking | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Yu Sung
					Yu Sung