Skip to content

Commit

Permalink
[refactor] #129 CategorySharingFeature 액션 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
stealmh committed Oct 20, 2024
1 parent 4b2482e commit 3bc78c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ public struct CategorySharingFeature {
@ObservableState
public struct State: Equatable {
fileprivate var domain: CategorySharing
var category: CategorySharing.Category {
get { domain.sharedCategory.category }
}
var category: CategorySharing.Category { domain.sharedCategory.category }
var contents: IdentifiedArrayOf<CategorySharing.Content>? {
var identifiedArray = IdentifiedArrayOf<CategorySharing.Content>()
domain.sharedCategory.contentList.data.forEach { content in
identifiedArray.append(content)
}
return identifiedArray
}
var hasNext: Bool {
get { domain.sharedCategory.contentList.hasNext }
}
var hasNext: Bool { domain.sharedCategory.contentList.hasNext }
var error: BaseError?
var isErrorSheetPresented: Bool = false

Expand All @@ -63,27 +59,26 @@ public struct CategorySharingFeature {

@CasePathable
public enum View: Equatable, BindableAction {
case 저장버튼_클릭
case 컨텐츠_아이템_클릭(CategorySharing.Content)
case 뒤로가기버튼_클릭
case 경고_확인버튼_클릭

case 다음페이지_로딩_onAppear

case binding(BindingAction<State>)
case dismiss

case 저장_버튼_눌렀을때
case 컨텐츠_항목_눌렀을때(CategorySharing.Content)
case 경고_확인버튼_눌렀을때
case 페이지_로딩중일때
}

public enum InnerAction: Equatable {
case 공유받은_카테고리_갱신(CategorySharing.SharedCategory)
case 공유받은_카테고리_API_반영(CategorySharing.SharedCategory)
case 경고_닫음
case 경고_띄움(BaseError)
}

public enum AsyncAction: Equatable {
case 공유받은_카테고리_조회
case 공유받은_카테고리_조회_API
}

public enum ScopeAction: Equatable { case doNothing }
public enum ScopeAction: Equatable { case 없음 }

public enum DelegateAction: Equatable {
case 컨텐츠_아이템_클릭(categoryId: Int, content: CategorySharing.Content)
Expand Down Expand Up @@ -130,32 +125,39 @@ private extension CategorySharingFeature {
/// - View Effect
func handleViewAction(_ action: Action.View, state: inout State) -> Effect<Action> {
switch action {
case .저장버튼_클릭:
case .binding:
return .none

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

case .저장_버튼_눌렀을때:
let sharedCategory = state.domain.sharedCategory.category
return .send(.delegate(.공유받은_카테고리_추가(sharedCategory: sharedCategory)))
case let .컨텐츠_아이템_클릭(content):

case let .컨텐츠_항목_눌렀을때(content):
return .send(.delegate(.컨텐츠_아이템_클릭(categoryId: state.category.categoryId , content: content)))
case .뒤로가기버튼_클릭:
return .run { _ in await dismiss() }
case .경고_확인버튼_클릭:
return .none
case .binding:

case .경고_확인버튼_눌렀을때:
return .none
case .다음페이지_로딩_onAppear:
return .send(.async(.공유받은_카테고리_조회))

case .페이지_로딩중일때:
return .send(.async(.공유받은_카테고리_조회_API))
}
}

/// - Inner Effect
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
switch action {
case let .공유받은_카테고리_갱신(sharedCategory):
case let .공유받은_카테고리_API_반영(sharedCategory):
state.domain.sharedCategory = sharedCategory
return .none

case let .경고_띄움(baseError):
state.error = baseError
state.isErrorSheetPresented = true
return .none

case .경고_닫음:
state.isErrorSheetPresented = false
state.error = nil
Expand All @@ -166,21 +168,18 @@ private extension CategorySharingFeature {
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .공유받은_카테고리_조회:
case .공유받은_카테고리_조회_API:
state.domain.pageable.page += 1
return .run { [
categoryId = state.domain.sharedCategory.category.categoryId,
pageable = state.domain.pageable
] send in
let request = BasePageableRequest(page: pageable.page, size: pageable.size, sort: pageable.sort)
let sharedCategory = try await categoryClient.공유받은_카테고리_조회(
"\(categoryId)",
BasePageableRequest(
page: pageable.page,
size: pageable.size,
sort: pageable.sort
)
request
).toDomain()
await send(.inner(.공유받은_카테고리_갱신(sharedCategory)), animation: .pokitDissolve)
await send(.inner(.공유받은_카테고리_API_반영(sharedCategory)), animation: .pokitDissolve)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public extension CategorySharingView {
store.error?.title ?? "에러",
message: store.error?.message,
confirmText: "확인",
action: { send(.경고_확인버튼_클릭) }
action: { send(.경고_확인버튼_눌렀을때) }
)
}
}
Expand All @@ -52,7 +52,7 @@ private extension CategorySharingView {
PokitHeaderItems(placement: .leading) {
PokitToolbarButton(
.icon(.arrowLeft),
action: { send(.뒤로가기버튼_클릭) }
action: { send(.dismiss) }
)
}
}
Expand All @@ -79,7 +79,7 @@ private extension CategorySharingView {
state: .filled(.primary),
size: .medium,
shape: .rectangle,
action: { send(.저장버튼_클릭) }
action: { send(.저장_버튼_눌렀을때) }
)
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ private extension CategorySharingView {

PokitLinkCard(
link: content,
action: { send(.컨텐츠_아이템_클릭(content)) }
action: { send(.컨텐츠_항목_눌렀을때(content)) }
)
.divider(isFirst: isFirst, isLast: isLast)
.pokitScrollTransition(.opacity)
Expand All @@ -116,7 +116,7 @@ private extension CategorySharingView {
if store.hasNext {
PokitLoading()
.padding(.top, 12)
.onAppear { send(.다음페이지_로딩_onAppear) }
.onAppear { send(.페이지_로딩중일때) }
}
}
}
Expand Down

0 comments on commit 3bc78c4

Please sign in to comment.