diff --git a/Nuage.xcodeproj/project.pbxproj b/Nuage.xcodeproj/project.pbxproj index 2e2ab22..55a5a35 100644 --- a/Nuage.xcodeproj/project.pbxproj +++ b/Nuage.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 53; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -513,7 +513,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 0.0.7; + MARKETING_VERSION = 0.0.8; PRODUCT_BUNDLE_IDENTIFIER = ch.laurinbrandner.nuage; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -541,7 +541,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.0; - MARKETING_VERSION = 0.0.7; + MARKETING_VERSION = 0.0.8; PRODUCT_BUNDLE_IDENTIFIER = ch.laurinbrandner.nuage; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/Nuage/Views/InfiniteView/PageView.swift b/Nuage/Views/InfiniteView/PageView.swift index 5898488..f99bc3e 100644 --- a/Nuage/Views/InfiniteView/PageView.swift +++ b/Nuage/Views/InfiniteView/PageView.swift @@ -16,10 +16,10 @@ private let initialPageSubscription = 0 struct PageView: View { var elements: [Element] { - return pages.map { $0.collection } - .reduce([], +) + return pages?.map { $0.collection } + .reduce([], +) ?? [] } - @State private var pages = [Page]() + @State private var pages: [Page]? private var publisher: AnyPublisher, Error> @State private var subscriptions = [Int: AnyCancellable]() @@ -28,19 +28,30 @@ struct PageView: View { var body: some View { Group { - if elements.isEmpty { + if let pages = pages { + if pages.isEmpty { + Text("Empty") + .font(.title2) + .foregroundColor(.secondary) + } + else { + content(elements, getNextPage) + } + } + else { ProgressView() .progressViewStyle(.circular) .frame(maxWidth: .infinity, maxHeight: .infinity) } - else { - content(elements, getNextPage) - } } .onAppear { publisher.receive(on: RunLoop.main) - .sink(receiveCompletion: { _ in }, receiveValue: { page in - pages.append(page) + .sink(receiveCompletion: { completion in + if case .failure(_) = completion { + pages = [] + } + }, receiveValue: { page in + pages = [page] }) .store(in: &subscriptions, key: initialPageSubscription) } @@ -55,16 +66,16 @@ struct PageView: View { private func getNextPage() { guard subscriptions[elements.count] == nil else { return } - let currentPagePublisher = pages.publisher + let currentPagePublisher = (pages ?? []).publisher .last() - .mapError{ $0 as Error } + .mapError { $0 as Error } publisher.merge(with: currentPagePublisher) .first() .flatMap { SoundCloud.shared.get(next: $0) } .receive(on: RunLoop.main) .sink(receiveCompletion: { _ in }, receiveValue: { page in - pages.append(page) + pages?.append(page) }) .store(in: &subscriptions, key: elements.count) }