From d7b4d1da18c43d3fd7dff8cda6f93f85ff5f5397 Mon Sep 17 00:00:00 2001 From: tomokisun Date: Mon, 5 Aug 2024 15:00:27 +0900 Subject: [PATCH] feat(core): recommendation refetch (#983) --- .../RecommendationLogic/Recommendation.swift | 27 ++++++++++++------- .../RecommendationEmpty.swift | 9 +++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Packages/MatchCore/Sources/RecommendationLogic/Recommendation.swift b/Packages/MatchCore/Sources/RecommendationLogic/Recommendation.swift index aa827d39..af673335 100644 --- a/Packages/MatchCore/Sources/RecommendationLogic/Recommendation.swift +++ b/Packages/MatchCore/Sources/RecommendationLogic/Recommendation.swift @@ -41,15 +41,7 @@ public struct RecommendationLogic { analytics.logScreen(screenName: "Recommendation", of: self) return .merge( .run(operation: { send in - await withTaskCancellation(id: Cancel.recommendations, cancelInFlight: true) { - do { - for try await data in recommendations() { - await send(.recommendationsResponse(.success(data)), animation: .default) - } - } catch { - await send(.recommendationsResponse(.failure(error)), animation: .default) - } - } + await requestRecommendations(send: send) }), .run(operation: { _ in guard try await requestAuthorization([.alert, .sound, .badge]) @@ -72,6 +64,11 @@ public struct RecommendationLogic { state = .empty() return .none + case .empty(.delegate(.shareFinished)): + return .run { send in + await requestRecommendations(send: send) + } + default: return .none } @@ -83,4 +80,16 @@ public struct RecommendationLogic { RecommendationEmptyLogic() } } + + private func requestRecommendations(send: Send) async { + await withTaskCancellation(id: Cancel.recommendations, cancelInFlight: true) { + do { + for try await data in recommendations() { + await send(.recommendationsResponse(.success(data)), animation: .default) + } + } catch { + await send(.recommendationsResponse(.failure(error)), animation: .default) + } + } + } } diff --git a/Packages/MatchCore/Sources/RecommendationLogic/RecommendationEmpty.swift b/Packages/MatchCore/Sources/RecommendationLogic/RecommendationEmpty.swift index e7ebecd6..2112be88 100644 --- a/Packages/MatchCore/Sources/RecommendationLogic/RecommendationEmpty.swift +++ b/Packages/MatchCore/Sources/RecommendationLogic/RecommendationEmpty.swift @@ -37,6 +37,11 @@ public struct RecommendationEmptyLogic { case shareButtonTapped case onCompletion(CompletionWithItems) case binding(BindingAction) + case delegate(Delegate) + + public enum Delegate: Equatable { + case shareFinished + } } @Dependency(\.analytics) var analytics @@ -61,6 +66,10 @@ public struct RecommendationEmptyLogic { "activity_type": completion.activityType?.rawValue ?? "", "result": completion.result, ]) + + if completion.result { + return Effect.send(.delegate(.shareFinished), animation: .default) + } return .none default: