Skip to content

Commit

Permalink
[Feature/#232] 커스텀 alert 적용 (#272)
Browse files Browse the repository at this point in the history
* feat: SplashView bottleAlert 적용

* feat: PingPongDetailView bottleAlert 적용

* feat: ReportUserView bottleAlert 적용

* feat: SandBeachView bottleAlert 적용
  • Loading branch information
leemhyungyu authored Sep 25, 2024
1 parent 85925f6 commit dc507b3
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import Foundation

import CoreLoggerInterface
import FeatureReportInterface
import DomainBottle

import CoreLoggerInterface

import ComposableArchitecture

extension PingPongDetailFeature {
Expand Down Expand Up @@ -42,12 +43,46 @@ extension PingPongDetailFeature {
imageURL: imageURL ?? "", userID: userId ?? -1, userName: userName, userAge: userAge ?? -1)
return .send(.delegate(.reportButtonDidTapped(userReportProfile)))

case .stopTalkAlertDidRequired:
state.destination = .alert(.init(
title: { TextState("중단하기") },
actions: {
ButtonState(
role: .cancel,
action: .dismiss,
label: { TextState("계속하기")})

ButtonState(
role: .destructive,
action: .confirmStopTalk,
label: { TextState("중단하기") })
},
message: { TextState("중단 시 모든 핑퐁 내용이 사라져요. 정말 중단하시겠어요?") }
))
return .none

// Destination
case let .destination(.presented(.alert(alert))):
switch alert {
case .confirmStopTalk:
return .run { [bottleID = state.bottleID] send in
try await bottleClient.stopTalk(bottleID: bottleID)
await send(.delegate(.popToRootDidRequired))
}

case .dismiss:
state.destination = nil
return .none
}

// Introduction Delegate
case let .introduction(.delegate(delegate)):
switch delegate {
case .popToRootDidRequired:
return .send(.delegate(.popToRootDidRequired))
case .stopTaskButtonTapped:
return .send(.stopTalkAlertDidRequired)
}


// QuestionAndAnswer Delegate
case let .questionAndAnswer(.delegate(delegate)):
switch delegate {
case .reloadPingPongRequired:
Expand All @@ -56,8 +91,11 @@ extension PingPongDetailFeature {
return .send(.delegate(.popToRootDidRequired))
case .refreshPingPong:
return fetchPingPong(state: &state)
case .stopTaskButtonDidTapped:
return .send(.stopTalkAlertDidRequired)
}


// Matching Delegate
case let .matching(.delegate(delegate)):
switch delegate {
case .otherBottleButtonDidTapped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public struct PingPongDetailFeature {
var matching: MatchingFeature.State
var selectedTab: PingPongDetailViewTabType

@Presents var destination: Destination.State?

public init(
bottleID: Int,
isRead: Bool,
Expand All @@ -67,7 +69,7 @@ public struct PingPongDetailFeature {
case pingPongDidFetched(_: BottlePingPong)
case backButtonDidTapped
case reportButtonDidTapped

case stopTalkAlertDidRequired

// Delegate
case delegate(Delegate)
Expand All @@ -83,6 +85,13 @@ public struct PingPongDetailFeature {
case questionAndAnswer(QuestionAndAnswerFeature.Action)
case matching(MatchingFeature.Action)
case binding(BindingAction<State>)
case destination(PresentationAction<Destination.Action>)
// Alert
case alert(Alert)
public enum Alert: Equatable {
case confirmStopTalk
case dismiss
}
}

public var body: some ReducerOf<Self> {
Expand All @@ -97,6 +106,15 @@ public struct PingPongDetailFeature {
MatchingFeature()
}
reducer
.ifLet(\.$destination, action: \.destination)
}
}

// MARK: - Destination

extension PingPongDetailFeature {
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<PingPongDetailFeature.Action.Alert>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public struct PingPongDetailView: View {
}
)
.ignoresSafeArea(.all, edges: .bottom)
.bottleAlert($store.scope(state: \.destination?.alert, action: \.destination.alert))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,7 @@ extension IntroductionFeature {
return .none

case .stopTaskButtonTapped:
state.destination = .alert(.init(
title: { TextState("중단하기") },
actions: {
ButtonState(
role: .destructive,
action: .confirmStopTalk,
label: { TextState("중단하기") })
},
message: { TextState("중단 시 모든 핑퐁 내용이 사라져요. 정말 중단하시겠어요?") }
))
return .none

case let .destination(.presented(.alert(alert))):
switch alert {
case .confirmStopTalk:
return .run { [bottleID = state.bottleID] send in
try await bottleClient.stopTalk(bottleID: bottleID)
await send(.delegate(.popToRootDidRequired))
}
}
return .send(.delegate(.stopTaskButtonTapped))

case .refreshPingPongDidRequired:
return .run { [bottleID = state.bottleID] send in
Expand All @@ -62,7 +43,7 @@ extension IntroductionFeature {
await send(.introductionFetched(pingPong.introduction ?? []))
}

case .binding, .alert:
case .binding:
return .none

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public struct IntroductionFeature {
+ (interest?.etc ?? [])
+ (interest?.sports ?? [])
}

@Presents var destination: Destination.State?


public init (bottleID: Int) {
self.bottleID = bottleID
}
Expand All @@ -88,32 +86,14 @@ public struct IntroductionFeature {

// ETC.
case binding(BindingAction<State>)
case destination(PresentationAction<Destination.Action>)

case alert(Alert)
public enum Alert: Equatable {
case confirmStopTalk
}

case delegate(Delegate)

public enum Delegate {
case popToRootDidRequired
case stopTaskButtonTapped
}
}

public var body: some ReducerOf<Self> {
reducer
.ifLet(\.$destination, action: \.destination)
}
}

// MARK: - Destination

extension IntroductionFeature {
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<IntroductionFeature.Action.Alert>)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public struct IntroductionView: View {
.padding(.top, 32.0)
}
.scrollIndicators(.hidden)
.alert($store.scope(state: \.destination?.alert, action: \.destination.alert))
.background(to: ColorToken.background(.primary))

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,10 @@ extension QuestionAndAnswerFeature {
}

case .stopTalkButtonDidTapped:
state.destination = .alert(.init(
title: { TextState("중단하기") },
actions: {
ButtonState(
role: .destructive,
action: .confirmStopTalk,
label: { TextState("중단하기") })
},
message: { TextState("중단 시 모든 핑퐁 내용이 사라져요. 정말 중단하시겠어요?") }
))
return .none
return .send(.delegate(.stopTaskButtonDidTapped))

case .refreshDidPulled:
return .send(.delegate(.refreshPingPong))

case let .destination(.presented(.alert(alert))):
switch alert {
case .confirmStopTalk:
state.isShowLoadingIndicator = true
return .run { [bottleID = state.bottleID] send in
try await bottleClient.stopTalk(bottleID: bottleID)
await send(.delegate(.popToRootDidRequired))
}
}

case .binding(\.firstLetterTextFieldContent):
if state.firstLetterTextFieldContent.count >= 50 {
Expand All @@ -132,7 +112,7 @@ extension QuestionAndAnswerFeature {
}
return .none

case .binding, .destination, .alert:
case .binding:
return .none

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ public struct QuestionAndAnswerFeature {
}
var finalSelectIsSelctedYesButton: Bool
var finalSelectIsSelctedNoButton: Bool

@Presents var destination: Destination.State?


public init(bottleID: Int) {
self.bottleID = bottleID
self.isShowLoadingIndicator = false
Expand Down Expand Up @@ -181,34 +179,19 @@ public struct QuestionAndAnswerFeature {

// ETC.
case binding(BindingAction<State>)
case destination(PresentationAction<Destination.Action>)

case alert(Alert)
public enum Alert: Equatable {
case confirmStopTalk
}

case delegate(Delegate)

public enum Delegate {
case reloadPingPongRequired
case popToRootDidRequired
case refreshPingPong
case stopTaskButtonDidTapped
}
}

public var body: some ReducerOf<Self> {
BindingReducer()
reducer
.ifLet(\.$destination, action: \.destination)
}
}

// MARK: - Destination

extension QuestionAndAnswerFeature {
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<QuestionAndAnswerFeature.Action.Alert>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public struct QuestionAndAnswerView: View {
LoadingIndicator()
}
}
.alert($store.scope(state: \.destination?.alert, action: \.destination.alert))
.background(to: ColorToken.background(.primary))
.toolbar(.hidden, for: .bottomBar)

Expand Down
32 changes: 24 additions & 8 deletions Projects/Feature/Report/Interface/Sources/ReportUserFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ extension ReportUserFeature {
print("tapped")
state.destination = .alert(.init(
title: { TextState("신고하기")},
actions: { ButtonState(
role: .destructive,
action: .confirmReport,
label: { TextState("신고하기") }) },
actions: {
ButtonState(
role: .cancel,
action: .confirmReport,
label: { TextState("계속하기") }
)

ButtonState(
role: .destructive,
action: .dismiss,
label: { TextState("중단하기") }
)
},
message: { TextState("접수 후 취소할 수 없으며 해당 사용자는 차단되요.\n정말 신고하시겠어요?")}))
return .none

Expand All @@ -43,10 +52,17 @@ extension ReportUserFeature {
}
return .none

case .destination(.presented(.alert(.confirmReport))):
return .run { [userProfile = state.userProfile, reportText = state.reportText] send in
try await reportClient.reportUser(userReportInfo: .init(reason: reportText, userId: userProfile.userID))
await send(.delegate(.reportDidCompleted))
case let .destination(.presented(.alert(alert))):
switch alert {
case .confirmReport:
return .run { [userProfile = state.userProfile, reportText = state.reportText] send in
try await reportClient.reportUser(userReportInfo: .init(reason: reportText, userId: userProfile.userID))
await send(.delegate(.reportDidCompleted))
}

case .dismiss:
state.destination = nil
return .none
}

case .binding(\.reportText):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public struct ReportUserFeature {
case alert(Alert)
public enum Alert: Equatable {
case confirmReport
case dismiss
}

// ETC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct ReportUserView: View {
}
}
.padding(.horizontal, .md)
.alert($store.scope(state: \.destination?.alert, action: \.destination.alert))
.bottleAlert($store.scope(state: \.destination?.alert, action: \.destination.alert))
.toolbar(.hidden, for: .bottomBar)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct SandBeachView: View {
}
}
}
.alert($store.scope(state: \.destination?.alert, action: \.destination.alert))
.bottleAlert($store.scope(state: \.destination?.alert, action: \.destination.alert))
.onAppear {
store.send(.onAppear)
}
Expand Down
Loading

0 comments on commit dc507b3

Please sign in to comment.