From ad163f158fb362c009dc046dfc6d8fc8d655143f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=9F=E3=81=A4=E3=81=9D=E3=82=99=E3=81=86?= Date: Fri, 10 Sep 2021 12:17:03 +0800 Subject: [PATCH] fix: Gallery navigation --- .github/workflows/deploy.yml | 2 +- EhPanda/DataFlow/AppCommand.swift | 91 ++++++++++++------------------- EhPanda/View/Home/HomeView.swift | 21 +++++-- 3 files changed, 53 insertions(+), 61 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c2264be0..ee1a2519 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,7 +6,7 @@ on: types: [closed] env: DEVELOPER_DIR: /Applications/Xcode_13.0.app - APP_VERSION: '1.0.5' + APP_VERSION: '1.0.6' SCHEME_NAME: 'EhPanda' BUILDS_PATH: '/tmp/action-builds' ARCHIVE_PATH: '/tmp/action-builds/EhPanda.xcarchive' diff --git a/EhPanda/DataFlow/AppCommand.swift b/EhPanda/DataFlow/AppCommand.swift index c0c31846..7bcfccf9 100644 --- a/EhPanda/DataFlow/AppCommand.swift +++ b/EhPanda/DataFlow/AppCommand.swift @@ -6,6 +6,7 @@ // import Kanna +import SwiftUI import Combine import Foundation @@ -16,8 +17,7 @@ protocol AppCommand { struct FetchGreetingCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - GreetingRequest() - .publisher + GreetingRequest().publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -36,8 +36,7 @@ struct FetchUserInfoCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - UserInfoRequest(uid: uid) - .publisher + UserInfoRequest(uid: uid).publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -54,8 +53,7 @@ struct FetchUserInfoCommand: AppCommand { struct FetchFavoriteNamesCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - FavoriteNamesRequest() - .publisher + FavoriteNamesRequest().publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -76,8 +74,7 @@ struct FetchTagTranslatorCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() TagTranslatorRequest(language: language, updatedDate: updatedDate) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchTagTranslatorDone(result: .failure(error))) @@ -91,6 +88,8 @@ struct FetchTagTranslatorCommand: AppCommand { } struct FetchGalleryItemReverseCommand: AppCommand { + @State var didReceiveGallery = false // workaround + let gid: String let url: String let shouldParseGalleryURL: Bool @@ -98,15 +97,19 @@ struct FetchGalleryItemReverseCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() GalleryItemReverseRequest(url: url, shouldParseGalleryURL: shouldParseGalleryURL) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in - if case .failure(let error) = completion { + switch completion { + case .failure(let error): store.dispatch(.fetchGalleryItemReverseDone(carriedValue: gid, result: .failure(error))) + case .finished: + guard !didReceiveGallery else { break } + store.dispatch(.fetchGalleryItemReverseDone(carriedValue: gid, result: .failure(.networkingFailed))) } token.unseal() } receiveValue: { gallery in if let gallery = gallery { + didReceiveGallery = true store.dispatch(.fetchGalleryItemReverseDone(carriedValue: gid, result: .success(gallery))) } else { store.dispatch(.fetchGalleryItemReverseDone(carriedValue: gid, result: .failure(.networkingFailed))) @@ -123,8 +126,7 @@ struct FetchSearchItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() SearchItemsRequest(keyword: keyword, filter: filter) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchSearchItemsDone(result: .failure(error))) @@ -181,8 +183,7 @@ struct FetchMoreSearchItemsCommand: AppCommand { struct FetchFrontpageItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - FrontpageItemsRequest() - .publisher + FrontpageItemsRequest().publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -211,8 +212,7 @@ struct FetchMoreFrontpageItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() MoreFrontpageItemsRequest(lastID: lastID, pageNum: pageNum) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchMoreFrontpageItemsDone(result: .failure(error))) @@ -233,8 +233,7 @@ struct FetchMoreFrontpageItemsCommand: AppCommand { struct FetchPopularItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - PopularItemsRequest() - .publisher + PopularItemsRequest().publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -255,8 +254,7 @@ struct FetchPopularItemsCommand: AppCommand { struct FetchWatchedItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - WatchedItemsRequest() - .publisher + WatchedItemsRequest().publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -285,8 +283,7 @@ struct FetchMoreWatchedItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() MoreWatchedItemsRequest(lastID: lastID, pageNum: pageNum) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchMoreWatchedItemsDone(result: .failure(error))) @@ -310,8 +307,7 @@ struct FetchFavoritesItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() FavoritesItemsRequest(favIndex: favIndex) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchFavoritesItemsDone(carriedValue: favIndex, result: .failure(error))) @@ -342,8 +338,7 @@ struct FetchMoreFavoritesItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() MoreFavoritesItemsRequest(favIndex: favIndex, lastID: lastID, pageNum: pageNum) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchMoreFavoritesItemsDone(carriedValue: favIndex, result: .failure(error))) @@ -369,8 +364,7 @@ struct FetchToplistsItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() ToplistsItemsRequest(catIndex: catIndex) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchToplistsItemsDone(carriedValue: topIndex, result: .failure(error))) @@ -401,8 +395,7 @@ struct FetchMoreToplistsItemsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() MoreToplistsItemsRequest(catIndex: catIndex, pageNum: pageNum) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchMoreToplistsItemsDone(carriedValue: topIndex, result: .failure(error))) @@ -428,8 +421,7 @@ struct FetchGalleryDetailCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() GalleryDetailRequest(gid: gid, galleryURL: galleryURL) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchGalleryDetailDone(gid: gid, result: .failure(error))) @@ -449,8 +441,7 @@ struct FetchGalleryArchiveFundsCommand: AppCommand { func execute(in store: Store) { let sToken = SubscriptionToken() GalleryArchiveFundsRequest(gid: gid, galleryURL: galleryURL) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchGalleryArchiveFundsDone(result: .failure(error))) @@ -474,8 +465,7 @@ struct FetchGalleryPreviewsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - GalleryPreviewsRequest(url: url) - .publisher + GalleryPreviewsRequest(url: url).publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -501,8 +491,7 @@ struct FetchMPVKeysCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - MPVKeysRequest(mpvURL: mpvURL) - .publisher + MPVKeysRequest(mpvURL: mpvURL).publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -527,8 +516,7 @@ struct FetchThumbnailsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - ThumbnailsRequest(url: url) - .publisher + ThumbnailsRequest(url: url).publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -554,8 +542,7 @@ struct FetchGalleryNormalContentsCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() GalleryNormalContentsRequest(thumbnails: thumbnails) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { store.dispatch(.fetchGalleryNormalContentsDone(gid: gid, index: index, result: .failure(error))) @@ -645,8 +632,7 @@ struct FetchGalleryMPVContentCommand: AppCommand { struct FetchIgneousCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - IgneousRequest() - .publisher + IgneousRequest().publisher .receive(on: DispatchQueue.main) .sink { _ in token.unseal() @@ -658,8 +644,7 @@ struct FetchIgneousCommand: AppCommand { struct VerifyEhProfileCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() - VerifyEhProfileRequest() - .publisher + VerifyEhProfileRequest().publisher .receive(on: DispatchQueue.main) .sink { completion in if case .failure(let error) = completion { @@ -679,8 +664,7 @@ struct CreateEhProfileCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() EhProfileRequest(action: .create, name: name) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { _ in token.unseal() } receiveValue: { _ in } @@ -696,8 +680,7 @@ struct AddFavoriteCommand: AppCommand { func execute(in store: Store) { let sToken = SubscriptionToken() AddFavoriteRequest(gid: gid, token: token, favIndex: favIndex) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .finished = completion { store.dispatch(.fetchGalleryDetail(gid: gid)) @@ -713,8 +696,7 @@ struct DeleteFavoriteCommand: AppCommand { func execute(in store: Store) { let sToken = SubscriptionToken() - DeleteFavoriteRequest(gid: gid) - .publisher + DeleteFavoriteRequest(gid: gid).publisher .receive(on: DispatchQueue.main) .sink { completion in if case .finished = completion { @@ -762,8 +744,7 @@ struct CommentCommand: AppCommand { func execute(in store: Store) { let token = SubscriptionToken() CommentRequest(content: content, galleryURL: galleryURL) - .publisher - .receive(on: DispatchQueue.main) + .publisher.receive(on: DispatchQueue.main) .sink { completion in if case .finished = completion { store.dispatch(.fetchGalleryDetail(gid: gid)) diff --git a/EhPanda/View/Home/HomeView.swift b/EhPanda/View/Home/HomeView.swift index 933145e1..cd5c1496 100644 --- a/EhPanda/View/Home/HomeView.swift +++ b/EhPanda/View/Home/HomeView.swift @@ -393,6 +393,7 @@ private extension HomeView { } } func handle(incomingURL: URL) { + let shouldDelayDisplay = homeInfo.frontpageItems.isEmpty handleIncomingURL(incomingURL) { shouldParseGalleryURL, incomingURL, pageIndex, commentID in guard let incomingURL = incomingURL else { return } @@ -404,11 +405,21 @@ private extension HomeView { if PersistenceController.galleryCached(gid: gid) { replaceGalleryCommentJumpID(gid: gid) } else { - store.dispatch(.fetchGalleryItemReverse( - url: incomingURL.absoluteString, - shouldParseGalleryURL: shouldParseGalleryURL - )) - showHUD() + if shouldDelayDisplay { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) { + store.dispatch(.fetchGalleryItemReverse( + url: incomingURL.absoluteString, + shouldParseGalleryURL: shouldParseGalleryURL + )) + showHUD() + } + } else { + store.dispatch(.fetchGalleryItemReverse( + url: incomingURL.absoluteString, + shouldParseGalleryURL: shouldParseGalleryURL + )) + showHUD() + } } clearPasteboard() clearObstruction()