feat(content): 콘텐츠 탭 당겨서 새로고침을 추가한다
This commit is contained in:
@@ -70,11 +70,9 @@ struct MainContentAllView: View {
|
|||||||
sortBar
|
sortBar
|
||||||
|
|
||||||
if viewModel.isLoading && viewModel.hasLoaded == false {
|
if viewModel.isLoading && viewModel.hasLoaded == false {
|
||||||
ProgressView()
|
loadingContent
|
||||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
} else if viewModel.shouldShowEmptyState {
|
} else if viewModel.shouldShowEmptyState {
|
||||||
MainContentAudioEmptyStateView(message: I18n.MainContentAll.emptyStateMessage)
|
emptyContent
|
||||||
} else {
|
} else {
|
||||||
ScrollView(showsIndicators: false) {
|
ScrollView(showsIndicators: false) {
|
||||||
gridContent
|
gridContent
|
||||||
@@ -88,6 +86,35 @@ struct MainContentAllView: View {
|
|||||||
.padding(.vertical, SodaSpacing.s20)
|
.padding(.vertical, SodaSpacing.s20)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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: I18n.MainContentAll.emptyStateMessage)
|
||||||
|
.frame(minHeight: geometry.size.height)
|
||||||
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,4 +224,3 @@ struct MainContentAllView_Previews: PreviewProvider {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ final class MainContentAllViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchFirstPageIfNeeded() {
|
func fetchFirstPageIfNeeded() {
|
||||||
guard hasLoaded == false else { return }
|
guard hasLoaded == false, isLoading == false else { return }
|
||||||
fetchFirstPage()
|
fetchFirstPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +40,16 @@ final class MainContentAllViewModel: ObservableObject {
|
|||||||
fetchContents(page: 0, isNextPage: false)
|
fetchContents(page: 0, isNextPage: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refresh() async {
|
||||||
|
if !isLoading {
|
||||||
|
fetchFirstPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
for await isLoading in $isLoading.values {
|
||||||
|
if !isLoading { return }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func apply(type: MainContentAllType, sort: ContentSort) {
|
func apply(type: MainContentAllType, sort: ContentSort) {
|
||||||
guard allowedSorts(for: type).contains(sort) else { return }
|
guard allowedSorts(for: type).contains(sort) else { return }
|
||||||
|
|
||||||
@@ -247,4 +257,3 @@ extension SeriesPublishedDaysOfWeek {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,9 @@ struct MainContentRankingView: View {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if viewModel.isLoading && !viewModel.hasLoaded {
|
if viewModel.isLoading && !viewModel.hasLoaded {
|
||||||
ProgressView()
|
loadingContent
|
||||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
} else if viewModel.shouldShowEmptyState {
|
} else if viewModel.shouldShowEmptyState {
|
||||||
MainContentAudioRankingEmptyStateView(message: viewModel.emptyStateMessage)
|
emptyContent
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
||||||
} else {
|
} else {
|
||||||
rankingContent
|
rankingContent
|
||||||
}
|
}
|
||||||
@@ -41,6 +38,20 @@ struct MainContentRankingView: View {
|
|||||||
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2)
|
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, 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 rankingContent: some View {
|
private var rankingContent: some View {
|
||||||
ScrollView(showsIndicators: false) {
|
ScrollView(showsIndicators: false) {
|
||||||
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
|
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
|
||||||
@@ -93,6 +104,21 @@ struct MainContentRankingView: View {
|
|||||||
.padding(.horizontal, SodaSpacing.s8)
|
.padding(.horizontal, SodaSpacing.s8)
|
||||||
.padding(.vertical, SodaSpacing.s20)
|
.padding(.vertical, SodaSpacing.s20)
|
||||||
}
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var emptyContent: some View {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
ScrollView(showsIndicators: false) {
|
||||||
|
MainContentAudioRankingEmptyStateView(message: viewModel.emptyStateMessage)
|
||||||
|
.frame(minHeight: geometry.size.height)
|
||||||
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var twoColumns: [GridItem] {
|
private var twoColumns: [GridItem] {
|
||||||
|
|||||||
@@ -32,19 +32,17 @@ final class MainContentRankingViewModel: ObservableObject {
|
|||||||
|
|
||||||
repository.getAudioRankings(type: selectedType)
|
repository.getAudioRankings(type: selectedType)
|
||||||
.sink { [weak self] result in
|
.sink { [weak self] result in
|
||||||
guard let self else { return }
|
|
||||||
|
|
||||||
switch result {
|
switch result {
|
||||||
case .finished:
|
case .finished:
|
||||||
DEBUG_LOG("finish")
|
DEBUG_LOG("finish")
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
ERROR_LOG(error.localizedDescription)
|
ERROR_LOG(error.localizedDescription)
|
||||||
self.items = []
|
self?.items = []
|
||||||
self.showRankChange = false
|
self?.showRankChange = false
|
||||||
self.errorMessage = I18n.MainContentRanking.loadFailedMessage
|
self?.errorMessage = I18n.MainContentRanking.loadFailedMessage
|
||||||
self.isShowPopup = true
|
self?.isShowPopup = true
|
||||||
self.isLoading = false
|
self?.isLoading = false
|
||||||
self.hasLoaded = true
|
self?.hasLoaded = true
|
||||||
}
|
}
|
||||||
} receiveValue: { [weak self] response in
|
} receiveValue: { [weak self] response in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
@@ -79,6 +77,16 @@ final class MainContentRankingViewModel: ObservableObject {
|
|||||||
.store(in: &subscription)
|
.store(in: &subscription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refresh() async {
|
||||||
|
if !isLoading {
|
||||||
|
fetchRankings()
|
||||||
|
}
|
||||||
|
|
||||||
|
for await isLoading in $isLoading.values {
|
||||||
|
if !isLoading { return }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func selectType(_ type: AudioRankingType) {
|
func selectType(_ type: AudioRankingType) {
|
||||||
guard selectedType != type else { return }
|
guard selectedType != type else { return }
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ struct MainContentRecommendationView: View {
|
|||||||
Color.black
|
Color.black
|
||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
|
|
||||||
if viewModel.isLoading && viewModel.recommendations == nil {
|
if viewModel.isLoading && !viewModel.hasLoaded {
|
||||||
ProgressView()
|
loadingContent
|
||||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
|
||||||
} else if viewModel.shouldShowEmptyState {
|
} else if viewModel.shouldShowEmptyState {
|
||||||
MainContentAudioEmptyStateView(message: viewModel.emptyStateMessage)
|
emptyContent
|
||||||
} else {
|
} else {
|
||||||
ScrollView(showsIndicators: false) {
|
ScrollView(showsIndicators: false) {
|
||||||
VStack(alignment: .leading, spacing: SodaSpacing.s24) {
|
VStack(alignment: .leading, spacing: SodaSpacing.s24) {
|
||||||
@@ -81,6 +80,9 @@ struct MainContentRecommendationView: View {
|
|||||||
}
|
}
|
||||||
.padding(.vertical, SodaSpacing.s20)
|
.padding(.vertical, SodaSpacing.s20)
|
||||||
}
|
}
|
||||||
|
.refreshable {
|
||||||
|
await viewModel.refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@@ -94,4 +96,30 @@ struct MainContentRecommendationView: View {
|
|||||||
autohideIn: 2
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,17 +30,15 @@ final class MainContentRecommendationViewModel: ObservableObject {
|
|||||||
|
|
||||||
repository.getAudioRecommendations()
|
repository.getAudioRecommendations()
|
||||||
.sink { [weak self] result in
|
.sink { [weak self] result in
|
||||||
guard let self else { return }
|
|
||||||
|
|
||||||
switch result {
|
switch result {
|
||||||
case .finished:
|
case .finished:
|
||||||
DEBUG_LOG("finish")
|
DEBUG_LOG("finish")
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
ERROR_LOG(error.localizedDescription)
|
ERROR_LOG(error.localizedDescription)
|
||||||
self.errorMessage = I18n.MainContentRecommendation.loadFailedMessage
|
self?.errorMessage = I18n.MainContentRecommendation.loadFailedMessage
|
||||||
self.isShowPopup = true
|
self?.isShowPopup = true
|
||||||
self.isLoading = false
|
self?.isLoading = false
|
||||||
self.hasLoaded = true
|
self?.hasLoaded = true
|
||||||
}
|
}
|
||||||
} receiveValue: { [weak self] response in
|
} receiveValue: { [weak self] response in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
@@ -69,4 +67,14 @@ final class MainContentRecommendationViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
.store(in: &subscription)
|
.store(in: &subscription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refresh() async {
|
||||||
|
if !isLoading {
|
||||||
|
fetchRecommendations()
|
||||||
|
}
|
||||||
|
|
||||||
|
for await isLoading in $isLoading.values {
|
||||||
|
if !isLoading { return }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user