Skip to content

Commit

Permalink
feat(core): recommendation refetch (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun authored Aug 5, 2024
1 parent da55230 commit d7b4d1d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
}
Expand All @@ -83,4 +80,16 @@ public struct RecommendationLogic {
RecommendationEmptyLogic()
}
}

private func requestRecommendations(send: Send<Action>) 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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public struct RecommendationEmptyLogic {
case shareButtonTapped
case onCompletion(CompletionWithItems)
case binding(BindingAction<State>)
case delegate(Delegate)

public enum Delegate: Equatable {
case shareFinished
}
}

@Dependency(\.analytics) var analytics
Expand All @@ -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:
Expand Down

0 comments on commit d7b4d1d

Please sign in to comment.