Skip to content

Commit

Permalink
[ADD] 링크 요약 시 광고 시청 이후 요약 완료 모달 뜨도록 로직 수정 (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkyuchul committed Dec 1, 2024
1 parent 2d895e5 commit 9da2a58
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ public struct SaveLinkFeature {
var isValidationURL = true
var validationReasonText = "URL 형식이 올바르지 않아요. 다시 입력해주세요."
var isLoading: Bool = false

var ad: GoogleAd?
var isAdPresented: Bool = false
}

public enum Action: BindableAction {
case binding(BindingAction<State>)

//MARK: UserAction
case onAppear
case onTapNextButton
case adDismissButtonTapped
case onTapBackButton

// MARK: Inner Business Action
case postLinkSummary
case loadAd
case sendAnalyticsLog

// MARK: Inner SetState Action
case setAd(GoogleAd)
case setAdPresented(Bool)
case setLoading(Bool)

// MARK: Present Action
case linkSummaryLoadingAlertPresented
case linkSummaryFailAlertPresented
Expand All @@ -47,6 +55,7 @@ public struct SaveLinkFeature {
@Dependency(\.alertClient) private var alertClient
@Dependency(\.linkClient) private var linkClient
@Dependency(AnalyticsClient.self) private var analyticsClient
@Dependency(GoogleMobileAdsClient.self) private var googleMobileAdsClient

public var body: some ReducerOf<Self> {
BindingReducer()
Expand All @@ -66,6 +75,9 @@ public struct SaveLinkFeature {

return .none

case .onAppear:
return .send(.loadAd)

case .onTapBackButton:
return .run { _ in await self.dismiss() }

Expand All @@ -75,37 +87,56 @@ public struct SaveLinkFeature {
await send(.sendAnalyticsLog)
}

case .adDismissButtonTapped:
return .run { send in
await send(.setLoading(false))
await send(.linkSummaryLoadingAlertPresented)

// 요약 성공 시 LodingAlert 닫힌 후 2초 뒤 메인으로 이동
try? await Task.sleep(for: .seconds(2))

await alertClient.dismiss()
await send(.onTapBackButton)
}

case .postLinkSummary:
return .run(
operation: { [state] send in
await send(.setLoading(true))

_ = try await linkClient.postLinkSummary(state.urlText.trimmingCharacters(in: .whitespaces))

await send(.setLoading(false))
await send(.linkSummaryLoadingAlertPresented)

// 요약 성공 시 LodingAlert 닫힌 후 2초 뒤 메인으로 이동
try? await Task.sleep(for: .seconds(2))

await alertClient.dismiss()
await send(.onTapBackButton)
await send(.setAdPresented(true))
},
catch: { error, send in
await send(.setLoading(false))
await send(.linkSummaryFailAlertPresented)
}
)

case .loadAd:
return .run { send in
let ad = try await googleMobileAdsClient.load()
await send(.setAd(ad))
}

case .sendAnalyticsLog:
feedSummaryButtonTappedLog()
return .none

case let .setAd(ad):
state.ad = ad
return .none

case let .setAdPresented(isPresented):
state.isAdPresented = isPresented
return .none

case let .setLoading(isLoading):
state.isLoading = isLoading
return .none

case .linkSummaryLoadingAlertPresented:
case .linkSummaryLoadingAlertPresented:
return .run { send in
await alertClient.present(.init(
isLoadingType: true,
Expand All @@ -117,16 +148,16 @@ public struct SaveLinkFeature {
}

case .linkSummaryFailAlertPresented:
return .run { send in
await alertClient.present(.init(
title: "요약 불가",
imageType: .link,
description: "링크 요약에 실패했습니다",
buttonType: .singleButton("메인으로"),
rightButtonAction: { await send(.onTapBackButton) }
))
}
return .run { send in
await alertClient.present(.init(
title: "요약 불가",
imageType: .link,
description: "링크 요약에 실패했습니다",
buttonType: .singleButton("메인으로"),
rightButtonAction: { await send(.onTapBackButton) }
))
}

default:
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public struct SaveLinkView: View {
.if(store.isLoading) { view in
view.progressBackground()
}
.onAppear { store.send(.onAppear) }
.fullScreenCover(isPresented: $store.isAdPresented) {
BKGoogleAdView(
isPresented: $store.isAdPresented,
interstitialAd: $store.ad,
dismissAdScreen: { store.send(.adDismissButtonTapped) }
)
.presentationClearBackground()
}
}
}
}
Expand Down

0 comments on commit 9da2a58

Please sign in to comment.