From 2ef7db8e263574475aba531cafb8de8eacc40b50 Mon Sep 17 00:00:00 2001 From: Chihchy Date: Sat, 27 Jan 2024 22:51:34 +0800 Subject: [PATCH] Resolve compiler warnings [WIP] --- EhPanda/DataFlow/AppDelegateReducer.swift | 2 +- EhPanda/DataFlow/AppLockReducer.swift | 8 +- EhPanda/DataFlow/AppReducer.swift | 46 +++++------ EhPanda/DataFlow/AppRouteReducer.swift | 28 +++---- .../Detail/Archives/ArchivesReducer.swift | 6 +- .../Detail/Comments/CommentsReducer.swift | 32 ++++---- EhPanda/View/Detail/DetailReducer.swift | 48 ++++++------ .../DetailSearch/DetailSearchReducer.swift | 12 +-- .../Detail/Previews/PreviewsReducer.swift | 10 +-- .../Detail/Torrents/TorrentsReducer.swift | 4 +- EhPanda/View/Favorites/FavoritesReducer.swift | 10 +-- .../Home/Frontpage/FrontpageReducer.swift | 10 +-- .../View/Home/History/HistoryReducer.swift | 8 +- EhPanda/View/Home/HomeReducer.swift | 22 +++--- .../View/Home/Popular/PopularReducer.swift | 6 +- .../View/Home/Toplists/ToplistsReducer.swift | 12 +-- .../View/Home/Watched/WatchedReducer.swift | 12 +-- EhPanda/View/Migration/MigrationReducer.swift | 4 +- EhPanda/View/Reading/ReadingReducer.swift | 48 ++++++------ EhPanda/View/Search/SearchReducer.swift | 12 +-- EhPanda/View/Search/SearchRootReducer.swift | 20 ++--- .../Search/Support/QuickSearchReducer.swift | 14 ++-- .../AccountSettingReducer.swift | 2 + .../GeneralSettingReducer.swift | 8 +- EhPanda/View/Setting/SettingReducer.swift | 76 +++++++++---------- EhPanda/View/Support/FiltersReducer.swift | 12 +-- 26 files changed, 237 insertions(+), 235 deletions(-) diff --git a/EhPanda/DataFlow/AppDelegateReducer.swift b/EhPanda/DataFlow/AppDelegateReducer.swift index 53efa716..d21cc097 100644 --- a/EhPanda/DataFlow/AppDelegateReducer.swift +++ b/EhPanda/DataFlow/AppDelegateReducer.swift @@ -36,7 +36,7 @@ struct AppDelegateReducer: ReducerProtocol { cookieClient.syncExCookies().fireAndForget(), cookieClient.ignoreOffensive().fireAndForget(), cookieClient.fulfillAnotherHostField().fireAndForget(), - .init(value: .migration(.prepareDatabase)) + .send(.migration(.prepareDatabase)) ) case .removeExpiredImageURLs: diff --git a/EhPanda/DataFlow/AppLockReducer.swift b/EhPanda/DataFlow/AppLockReducer.swift index daafcc15..0046ce8c 100644 --- a/EhPanda/DataFlow/AppLockReducer.swift +++ b/EhPanda/DataFlow/AppLockReducer.swift @@ -39,11 +39,11 @@ struct AppLockReducer: ReducerProtocol { Date.now.timeIntervalSince(date) >= Double(threshold) { return .merge( - .init(value: .authorize), - .init(value: .lockApp(blurRadius)) + .send(.authorize), + .send(.lockApp(blurRadius)) ) } else { - return .init(value: .unlockApp) + return .send(.unlockApp) } case .onBecomeInactive(let blurRadius): @@ -67,7 +67,7 @@ struct AppLockReducer: ReducerProtocol { .map(Action.authorizeDone) case .authorizeDone(let isSucceeded): - return isSucceeded ? .init(value: .unlockApp) : .none + return isSucceeded ? .send(.unlockApp) : .none } } } diff --git a/EhPanda/DataFlow/AppReducer.swift b/EhPanda/DataFlow/AppReducer.swift index f67bca86..78f7c099 100644 --- a/EhPanda/DataFlow/AppReducer.swift +++ b/EhPanda/DataFlow/AppReducer.swift @@ -47,10 +47,10 @@ struct AppReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.appRouteState.$route): - return state.appRouteState.route == nil ? .init(value: .appRoute(.clearSubStates)) : .none + return state.appRouteState.route == nil ? .send(.appRoute(.clearSubStates)) : .none case .binding(\.settingState.$setting): - return .init(value: .setting(.syncSetting)) + return .send(.setting(.syncSetting)) case .binding: return .none @@ -62,11 +62,11 @@ struct AppReducer: ReducerProtocol { case .active: let threshold = state.settingState.setting.autoLockPolicy.rawValue let blurRadius = state.settingState.setting.backgroundBlurRadius - return .init(value: .appLock(.onBecomeActive(threshold, blurRadius))) + return .send(.appLock(.onBecomeActive(threshold, blurRadius))) case .inactive: let blurRadius = state.settingState.setting.backgroundBlurRadius - return .init(value: .appLock(.onBecomeInactive(blurRadius))) + return .send(.appLock(.onBecomeInactive(blurRadius))) default: return .none @@ -74,8 +74,8 @@ struct AppReducer: ReducerProtocol { case .appDelegate(.migration(.onDatabasePreparationSuccess)): return .merge( - .init(value: .appDelegate(.removeExpiredImageURLs)), - .init(value: .setting(.loadUserSettings)) + .send(.appDelegate(.removeExpiredImageURLs)), + .send(.setting(.loadUserSettings)) ) case .appDelegate: @@ -85,7 +85,7 @@ struct AppReducer: ReducerProtocol { var effects = [EffectTask]() if deviceClient.isPad() { state.settingState.route = nil - effects.append(.init(value: .setting(.clearSubStates))) + effects.append(.send(.setting(.clearSubStates))) } return effects.isEmpty ? .none : .merge(effects) @@ -94,10 +94,10 @@ struct AppReducer: ReducerProtocol { case .appLock(.unlockApp): var effects: [EffectTask] = [ - .init(value: .setting(.fetchGreeting)) + .send(.setting(.fetchGreeting)) ] if state.settingState.setting.detectsLinksFromClipboard { - effects.append(.init(value: .appRoute(.detectClipboardURL))) + effects.append(.send(.appRoute(.detectClipboardURL))) } return .merge(effects) @@ -111,27 +111,27 @@ struct AppReducer: ReducerProtocol { switch type { case .home: if state.homeState.route != nil { - effects.append(.init(value: .home(.setNavigation(nil)))) + effects.append(.send(.home(.setNavigation(nil)))) } else { - effects.append(.init(value: .home(.fetchAllGalleries))) + effects.append(.send(.home(.fetchAllGalleries))) } case .favorites: if state.favoritesState.route != nil { - effects.append(.init(value: .favorites(.setNavigation(nil)))) + effects.append(.send(.favorites(.setNavigation(nil)))) effects.append(hapticEffect) } else if cookieClient.didLogin { - effects.append(.init(value: .favorites(.fetchGalleries()))) + effects.append(.send(.favorites(.fetchGalleries()))) effects.append(hapticEffect) } case .search: if state.searchRootState.route != nil { - effects.append(.init(value: .searchRoot(.setNavigation(nil)))) + effects.append(.send(.searchRoot(.setNavigation(nil)))) } else { - effects.append(.init(value: .searchRoot(.fetchDatabaseInfos))) + effects.append(.send(.searchRoot(.fetchDatabaseInfos))) } case .setting: if state.settingState.route != nil { - effects.append(.init(value: .setting(.setNavigation(nil)))) + effects.append(.send(.setting(.setNavigation(nil)))) effects.append(hapticEffect) } } @@ -140,7 +140,7 @@ struct AppReducer: ReducerProtocol { } } if type == .setting && deviceClient.isPad() { - effects.append(.init(value: .appRoute(.setNavigation(.setting)))) + effects.append(.send(.appRoute(.setNavigation(.setting)))) } return effects.isEmpty ? .none : .merge(effects) @@ -150,12 +150,12 @@ struct AppReducer: ReducerProtocol { case .home(.watched(.onNotLoginViewButtonTapped)), .favorites(.onNotLoginViewButtonTapped): var effects: [EffectTask] = [ .fireAndForget({ hapticsClient.generateFeedback(.soft) }), - .init(value: .tabBar(.setTabBarItemType(.setting))) + .send(.tabBar(.setTabBarItemType(.setting))) ] - effects.append(.init(value: .setting(.setNavigation(.account)))) + effects.append(.send(.setting(.setNavigation(.account)))) if !cookieClient.didLogin { effects.append( - .init(value: .setting(.account(.setNavigation(.login)))) + .send(.setting(.account(.setNavigation(.login)))) .delay( for: .milliseconds(deviceClient.isPad() ? 1200 : 200), scheduler: DispatchQueue.main @@ -180,15 +180,15 @@ struct AppReducer: ReducerProtocol { let blurRadius = state.settingState.setting.backgroundBlurRadius if threshold >= 0 { state.appLockState.becameInactiveDate = .distantPast - effects.append(.init(value: .appLock(.onBecomeActive(threshold, blurRadius)))) + effects.append(.send(.appLock(.onBecomeActive(threshold, blurRadius)))) } if state.settingState.setting.detectsLinksFromClipboard { - effects.append(.init(value: .appRoute(.detectClipboardURL))) + effects.append(.send(.appRoute(.detectClipboardURL))) } return effects.isEmpty ? .none : .merge(effects) case .setting(.fetchGreetingDone(let result)): - return .init(value: .appRoute(.fetchGreetingDone(result))) + return .send(.appRoute(.fetchGreetingDone(result))) case .setting: return .none diff --git a/EhPanda/DataFlow/AppRouteReducer.swift b/EhPanda/DataFlow/AppRouteReducer.swift index 9b410b04..ad888a35 100644 --- a/EhPanda/DataFlow/AppRouteReducer.swift +++ b/EhPanda/DataFlow/AppRouteReducer.swift @@ -59,14 +59,14 @@ struct AppRouteReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .setHUDConfig(let config): state.hudConfig = config @@ -74,7 +74,7 @@ struct AppRouteReducer: ReducerProtocol { case .clearSubStates: state.detailState = .init() - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .detectClipboardURL: let currentChangeCount = clipboardClient.changeCount() @@ -85,7 +85,7 @@ struct AppRouteReducer: ReducerProtocol { .setValue(currentChangeCount, .clipboardChangeCount).fireAndForget() ] if let url = clipboardClient.url() { - effects.append(.init(value: .handleDeepLink(url))) + effects.append(.send(.handleDeepLink(url))) } return .merge(effects) @@ -101,10 +101,10 @@ struct AppRouteReducer: ReducerProtocol { let (isGalleryImageURL, _, _) = urlClient.analyzeURL(url) let gid = urlClient.parseGalleryID(url) guard databaseClient.fetchGallery(gid: gid) == nil else { - return .init(value: .handleGalleryLink(url)) + return .send(.handleGalleryLink(url)) .delay(for: .milliseconds(delay + 250), scheduler: DispatchQueue.main).eraseToEffect() } - return .init(value: .fetchGallery(url, isGalleryImageURL)) + return .send(.fetchGallery(url, isGalleryImageURL)) .delay(for: .milliseconds(delay), scheduler: DispatchQueue.main).eraseToEffect() case .handleGalleryLink(let url): @@ -112,21 +112,21 @@ struct AppRouteReducer: ReducerProtocol { let gid = urlClient.parseGalleryID(url) var effects = [EffectTask]() state.detailState = .init() - effects.append(.init(value: .detail(.fetchDatabaseInfos(gid)))) + effects.append(.send(.detail(.fetchDatabaseInfos(gid)))) if let pageIndex = pageIndex { - effects.append(.init(value: .updateReadingProgress(gid, pageIndex))) + effects.append(.send(.updateReadingProgress(gid, pageIndex))) effects.append( - .init(value: .detail(.setNavigation(.reading))) + .send(.detail(.setNavigation(.reading))) .delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect() ) } else if let commentID = commentID { state.detailState.commentsState?.scrollCommentID = commentID effects.append( - .init(value: .detail(.setNavigation(.comments(url)))) + .send(.detail(.setNavigation(.comments(url)))) .delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect() ) } - effects.append(.init(value: .setNavigation(.detail(gid)))) + effects.append(.send(.setNavigation(.detail(gid)))) return .merge(effects) case .updateReadingProgress(let gid, let progress): @@ -145,16 +145,16 @@ struct AppRouteReducer: ReducerProtocol { case .success(let gallery): return .merge( databaseClient.cacheGalleries([gallery]).fireAndForget(), - .init(value: .handleGalleryLink(url)) + .send(.handleGalleryLink(url)) ) case .failure: - return .init(value: .setHUDConfig(.error)) + return .send(.setHUDConfig(.error)) .delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect() } case .fetchGreetingDone(let result): if case .success(let greeting) = result, !greeting.gainedNothing { - return .init(value: .setNavigation(.newDawn(greeting))) + return .send(.setNavigation(.newDawn(greeting))) } return .none diff --git a/EhPanda/View/Detail/Archives/ArchivesReducer.swift b/EhPanda/View/Detail/Archives/ArchivesReducer.swift index 3e180958..1ee16ead 100644 --- a/EhPanda/View/Detail/Archives/ArchivesReducer.swift +++ b/EhPanda/View/Detail/Archives/ArchivesReducer.swift @@ -85,9 +85,9 @@ struct ArchivesReducer: ReducerProtocol { } state.hathArchives = archive.hathArchives if let galleryPoints = galleryPoints, let credits = credits { - return .init(value: .syncGalleryFunds(galleryPoints, credits)) + return .send(.syncGalleryFunds(galleryPoints, credits)) } else if cookieClient.isSameAccount { - return .init(value: .fetchArchiveFunds(gid, galleryURL)) + return .send(.fetchArchiveFunds(gid, galleryURL)) } else { return .none } @@ -103,7 +103,7 @@ struct ArchivesReducer: ReducerProtocol { case .fetchArchiveFundsDone(let result): if case .success(let (galleryPoints, credits)) = result { - return .init(value: .syncGalleryFunds(galleryPoints, credits)) + return .send(.syncGalleryFunds(galleryPoints, credits)) } return .none diff --git a/EhPanda/View/Detail/Comments/CommentsReducer.swift b/EhPanda/View/Detail/Comments/CommentsReducer.swift index 98ebffaf..9f531f96 100644 --- a/EhPanda/View/Detail/Comments/CommentsReducer.swift +++ b/EhPanda/View/Detail/Comments/CommentsReducer.swift @@ -76,20 +76,20 @@ struct CommentsReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() state.commentContent = .init() state.postCommentFocused = false - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .clearScrollCommentID: state.scrollCommentID = nil @@ -113,11 +113,11 @@ struct CommentsReducer: ReducerProtocol { case .performScrollOpacityEffect: return .merge( - .init(value: .setScrollRowOpacity(0.25)) + .send(.setScrollRowOpacity(0.25)) .delay(for: .milliseconds(750), scheduler: DispatchQueue.main).eraseToEffect(), - .init(value: .setScrollRowOpacity(1)) + .send(.setScrollRowOpacity(1)) .delay(for: .milliseconds(1250), scheduler: DispatchQueue.main).eraseToEffect(), - .init(value: .clearScrollCommentID) + .send(.clearScrollCommentID) .delay(for: .milliseconds(2000), scheduler: DispatchQueue.main).eraseToEffect() ) @@ -128,39 +128,39 @@ struct CommentsReducer: ReducerProtocol { let (isGalleryImageURL, _, _) = urlClient.analyzeURL(url) let gid = urlClient.parseGalleryID(url) guard databaseClient.fetchGallery(gid: gid) == nil else { - return .init(value: .handleGalleryLink(url)) + return .send(.handleGalleryLink(url)) } - return .init(value: .fetchGallery(url, isGalleryImageURL)) + return .send(.fetchGallery(url, isGalleryImageURL)) case .handleGalleryLink(let url): let (_, pageIndex, commentID) = urlClient.analyzeURL(url) let gid = urlClient.parseGalleryID(url) var effects = [EffectTask]() if let pageIndex = pageIndex { - effects.append(.init(value: .updateReadingProgress(gid, pageIndex))) + effects.append(.send(.updateReadingProgress(gid, pageIndex))) effects.append( - .init(value: .detail(.setNavigation(.reading))) + .send(.detail(.setNavigation(.reading))) .delay(for: .milliseconds(750), scheduler: DispatchQueue.main).eraseToEffect() ) } else if let commentID = commentID { state.detailState.commentsState?.scrollCommentID = commentID effects.append( - .init(value: .detail(.setNavigation(.comments(url)))) + .send(.detail(.setNavigation(.comments(url)))) .delay(for: .milliseconds(750), scheduler: DispatchQueue.main).eraseToEffect() ) } - effects.append(.init(value: .setNavigation(.detail(gid)))) + effects.append(.send(.setNavigation(.detail(gid)))) return .merge(effects) case .onPostCommentAppear: - return .init(value: .setPostCommentFocused(true)) + return .send(.setPostCommentFocused(true)) .delay(for: .milliseconds(750), scheduler: DispatchQueue.main).eraseToEffect() case .onAppear: if state.detailState == nil { state.detailState = .init() } - return state.scrollCommentID != nil ? .init(value: .performScrollOpacityEffect) : .none + return state.scrollCommentID != nil ? .send(.performScrollOpacityEffect) : .none case .updateReadingProgress(let gid, let progress): guard !gid.isEmpty else { return .none } @@ -206,10 +206,10 @@ struct CommentsReducer: ReducerProtocol { case .success(let gallery): return .merge( databaseClient.cacheGalleries([gallery]).fireAndForget(), - .init(value: .handleGalleryLink(url)) + .send(.handleGalleryLink(url)) ) case .failure: - return .init(value: .setHUDConfig(.error)) + return .send(.setHUDConfig(.error)) .delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect() } diff --git a/EhPanda/View/Detail/DetailReducer.swift b/EhPanda/View/Detail/DetailReducer.swift index 67b0de73..96e01358 100644 --- a/EhPanda/View/Detail/DetailReducer.swift +++ b/EhPanda/View/Detail/DetailReducer.swift @@ -122,14 +122,14 @@ struct DetailReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.readingState = .init() @@ -142,16 +142,16 @@ struct DetailReducer: ReducerProtocol { state.galleryInfosState = .init() state.detailSearchState = .init() return .merge( - .init(value: .reading(.teardown)), - .init(value: .archives(.teardown)), - .init(value: .torrents(.teardown)), - .init(value: .previews(.teardown)), - .init(value: .comments(.teardown)), - .init(value: .detailSearch(.teardown)) + .send(.reading(.teardown)), + .send(.archives(.teardown)), + .send(.torrents(.teardown)), + .send(.previews(.teardown)), + .send(.comments(.teardown)), + .send(.detailSearch(.teardown)) ) case .onPostCommentAppear: - return .init(value: .setPostCommentFocused(true)) + return .send(.setPostCommentFocused(true)) .delay(for: .milliseconds(750), scheduler: DispatchQueue.main).eraseToEffect() case .onAppear(let gid, let showsNewDawnGreeting): @@ -162,7 +162,7 @@ struct DetailReducer: ReducerProtocol { if state.commentsState == nil { state.commentsState = .init() } - return .init(value: .fetchDatabaseInfos(gid)) + return .send(.fetchDatabaseInfos(gid)) case .toggleShowFullTitle: state.showsFullTitle.toggle() @@ -187,9 +187,9 @@ struct DetailReducer: ReducerProtocol { case .confirmRating(let value): state.updateRating(value: value) return .merge( - .init(value: .rateGallery), + .send(.rateGallery), .fireAndForget({ hapticsClient.generateFeedback(.soft) }), - .init(value: .confirmRatingDone).delay(for: 1, scheduler: DispatchQueue.main).eraseToEffect() + .send(.confirmRatingDone).delay(for: 1, scheduler: DispatchQueue.main).eraseToEffect() ) case .confirmRatingDone: @@ -236,7 +236,7 @@ struct DetailReducer: ReducerProtocol { state.galleryDetail = detail } return .merge( - .init(value: .saveGalleryHistory), + .send(.saveGalleryHistory), databaseClient.fetchGalleryState(gid: state.gallery.id) .map(Action.fetchDatabaseInfosDone).cancellable(id: CancelID.fetchDatabaseInfos) ) @@ -245,7 +245,7 @@ struct DetailReducer: ReducerProtocol { state.galleryTags = galleryState.tags state.galleryPreviewURLs = galleryState.previewURLs state.galleryComments = galleryState.comments - return .init(value: .fetchGalleryDetail) + return .send(.fetchGalleryDetail) case .fetchGalleryDetail: guard state.loadingState != .loading, @@ -260,10 +260,10 @@ struct DetailReducer: ReducerProtocol { switch result { case .success(let (galleryDetail, galleryState, apiKey, greeting)): var effects: [EffectTask] = [ - .init(value: .syncGalleryTags), - .init(value: .syncGalleryDetail), - .init(value: .syncGalleryPreviewURLs), - .init(value: .syncGalleryComments) + .send(.syncGalleryTags), + .send(.syncGalleryDetail), + .send(.syncGalleryPreviewURLs), + .send(.syncGalleryComments) ] state.apiKey = apiKey state.galleryDetail = galleryDetail @@ -272,13 +272,13 @@ struct DetailReducer: ReducerProtocol { state.galleryComments = galleryState.comments state.userRating = Int(galleryDetail.userRating) * 2 if let greeting = greeting { - effects.append(.init(value: .syncGreeting(greeting))) + effects.append(.send(.syncGreeting(greeting))) if !greeting.gainedNothing && state.showsNewDawnGreeting { - effects.append(.init(value: .setNavigation(.newDawn(greeting)))) + effects.append(.send(.setNavigation(.newDawn(greeting)))) } } if let config = galleryState.previewConfig { - effects.append(.init(value: .syncPreviewConfig(config))) + effects.append(.send(.syncPreviewConfig(config))) } return .merge(effects) case .failure(let error): @@ -319,14 +319,14 @@ struct DetailReducer: ReducerProtocol { case .anyGalleryOpsDone(let result): if case .success = result { return .merge( - .init(value: .fetchGalleryDetail), + .send(.fetchGalleryDetail), .fireAndForget({ hapticsClient.generateNotificationFeedback(.success) }) ) } return .fireAndForget({ hapticsClient.generateNotificationFeedback(.error) }) case .reading(.onPerformDismiss): - return .init(value: .setNavigation(nil)) + return .send(.setNavigation(nil)) case .reading: return .none @@ -341,7 +341,7 @@ struct DetailReducer: ReducerProtocol { return .none case .comments(.performCommentActionDone(let result)): - return .init(value: .anyGalleryOpsDone(result)) + return .send(.anyGalleryOpsDone(result)) case .comments(.detail(let recursiveAction)): guard state.commentsState != nil else { return .none } diff --git a/EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift b/EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift index d1aa1d7b..4aba5395 100644 --- a/EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift +++ b/EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift @@ -70,7 +70,7 @@ struct DetailSearchReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding(\.$keyword): if !state.keyword.isEmpty { @@ -83,15 +83,15 @@ struct DetailSearchReducer: ReducerProtocol { case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() state.filtersState = .init() state.quickDetailSearchState = .init() return .merge( - .init(value: .detail(.teardown)), - .init(value: .quickSearch(.teardown)) + .send(.detail(.teardown)), + .send(.quickSearch(.teardown)) ) case .teardown: @@ -116,7 +116,7 @@ struct DetailSearchReducer: ReducerProtocol { guard !galleries.isEmpty else { state.loadingState = .failed(.notFound) guard pageNumber.hasNextPage() else { return .none } - return .init(value: .fetchMoreGalleries) + return .send(.fetchMoreGalleries) } state.pageNumber = pageNumber state.galleries = galleries @@ -149,7 +149,7 @@ struct DetailSearchReducer: ReducerProtocol { databaseClient.cacheGalleries(galleries).fireAndForget() ] if galleries.isEmpty, pageNumber.hasNextPage() { - effects.append(.init(value: .fetchMoreGalleries)) + effects.append(.send(.fetchMoreGalleries)) } else if !galleries.isEmpty { state.loadingState = .idle } diff --git a/EhPanda/View/Detail/Previews/PreviewsReducer.swift b/EhPanda/View/Detail/Previews/PreviewsReducer.swift index ec25a37b..9b2ac8a5 100644 --- a/EhPanda/View/Detail/Previews/PreviewsReducer.swift +++ b/EhPanda/View/Detail/Previews/PreviewsReducer.swift @@ -62,18 +62,18 @@ struct PreviewsReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.readingState = .init() - return .init(value: .reading(.teardown)) + return .send(.reading(.teardown)) case .syncPreviewURLs(let previewURLs): return databaseClient @@ -119,14 +119,14 @@ struct PreviewsReducer: ReducerProtocol { return .none } state.updatePreviewURLs(previewURLs) - return .init(value: .syncPreviewURLs(previewURLs)) + return .send(.syncPreviewURLs(previewURLs)) case .failure(let error): state.loadingState = .failed(error) } return .none case .reading(.onPerformDismiss): - return .init(value: .setNavigation(nil)) + return .send(.setNavigation(nil)) case .reading: return .none diff --git a/EhPanda/View/Detail/Torrents/TorrentsReducer.swift b/EhPanda/View/Detail/Torrents/TorrentsReducer.swift index 24e2d304..2d5a50e1 100644 --- a/EhPanda/View/Detail/Torrents/TorrentsReducer.swift +++ b/EhPanda/View/Detail/Torrents/TorrentsReducer.swift @@ -65,7 +65,7 @@ struct TorrentsReducer: ReducerProtocol { case .presentTorrentActivity(let hash, let data): if let url = fileClient.saveTorrent(hash: hash, data: data) { - return .init(value: .setNavigation(.share(url))) + return .send(.setNavigation(.share(url))) } return .none @@ -78,7 +78,7 @@ struct TorrentsReducer: ReducerProtocol { case .fetchTorrentDone(let hash, let result): if case .success(let data) = result, !data.isEmpty { - return .init(value: .presentTorrentActivity(hash, data)) + return .send(.presentTorrentActivity(hash, data)) } return .none diff --git a/EhPanda/View/Favorites/FavoritesReducer.swift b/EhPanda/View/Favorites/FavoritesReducer.swift index c2c694cf..05c8b679 100644 --- a/EhPanda/View/Favorites/FavoritesReducer.swift +++ b/EhPanda/View/Favorites/FavoritesReducer.swift @@ -81,14 +81,14 @@ struct FavoritesReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .setFavoritesIndex(let index): state.index = index @@ -97,7 +97,7 @@ struct FavoritesReducer: ReducerProtocol { case .clearSubStates: state.detailState = .init() - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .onNotLoginViewButtonTapped: return .none @@ -125,7 +125,7 @@ struct FavoritesReducer: ReducerProtocol { guard !galleries.isEmpty else { state.rawLoadingState[targetFavIndex] = .failed(.notFound) guard pageNumber.hasNextPage() else { return .none } - return .init(value: .fetchMoreGalleries) + return .send(.fetchMoreGalleries) } state.rawPageNumber[targetFavIndex] = pageNumber state.rawGalleries[targetFavIndex] = galleries @@ -164,7 +164,7 @@ struct FavoritesReducer: ReducerProtocol { databaseClient.cacheGalleries(galleries).fireAndForget() ] if galleries.isEmpty, pageNumber.hasNextPage() { - effects.append(.init(value: .fetchMoreGalleries)) + effects.append(.send(.fetchMoreGalleries)) } else if !galleries.isEmpty { state.rawLoadingState[targetFavIndex] = .idle } diff --git a/EhPanda/View/Home/Frontpage/FrontpageReducer.swift b/EhPanda/View/Home/Frontpage/FrontpageReducer.swift index b4574355..92007125 100644 --- a/EhPanda/View/Home/Frontpage/FrontpageReducer.swift +++ b/EhPanda/View/Home/Frontpage/FrontpageReducer.swift @@ -70,19 +70,19 @@ struct FrontpageReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() state.filtersState = .init() - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .teardown: return .cancel(ids: CancelID.allCases) @@ -103,7 +103,7 @@ struct FrontpageReducer: ReducerProtocol { guard !galleries.isEmpty else { state.loadingState = .failed(.notFound) guard pageNumber.hasNextPage() else { return .none } - return .init(value: .fetchMoreGalleries) + return .send(.fetchMoreGalleries) } state.pageNumber = pageNumber state.galleries = galleries @@ -136,7 +136,7 @@ struct FrontpageReducer: ReducerProtocol { databaseClient.cacheGalleries(galleries).fireAndForget() ] if galleries.isEmpty, pageNumber.hasNextPage() { - effects.append(.init(value: .fetchMoreGalleries)) + effects.append(.send(.fetchMoreGalleries)) } else if !galleries.isEmpty { state.loadingState = .idle } diff --git a/EhPanda/View/Home/History/HistoryReducer.swift b/EhPanda/View/Home/History/HistoryReducer.swift index 547275c7..abc1d983 100644 --- a/EhPanda/View/Home/History/HistoryReducer.swift +++ b/EhPanda/View/Home/History/HistoryReducer.swift @@ -54,23 +54,23 @@ struct HistoryReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .clearHistoryGalleries: return .merge( databaseClient.clearHistoryGalleries().fireAndForget(), - .init(value: .fetchGalleries) + .send(.fetchGalleries) .delay(for: .milliseconds(200), scheduler: DispatchQueue.main).eraseToEffect() ) diff --git a/EhPanda/View/Home/HomeReducer.swift b/EhPanda/View/Home/HomeReducer.swift index 0089bd72..89360949 100644 --- a/EhPanda/View/Home/HomeReducer.swift +++ b/EhPanda/View/Home/HomeReducer.swift @@ -99,13 +99,13 @@ struct HomeReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding(\.$cardPageIndex): guard state.cardPageIndex < state.popularGalleries.count else { return .none } state.currentCardID = state.popularGalleries[state.cardPageIndex].gid state.allowsCardHitTesting = false - return .init(value: .setAllowsCardHitTesting(true)) + return .send(.setAllowsCardHitTesting(true)) .delay(for: .milliseconds(300), scheduler: DispatchQueue.main) .eraseToEffect() @@ -114,7 +114,7 @@ struct HomeReducer: ReducerProtocol { case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.frontpageState = .init() @@ -124,11 +124,11 @@ struct HomeReducer: ReducerProtocol { state.historyState = .init() state.detailState = .init() return .merge( - .init(value: .frontpage(.teardown)), - .init(value: .toplists(.teardown)), - .init(value: .popular(.teardown)), - .init(value: .watched(.teardown)), - .init(value: .detail(.teardown)) + .send(.frontpage(.teardown)), + .send(.toplists(.teardown)), + .send(.popular(.teardown)), + .send(.watched(.teardown)), + .send(.detail(.teardown)) ) case .setAllowsCardHitTesting(let isAllowed): @@ -137,9 +137,9 @@ struct HomeReducer: ReducerProtocol { case .fetchAllGalleries: return .merge( - .init(value: .fetchPopularGalleries), - .init(value: .fetchFrontpageGalleries), - .init(value: .fetchAllToplistsGalleries) + .send(.fetchPopularGalleries), + .send(.fetchFrontpageGalleries), + .send(.fetchAllToplistsGalleries) ) case .fetchAllToplistsGalleries: diff --git a/EhPanda/View/Home/Popular/PopularReducer.swift b/EhPanda/View/Home/Popular/PopularReducer.swift index a6141703..0764e299 100644 --- a/EhPanda/View/Home/Popular/PopularReducer.swift +++ b/EhPanda/View/Home/Popular/PopularReducer.swift @@ -58,19 +58,19 @@ struct PopularReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() state.filtersState = .init() - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .teardown: return .cancel(id: CancelID.fetchGalleries) diff --git a/EhPanda/View/Home/Toplists/ToplistsReducer.swift b/EhPanda/View/Home/Toplists/ToplistsReducer.swift index 6497de5b..9ff047ab 100644 --- a/EhPanda/View/Home/Toplists/ToplistsReducer.swift +++ b/EhPanda/View/Home/Toplists/ToplistsReducer.swift @@ -91,7 +91,7 @@ struct ToplistsReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding(\.$jumpPageAlertPresented): if !state.jumpPageAlertPresented { @@ -104,7 +104,7 @@ struct ToplistsReducer: ReducerProtocol { case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .setToplistsType(let type): state.type = type @@ -113,7 +113,7 @@ struct ToplistsReducer: ReducerProtocol { case .clearSubStates: state.detailState = .init() - return .init(value: .detail(.teardown)) + return .send(.detail(.teardown)) case .performJumpPage: guard let index = Int(state.jumpPageIndex), @@ -121,7 +121,7 @@ struct ToplistsReducer: ReducerProtocol { index > 0, index <= pageNumber.maximum + 1 else { return .fireAndForget({ hapticsClient.generateNotificationFeedback(.error) }) } - return .init(value: .fetchGalleries(index - 1)) + return .send(.fetchGalleries(index - 1)) case .presentJumpPageAlert: state.jumpPageAlertPresented = true @@ -153,7 +153,7 @@ struct ToplistsReducer: ReducerProtocol { guard !galleries.isEmpty else { state.rawLoadingState[type] = .failed(.notFound) guard pageNumber.hasNextPage() else { return .none } - return .init(value: .fetchMoreGalleries) + return .send(.fetchMoreGalleries) } state.rawPageNumber[type] = pageNumber state.rawGalleries[type] = galleries @@ -185,7 +185,7 @@ struct ToplistsReducer: ReducerProtocol { databaseClient.cacheGalleries(galleries).fireAndForget() ] if galleries.isEmpty, pageNumber.hasNextPage() { - effects.append(.init(value: .fetchMoreGalleries)) + effects.append(.send(.fetchMoreGalleries)) } else if !galleries.isEmpty { state.rawLoadingState[type] = .idle } diff --git a/EhPanda/View/Home/Watched/WatchedReducer.swift b/EhPanda/View/Home/Watched/WatchedReducer.swift index 6f583d64..4a8a3c7a 100644 --- a/EhPanda/View/Home/Watched/WatchedReducer.swift +++ b/EhPanda/View/Home/Watched/WatchedReducer.swift @@ -70,22 +70,22 @@ struct WatchedReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() state.filtersState = .init() state.quickSearchState = .init() return .merge( - .init(value: .detail(.teardown)), - .init(value: .quickSearch(.teardown)) + .send(.detail(.teardown)), + .send(.quickSearch(.teardown)) ) case .onNotLoginViewButtonTapped: @@ -112,7 +112,7 @@ struct WatchedReducer: ReducerProtocol { guard !galleries.isEmpty else { state.loadingState = .failed(.notFound) guard pageNumber.hasNextPage() else { return .none } - return .init(value: .fetchMoreGalleries) + return .send(.fetchMoreGalleries) } state.pageNumber = pageNumber state.galleries = galleries @@ -145,7 +145,7 @@ struct WatchedReducer: ReducerProtocol { databaseClient.cacheGalleries(galleries).fireAndForget() ] if galleries.isEmpty, pageNumber.hasNextPage() { - effects.append(.init(value: .fetchMoreGalleries)) + effects.append(.send(.fetchMoreGalleries)) } else if !galleries.isEmpty { state.loadingState = .idle } diff --git a/EhPanda/View/Migration/MigrationReducer.swift b/EhPanda/View/Migration/MigrationReducer.swift index 3488ed04..5aeb9fde 100644 --- a/EhPanda/View/Migration/MigrationReducer.swift +++ b/EhPanda/View/Migration/MigrationReducer.swift @@ -55,7 +55,7 @@ struct MigrationReducer: ReducerProtocol { return .none } else { state.databaseState = .idle - return .init(value: .onDatabasePreparationSuccess) + return .send(.onDatabasePreparationSuccess) } case .dropDatabase: @@ -70,7 +70,7 @@ struct MigrationReducer: ReducerProtocol { return .none } else { state.databaseState = .idle - return .init(value: .onDatabasePreparationSuccess) + return .send(.onDatabasePreparationSuccess) } } } diff --git a/EhPanda/View/Reading/ReadingReducer.swift b/EhPanda/View/Reading/ReadingReducer.swift index 96b5560b..3901e028 100644 --- a/EhPanda/View/Reading/ReadingReducer.swift +++ b/EhPanda/View/Reading/ReadingReducer.swift @@ -218,10 +218,10 @@ struct ReadingReducer: ReducerProtocol { case .onAppear(let gid, let enablesLandscape): var effects: [EffectTask] = [ - .init(value: .fetchDatabaseInfos(gid)) + .send(.fetchDatabaseInfos(gid)) ] if enablesLandscape { - effects.append(.init(value: .setOrientationPortrait(false))) + effects.append(.send(.setOrientationPortrait(false))) } return .merge(effects) @@ -263,17 +263,17 @@ struct ReadingReducer: ReducerProtocol { return .none case .copyImage(let imageURL): - return .init(value: .fetchImage(.copy(imageURL.isGIF), imageURL)) + return .send(.fetchImage(.copy(imageURL.isGIF), imageURL)) case .saveImage(let imageURL): - return .init(value: .fetchImage(.save(imageURL.isGIF), imageURL)) + return .send(.fetchImage(.save(imageURL.isGIF), imageURL)) case .saveImageDone(let isSucceeded): state.hudConfig = isSucceeded ? .savedToPhotoLibrary : .error - return .init(value: .setNavigation(.hud)) + return .send(.setNavigation(.hud)) case .shareImage(let imageURL): - return .init(value: .fetchImage(.share(imageURL.isGIF), imageURL)) + return .send(.fetchImage(.share(imageURL.isGIF), imageURL)) case .fetchImage(let action, let imageURL): return imageClient.fetchImage(url: imageURL) @@ -286,7 +286,7 @@ struct ReadingReducer: ReducerProtocol { case .copy(let isAnimated): state.hudConfig = .copiedToClipboardSucceeded return .merge( - .init(value: .setNavigation(.hud)), + .send(.setNavigation(.hud)), clipboardClient.saveImage(image, isAnimated).fireAndForget() ) case .save(let isAnimated): @@ -294,14 +294,14 @@ struct ReadingReducer: ReducerProtocol { .saveImageToPhotoLibrary(image, isAnimated).map(Action.saveImageDone) case .share(let isAnimated): if isAnimated, let data = image.kf.data(format: .GIF) { - return .init(value: .setNavigation(.share(.data(data)))) + return .send(.setNavigation(.share(.data(data)))) } else { - return .init(value: .setNavigation(.share(.image(image)))) + return .send(.setNavigation(.share(.image(image)))) } } } else { state.hudConfig = .error - return .init(value: .setNavigation(.hud)) + return .send(.setNavigation(.hud)) } case .syncReadingProgress(let progress): @@ -326,7 +326,7 @@ struct ReadingReducer: ReducerProtocol { .cancel(ids: CancelID.allCases) ] if !deviceClient.isPad() { - effects.append(.init(value: .setOrientationPortrait(true))) + effects.append(.send(.setOrientationPortrait(true))) } return .merge(effects) @@ -367,7 +367,7 @@ struct ReadingReducer: ReducerProtocol { } state.previewLoadingStates[index] = .idle state.updatePreviewURLs(previewURLs) - return .init(value: .syncPreviewURLs(previewURLs)) + return .send(.syncPreviewURLs(previewURLs)) case .failure(let error): state.previewLoadingStates[index] = .failed(error) } @@ -375,16 +375,16 @@ struct ReadingReducer: ReducerProtocol { case .fetchImageURLs(let index): if state.mpvKey != nil { - return .init(value: .fetchMPVImageURL(index, false)) + return .send(.fetchMPVImageURL(index, false)) } else { - return .init(value: .fetchThumbnailURLs(index)) + return .send(.fetchThumbnailURLs(index)) } case .refetchImageURLs(let index): if state.mpvKey != nil { - return .init(value: .fetchMPVImageURL(index, true)) + return .send(.fetchMPVImageURL(index, true)) } else { - return .init(value: .refetchNormalImageURLs(index)) + return .send(.refetchNormalImageURLs(index)) } case .prefetchImages(let index, let prefetchLimit): @@ -420,7 +420,7 @@ struct ReadingReducer: ReducerProtocol { fetchImageURLIndices += getFetchImageURLIndices(range: nextLowerBound...nextUpperBound) } fetchImageURLIndices.forEach { - effects.append(.init(value: .fetchImageURLs($0))) + effects.append(.send(.fetchImageURLs($0))) } effects.append(imageClient.prefetchImages(prefetchImageURLs).fireAndForget()) return .merge(effects) @@ -448,12 +448,12 @@ struct ReadingReducer: ReducerProtocol { return .none } if let url = thumbnailURLs[index], urlClient.checkIfMPVURL(url) { - return .init(value: .fetchMPVKeys(index, url)) + return .send(.fetchMPVKeys(index, url)) } else { state.updateThumbnailURLs(thumbnailURLs) return .merge( - .init(value: .syncThumbnailURLs(thumbnailURLs)), - .init(value: .fetchNormalImageURLs(index, thumbnailURLs)) + .send(.syncThumbnailURLs(thumbnailURLs)), + .send(.fetchNormalImageURLs(index, thumbnailURLs)) ) } case .failure(let error): @@ -482,7 +482,7 @@ struct ReadingReducer: ReducerProtocol { state.imageURLLoadingStates[$0] = .idle } state.updateImageURLs(imageURLs, originalImageURLs) - return .init(value: .syncImageURLs(imageURLs, originalImageURLs)) + return .send(.syncImageURLs(imageURLs, originalImageURLs)) case .failure(let error): batchRange.forEach { state.imageURLLoadingStates[$0] = .failed(error) @@ -519,7 +519,7 @@ struct ReadingReducer: ReducerProtocol { } state.imageURLLoadingStates[index] = .idle state.updateImageURLs(imageURLs, [:]) - effects.append(.init(value: .syncImageURLs(imageURLs, [:]))) + effects.append(.send(.syncImageURLs(imageURLs, [:]))) return .merge(effects) case .failure(let error): state.imageURLLoadingStates[index] = .failed(error) @@ -548,7 +548,7 @@ struct ReadingReducer: ReducerProtocol { state.mpvImageKeys = mpvImageKeys return .merge( Array(1...min(3, max(1, pageCount))).map { - .init(value: .fetchMPVImageURL($0, false)) + .send(.fetchMPVImageURL($0, false)) } ) case .failure(let error): @@ -582,7 +582,7 @@ struct ReadingReducer: ReducerProtocol { state.imageURLLoadingStates[index] = .idle state.mpvSkipServerIdentifiers[index] = skipServerIdentifier state.updateImageURLs(imageURLs, originalImageURLs) - return .init(value: .syncImageURLs(imageURLs, originalImageURLs)) + return .send(.syncImageURLs(imageURLs, originalImageURLs)) case .failure(let error): state.imageURLLoadingStates[index] = .failed(error) } diff --git a/EhPanda/View/Search/SearchReducer.swift b/EhPanda/View/Search/SearchReducer.swift index f4ea5499..a85a8b0a 100644 --- a/EhPanda/View/Search/SearchReducer.swift +++ b/EhPanda/View/Search/SearchReducer.swift @@ -70,7 +70,7 @@ struct SearchReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding(\.$keyword): if !state.keyword.isEmpty { @@ -83,15 +83,15 @@ struct SearchReducer: ReducerProtocol { case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.detailState = .init() state.filtersState = .init() state.quickSearchState = .init() return .merge( - .init(value: .detail(.teardown)), - .init(value: .quickSearch(.teardown)) + .send(.detail(.teardown)), + .send(.quickSearch(.teardown)) ) case .teardown: @@ -117,7 +117,7 @@ struct SearchReducer: ReducerProtocol { guard !galleries.isEmpty else { state.loadingState = .failed(.notFound) guard pageNumber.hasNextPage() else { return .none } - return .init(value: .fetchMoreGalleries) + return .send(.fetchMoreGalleries) } state.pageNumber = pageNumber state.galleries = galleries @@ -150,7 +150,7 @@ struct SearchReducer: ReducerProtocol { databaseClient.cacheGalleries(galleries).fireAndForget() ] if galleries.isEmpty, pageNumber.hasNextPage() { - effects.append(.init(value: .fetchMoreGalleries)) + effects.append(.send(.fetchMoreGalleries)) } else if !galleries.isEmpty { state.loadingState = .idle } diff --git a/EhPanda/View/Search/SearchRootReducer.swift b/EhPanda/View/Search/SearchRootReducer.swift index a3e23634..5a5ab083 100644 --- a/EhPanda/View/Search/SearchRootReducer.swift +++ b/EhPanda/View/Search/SearchRootReducer.swift @@ -94,8 +94,8 @@ struct SearchRootReducer: ReducerProtocol { case .binding(\.$route): return state.route == nil ? .merge( - .init(value: .clearSubStates), - .init(value: .fetchDatabaseInfos) + .send(.clearSubStates), + .send(.fetchDatabaseInfos) ) : .none @@ -106,8 +106,8 @@ struct SearchRootReducer: ReducerProtocol { state.route = route return route == nil ? .merge( - .init(value: .clearSubStates), - .init(value: .fetchDatabaseInfos) + .send(.clearSubStates), + .send(.fetchDatabaseInfos) ) : .none @@ -121,9 +121,9 @@ struct SearchRootReducer: ReducerProtocol { state.filtersState = .init() state.quickSearchState = .init() return .merge( - .init(value: .search(.teardown)), - .init(value: .quickSearch(.teardown)), - .init(value: .detail(.teardown)) + .send(.search(.teardown)), + .send(.quickSearch(.teardown)), + .send(.detail(.teardown)) ) case .syncHistoryKeywords: @@ -139,11 +139,11 @@ struct SearchRootReducer: ReducerProtocol { case .appendHistoryKeyword(let keyword): state.appendHistoryKeywords([keyword]) - return .init(value: .syncHistoryKeywords) + return .send(.syncHistoryKeywords) case .removeHistoryKeyword(let keyword): state.removeHistoryKeyword(keyword) - return .init(value: .syncHistoryKeywords) + return .send(.syncHistoryKeywords) case .fetchHistoryGalleries: return databaseClient.fetchHistoryGalleries(fetchLimit: 10).map(Action.fetchHistoryGalleriesDone) @@ -158,7 +158,7 @@ struct SearchRootReducer: ReducerProtocol { } else { state.appendHistoryKeywords([state.searchState.lastKeyword]) } - return .init(value: .syncHistoryKeywords) + return .send(.syncHistoryKeywords) case .search: return .none diff --git a/EhPanda/View/Search/Support/QuickSearchReducer.swift b/EhPanda/View/Search/Support/QuickSearchReducer.swift index a1449c90..30bcb7fb 100644 --- a/EhPanda/View/Search/Support/QuickSearchReducer.swift +++ b/EhPanda/View/Search/Support/QuickSearchReducer.swift @@ -67,14 +67,14 @@ struct QuickSearchReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.focusedField = nil @@ -94,26 +94,26 @@ struct QuickSearchReducer: ReducerProtocol { case .appendWord: state.quickSearchWords.append(state.editingWord) - return .init(value: .syncQuickSearchWords) + return .send(.syncQuickSearchWords) case .editWord: if let index = state.quickSearchWords.firstIndex(where: { $0.id == state.editingWord.id }) { state.quickSearchWords[index] = state.editingWord - return .init(value: .syncQuickSearchWords) + return .send(.syncQuickSearchWords) } return .none case .deleteWord(let word): state.quickSearchWords = state.quickSearchWords.filter({ $0 != word }) - return .init(value: .syncQuickSearchWords) + return .send(.syncQuickSearchWords) case .deleteWordWithOffsets(let offsets): state.quickSearchWords.remove(atOffsets: offsets) - return .init(value: .syncQuickSearchWords) + return .send(.syncQuickSearchWords) case .moveWord(let source, let destination): state.quickSearchWords.move(fromOffsets: source, toOffset: destination) - return .init(value: .syncQuickSearchWords) + return .send(.syncQuickSearchWords) case .teardown: return .cancel(id: CancelID.fetchQuickSearchWords) diff --git a/EhPanda/View/Setting/AccountSetting/AccountSettingReducer.swift b/EhPanda/View/Setting/AccountSetting/AccountSettingReducer.swift index 5cc9b7b6..84d86140 100644 --- a/EhPanda/View/Setting/AccountSetting/AccountSettingReducer.swift +++ b/EhPanda/View/Setting/AccountSetting/AccountSettingReducer.swift @@ -33,8 +33,10 @@ struct AccountSettingReducer: ReducerProtocol { case setNavigation(Route?) case onLogoutConfirmButtonTapped case clearSubStates + case loadCookies case copyCookies(GalleryHost) + case login(LoginReducer.Action) case ehSetting(EhSettingReducer.Action) } diff --git a/EhPanda/View/Setting/GeneralSetting/GeneralSettingReducer.swift b/EhPanda/View/Setting/GeneralSetting/GeneralSettingReducer.swift index 1fcb65d4..239c4f02 100644 --- a/EhPanda/View/Setting/GeneralSetting/GeneralSettingReducer.swift +++ b/EhPanda/View/Setting/GeneralSetting/GeneralSettingReducer.swift @@ -53,18 +53,18 @@ struct GeneralSettingReducer: ReducerProtocol { Reduce { state, action in switch action { case .binding(\.$route): - return state.route == nil ? .init(value: .clearSubStates) : .none + return state.route == nil ? .send(.clearSubStates) : .none case .binding: return .none case .setNavigation(let route): state.route = route - return route == nil ? .init(value: .clearSubStates) : .none + return route == nil ? .send(.clearSubStates) : .none case .clearSubStates: state.logsState = .init() - return .init(value: .logs(.teardown)) + return .send(.logs(.teardown)) case .onTranslationsFilePicked: return .none @@ -76,7 +76,7 @@ struct GeneralSettingReducer: ReducerProtocol { return .merge( libraryClient.clearWebImageDiskCache().fireAndForget(), databaseClient.removeImageURLs().fireAndForget(), - .init(value: .calculateWebImageDiskCache) + .send(.calculateWebImageDiskCache) ) case .checkPasscodeSetting: diff --git a/EhPanda/View/Setting/SettingReducer.swift b/EhPanda/View/Setting/SettingReducer.swift index 6aec4aac..b9bfdc3f 100644 --- a/EhPanda/View/Setting/SettingReducer.swift +++ b/EhPanda/View/Setting/SettingReducer.swift @@ -116,29 +116,29 @@ struct SettingReducer: ReducerProtocol { switch action { case .binding(\.$setting.galleryHost): return .merge( - .init(value: .syncSetting), + .send(.syncSetting), userDefaultsClient .setValue(state.setting.galleryHost.rawValue, .galleryHost).fireAndForget() ) case .binding(\.$setting.enablesTagsExtension): var effects: [EffectTask] = [ - .init(value: .syncSetting) + .send(.syncSetting) ] if state.setting.enablesTagsExtension { - effects.append(.init(value: .fetchTagTranslator)) + effects.append(.send(.fetchTagTranslator)) } return .merge(effects) case .binding(\.$setting.preferredColorScheme): return .merge( - .init(value: .syncSetting), - .init(value: .syncUserInterfaceStyle) + .send(.syncSetting), + .send(.syncUserInterfaceStyle) ) case .binding(\.$setting.appIconType): return .merge( - .init(value: .syncSetting), + .send(.syncSetting), uiApplicationClient.setAlternateIconName(state.setting.appIconType.filename) .map { _ in Action.syncAppIconType } ) @@ -149,7 +149,7 @@ struct SettingReducer: ReducerProtocol { { state.setting.backgroundBlurRadius = 10 } - return .init(value: .syncSetting) + return .send(.syncSetting) case .binding(\.$setting.backgroundBlurRadius): if state.setting.autoLockPolicy != .never @@ -157,11 +157,11 @@ struct SettingReducer: ReducerProtocol { { state.setting.autoLockPolicy = .never } - return .init(value: .syncSetting) + return .send(.syncSetting) case .binding(\.$setting.enablesLandscape): var effects: [EffectTask] = [ - .init(value: .syncSetting) + .send(.syncSetting) ] if !state.setting.enablesLandscape && !deviceClient.isPad() { effects.append(appDelegateClient.setPortraitOrientationMask().fireAndForget()) @@ -172,32 +172,32 @@ struct SettingReducer: ReducerProtocol { if state.setting.doubleTapScaleFactor > state.setting.maximumScaleFactor { state.setting.doubleTapScaleFactor = state.setting.maximumScaleFactor } - return .init(value: .syncSetting) + return .send(.syncSetting) case .binding(\.$setting.doubleTapScaleFactor): if state.setting.maximumScaleFactor < state.setting.doubleTapScaleFactor { state.setting.maximumScaleFactor = state.setting.doubleTapScaleFactor } - return .init(value: .syncSetting) + return .send(.syncSetting) case .binding(\.$setting.bypassesSNIFiltering): return .merge( - .init(value: .syncSetting), + .send(.syncSetting), .fireAndForget({ hapticsClient.generateFeedback(.soft) }), dfClient.setActive(state.setting.bypassesSNIFiltering).fireAndForget() ) case .binding(\.$setting): - return .init(value: .syncSetting) + return .send(.syncSetting) case .binding(\.$route): return .none case .binding: return .merge( - .init(value: .syncUser), - .init(value: .syncSetting), - .init(value: .syncTagTranslator) + .send(.syncUser), + .send(.syncSetting), + .send(.syncTagTranslator) ) case .setNavigation(let route): @@ -238,9 +238,9 @@ struct SettingReducer: ReducerProtocol { state.tagTranslator = appEnv.tagTranslator state.user = appEnv.user var effects: [EffectTask] = [ - .init(value: .syncAppIconType), - .init(value: .loadUserSettingsDone), - .init(value: .syncUserInterfaceStyle), + .send(.syncAppIconType), + .send(.loadUserSettingsDone), + .send(.syncUserInterfaceStyle), dfClient.setActive(state.setting.bypassesSNIFiltering).fireAndForget() ] if let value: String = userDefaultsClient.getValue(.galleryHost), @@ -249,18 +249,18 @@ struct SettingReducer: ReducerProtocol { state.setting.galleryHost = galleryHost } if cookieClient.shouldFetchIgneous { - effects.append(.init(value: .fetchIgneous)) + effects.append(.send(.fetchIgneous)) } if cookieClient.didLogin { effects.append(contentsOf: [ - .init(value: .fetchUserInfo), - .init(value: .fetchGreeting), - .init(value: .fetchFavoriteCategories), - .init(value: .fetchEhProfileIndex) + .send(.fetchUserInfo), + .send(.fetchGreeting), + .send(.fetchFavoriteCategories), + .send(.fetchEhProfileIndex) ]) } if state.setting.enablesTagsExtension { - effects.append(.init(value: .fetchTagTranslator)) + effects.append(.send(.fetchTagTranslator)) } return .merge(effects) @@ -280,7 +280,7 @@ struct SettingReducer: ReducerProtocol { if case .success(let response) = result { effects.append(cookieClient.setCredentials(response: response).fireAndForget()) } - effects.append(.init(value: .account(.loadCookies))) + effects.append(.send(.account(.loadCookies))) return .merge(effects) case .fetchUserInfo: @@ -295,7 +295,7 @@ struct SettingReducer: ReducerProtocol { case .fetchUserInfoDone(let result): if case .success(let user) = result { state.updateUser(user) - return .init(value: .syncUser) + return .send(.syncUser) } return .none @@ -335,13 +335,13 @@ struct SettingReducer: ReducerProtocol { switch result { case .success(let greeting): state.setGreeting(greeting) - return .init(value: .syncUser) + return .send(.syncUser) case .failure(let error): if case .parseFailed = error { var greeting = Greeting() greeting.updateTime = Date() state.setGreeting(greeting) - return .init(value: .syncUser) + return .send(.syncUser) } } return .none @@ -356,7 +356,7 @@ struct SettingReducer: ReducerProtocol { var databaseEffect: EffectTask? if state.tagTranslator.language != language { state.tagTranslator = TagTranslator(language: language) - databaseEffect = .init(value: .syncTagTranslator) + databaseEffect = .send(.syncTagTranslator) } let updatedDate = state.tagTranslator.updatedDate let requestEffect = TagTranslatorRequest(language: language, updatedDate: updatedDate) @@ -372,7 +372,7 @@ struct SettingReducer: ReducerProtocol { switch result { case .success(let tagTranslator): state.tagTranslator = tagTranslator - return .init(value: .syncTagTranslator) + return .send(.syncTagTranslator) case .failure(let error): state.tagTranslatorLoadingState = .failed(error) } @@ -401,7 +401,7 @@ struct SettingReducer: ReducerProtocol { ) } } else if response.isProfileNotFound { - effects.append(.init(value: .createDefaultEhProfile)) + effects.append(.send(.createDefaultEhProfile)) } else { let message = "Found profile but failed in parsing value." effects.append(loggerClient.error(message, nil).fireAndForget()) @@ -424,16 +424,16 @@ struct SettingReducer: ReducerProtocol { cookieClient.removeYay().fireAndForget(), cookieClient.syncExCookies().fireAndForget(), cookieClient.fulfillAnotherHostField().fireAndForget(), - .init(value: .fetchIgneous), - .init(value: .fetchUserInfo), - .init(value: .fetchFavoriteCategories), - .init(value: .fetchEhProfileIndex) + .send(.fetchIgneous), + .send(.fetchUserInfo), + .send(.fetchFavoriteCategories), + .send(.fetchEhProfileIndex) ) case .account(.onLogoutConfirmButtonTapped): state.user = User() return .merge( - .init(value: .syncUser), + .send(.syncUser), cookieClient.clearAll().fireAndForget(), databaseClient.removeImageURLs().fireAndForget(), libraryClient.clearWebImageDiskCache().fireAndForget() @@ -448,7 +448,7 @@ struct SettingReducer: ReducerProtocol { case .general(.onRemoveCustomTranslations): state.tagTranslator.hasCustomTranslations = false state.tagTranslator.translations = .init() - return .init(value: .syncTagTranslator) + return .send(.syncTagTranslator) case .general: return .none diff --git a/EhPanda/View/Support/FiltersReducer.swift b/EhPanda/View/Support/FiltersReducer.swift index 83121f01..94e4c1c9 100644 --- a/EhPanda/View/Support/FiltersReducer.swift +++ b/EhPanda/View/Support/FiltersReducer.swift @@ -47,15 +47,15 @@ struct FiltersReducer: ReducerProtocol { switch action { case .binding(\.$searchFilter): state.searchFilter.fixInvalidData() - return .init(value: .syncFilter(.search)) + return .send(.syncFilter(.search)) case .binding(\.$globalFilter): state.globalFilter.fixInvalidData() - return .init(value: .syncFilter(.global)) + return .send(.syncFilter(.global)) case .binding(\.$watchedFilter): state.watchedFilter.fixInvalidData() - return .init(value: .syncFilter(.watched)) + return .send(.syncFilter(.watched)) case .binding: return .none @@ -91,13 +91,13 @@ struct FiltersReducer: ReducerProtocol { switch state.filterRange { case .search: state.searchFilter = .init() - return .init(value: .syncFilter(.search)) + return .send(.syncFilter(.search)) case .global: state.globalFilter = .init() - return .init(value: .syncFilter(.global)) + return .send(.syncFilter(.global)) case .watched: state.watchedFilter = .init() - return .init(value: .syncFilter(.watched)) + return .send(.syncFilter(.watched)) } case .fetchFilters: