feat(content): 콘텐츠 탭 당겨서 새로고침을 추가한다

This commit is contained in:
Yu Sung
2026-08-18 13:30:15 +09:00
parent d2561272c0
commit bdd885a082
6 changed files with 135 additions and 30 deletions

View File

@@ -17,11 +17,10 @@ struct MainContentRecommendationView: View {
Color.black
.ignoresSafeArea()
if viewModel.isLoading && viewModel.recommendations == nil {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
if viewModel.isLoading && !viewModel.hasLoaded {
loadingContent
} else if viewModel.shouldShowEmptyState {
MainContentAudioEmptyStateView(message: viewModel.emptyStateMessage)
emptyContent
} else {
ScrollView(showsIndicators: false) {
VStack(alignment: .leading, spacing: SodaSpacing.s24) {
@@ -81,6 +80,9 @@ struct MainContentRecommendationView: View {
}
.padding(.vertical, SodaSpacing.s20)
}
.refreshable {
await viewModel.refresh()
}
}
}
.onAppear {
@@ -94,4 +96,30 @@ struct MainContentRecommendationView: View {
autohideIn: 2
)
}
private var loadingContent: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.frame(maxWidth: .infinity)
.frame(minHeight: geometry.size.height)
}
.refreshable {
await viewModel.refresh()
}
}
}
private var emptyContent: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
MainContentAudioEmptyStateView(message: viewModel.emptyStateMessage)
.frame(minHeight: geometry.size.height)
}
.refreshable {
await viewModel.refresh()
}
}
}
}

View File

@@ -30,17 +30,15 @@ final class MainContentRecommendationViewModel: ObservableObject {
repository.getAudioRecommendations()
.sink { [weak self] result in
guard let self else { return }
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
self.errorMessage = I18n.MainContentRecommendation.loadFailedMessage
self.isShowPopup = true
self.isLoading = false
self.hasLoaded = true
self?.errorMessage = I18n.MainContentRecommendation.loadFailedMessage
self?.isShowPopup = true
self?.isLoading = false
self?.hasLoaded = true
}
} receiveValue: { [weak self] response in
guard let self else { return }
@@ -69,4 +67,14 @@ final class MainContentRecommendationViewModel: ObservableObject {
}
.store(in: &subscription)
}
func refresh() async {
if !isLoading {
fetchRecommendations()
}
for await isLoading in $isLoading.values {
if !isLoading { return }
}
}
}