From a08b463c1183223439e212070b34f6b8008d02f7 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Tue, 30 Apr 2024 15:28:58 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9C=EB=A6=AC=EC=A6=88=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=EB=B3=B4=EA=B8=B0=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SodaLive/Sources/App/AppStep.swift | 2 + .../Series/Content/SeriesContentAllView.swift | 52 +++++++++++++ .../Content/SeriesContentAllViewModel.swift | 74 +++++++++++++++++++ .../Content/SeriesContentListItemView.swift | 2 +- .../Series/Detail/SeriesDetailHomeView.swift | 5 +- .../Sources/Content/Series/SeriesApi.swift | 14 +++- .../Content/Series/SeriesRepository.swift | 4 + SodaLive/Sources/ContentView.swift | 3 + 8 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 SodaLive/Sources/Content/Series/Content/SeriesContentAllView.swift create mode 100644 SodaLive/Sources/Content/Series/Content/SeriesContentAllViewModel.swift diff --git a/SodaLive/Sources/App/AppStep.swift b/SodaLive/Sources/App/AppStep.swift index 1936942..1f0e74f 100644 --- a/SodaLive/Sources/App/AppStep.swift +++ b/SodaLive/Sources/App/AppStep.swift @@ -125,4 +125,6 @@ enum AppStep { case seriesDetail(seriesId: Int) case seriesAll(creatorId: Int) + + case seriesContentAll(seriesId: Int, seriesTitle: String) } diff --git a/SodaLive/Sources/Content/Series/Content/SeriesContentAllView.swift b/SodaLive/Sources/Content/Series/Content/SeriesContentAllView.swift new file mode 100644 index 0000000..36c1ad7 --- /dev/null +++ b/SodaLive/Sources/Content/Series/Content/SeriesContentAllView.swift @@ -0,0 +1,52 @@ +// +// SeriesContentAllView.swift +// SodaLive +// +// Created by klaus on 4/30/24. +// + +import SwiftUI + +struct SeriesContentAllView: View { + + @ObservedObject var viewModel = SeriesContentAllViewModel() + + let seriesId: Int + let seriesTitle: String + + var body: some View { + VStack(spacing: 0) { + BaseView(isLoading: $viewModel.isLoading) { + VStack(spacing: 0) { + DetailNavigationBar(title: "\(seriesTitle) - 전체회차 듣기") + + ScrollView(.vertical, showsIndicators: false) { + VStack(spacing: 12) { + ForEach(0..() + + var seriesId = 0 + + @Published var isLoading = false + @Published var errorMessage = "" + @Published var isShowPopup = false + @Published var seriesContentList = [GetSeriesContentListItem]() + + var page = 1 + var isLast = false + private let pageSize = 10 + + func getSeriesContentList() { + if !isLoading && !isLast { + repository + .getSeriesContentList(seriesId: seriesId, page: page, size: pageSize) + .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.self, from: responseData) + + if let data = decoded.data, decoded.success { + if page == 1 { + self.seriesContentList.removeAll() + } + + if !data.items.isEmpty { + page += 1 + self.seriesContentList.append(contentsOf: data.items) + } else { + isLast = true + } + } 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) + } + } +} diff --git a/SodaLive/Sources/Content/Series/Content/SeriesContentListItemView.swift b/SodaLive/Sources/Content/Series/Content/SeriesContentListItemView.swift index 3651ed2..f6fba79 100644 --- a/SodaLive/Sources/Content/Series/Content/SeriesContentListItemView.swift +++ b/SodaLive/Sources/Content/Series/Content/SeriesContentListItemView.swift @@ -17,7 +17,7 @@ struct SeriesContentListItemView: View { HStack(spacing: 11) { KFImage(URL(string: item.coverImage)) .resizable() - .scaledToFit() + .scaledToFill() .frame(width: 66.7, height: 66.7) .cornerRadius(5.3) diff --git a/SodaLive/Sources/Content/Series/Detail/SeriesDetailHomeView.swift b/SodaLive/Sources/Content/Series/Detail/SeriesDetailHomeView.swift index 38b1433..1dd28f3 100644 --- a/SodaLive/Sources/Content/Series/Detail/SeriesDetailHomeView.swift +++ b/SodaLive/Sources/Content/Series/Detail/SeriesDetailHomeView.swift @@ -35,7 +35,10 @@ struct SeriesDetailHomeView: View { .foregroundColor(Color.button) ) .padding(.top, 16) - .onTapGesture {} + .onTapGesture { + AppState.shared + .setAppStep(step: .seriesContentAll(seriesId: seriesId, seriesTitle: title)) + } VStack(spacing: 8) { ForEach(0.. AnyPublisher { return api.requestPublisher(.getSeriesDetail(seriesId: seriesId)) } + + func getSeriesContentList(seriesId: Int, page: Int, size: Int) -> AnyPublisher { + return api.requestPublisher(.getSeriesContentList(seriesId: seriesId, page: page, size: size)) + } } diff --git a/SodaLive/Sources/ContentView.swift b/SodaLive/Sources/ContentView.swift index 908c817..7014189 100644 --- a/SodaLive/Sources/ContentView.swift +++ b/SodaLive/Sources/ContentView.swift @@ -184,6 +184,9 @@ struct ContentView: View { case .seriesDetail(let seriesId): SeriesDetailView(seriesId: seriesId) + case .seriesContentAll(let seriesId, let seriesTitle): + SeriesContentAllView(seriesId: seriesId, seriesTitle: seriesTitle) + default: EmptyView() .frame(width: 0, height: 0, alignment: .topLeading)