Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: CategorySharingFeature 액션 수정 #150

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get을 뺀 이유가 궁금합니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computed에서 명시적으로 사용하지 않아도 한줄은 당연히 get로 인식이 되는게 익숙해서 뺐읍니다

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
Loading