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

[1.0.3] - 페이지네이션 버그 수정 및 개선 #123

Merged
merged 13 commits into from
Sep 17, 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
41 changes: 0 additions & 41 deletions .github/workflows/develop.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Projects/App/Sources/MainTab/MainTabPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public extension MainTabFeature {

/// - 컨텐츠 상세보기 내부 액션 실행
case .contentDetail(.presented(.delegate(.즐겨찾기_갱신_완료))),
.contentDetail(.presented(.delegate(.컨텐츠_조회_완료))):
.contentDetail(.presented(.delegate(.컨텐츠_조회_완료))),
.contentDetail(.presented(.delegate(.컨텐츠_삭제_완료))):
guard let stackElementId = state.path.ids.last,
let lastPath = state.path.last else {
switch state.selectedTab {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public struct CategoryDetailFeature {
case 카테고리_내_컨텐츠_목록_조회
case 컨텐츠_삭제(id: Int)
case pagenation_네트워크
case 페이징_재조회
}

public enum ScopeAction: Equatable {
Expand Down Expand Up @@ -191,7 +192,7 @@ private extension CategoryDetailFeature {
state.domain.contentList.data = nil
state.domain.category = item
return .run { send in
await send(.async(.카테고리_내_컨텐츠_목록_조회))
await send(.inner(.pagenation_초기화))
await send(.inner(.pokitCategorySelectSheetPresented(false)))
}

Expand Down Expand Up @@ -258,7 +259,11 @@ private extension CategoryDetailFeature {
state.kebobSelectedType = nil
return .none
case .pagenation_네트워크_결과(let contentList):
let list = state.domain.contentList.data ?? []
guard let newList = contentList.data else { return .none }

state.domain.contentList = contentList
state.domain.contentList.data = list + newList
return .none
case .pagenation_초기화:
state.domain.pageable.page = 0
Expand Down Expand Up @@ -289,7 +294,11 @@ private extension CategoryDetailFeature {
favorites: condition.isFavoriteFlitered
)
).toDomain()
await send(.inner(.카테고리_내_컨텐츠_목록_갱신(contentList)), animation: .pokitDissolve)
if pageable.page == 0 {
await send(.inner(.카테고리_내_컨텐츠_목록_갱신(contentList)), animation: .pokitDissolve)
} else {
await send(.inner(.pagenation_네트워크_결과(contentList)))
}
}
case .컨텐츠_삭제(id: let id):
return .run { [id] send in
Expand All @@ -299,6 +308,45 @@ private extension CategoryDetailFeature {
case .pagenation_네트워크:
state.domain.pageable.page += 1
return .send(.async(.카테고리_내_컨텐츠_목록_조회))
case .페이징_재조회:
return .run { [
pageable = state.domain.pageable,
categoryId = state.domain.category.id,
condition = state.domain.condition
] send in
let stream = AsyncThrowingStream<BaseContentListInquiry, Error> { continuation in
Task {
for page in 0...pageable.page {
let paeagableRequest = BasePageableRequest(
page: page,
size: pageable.size,
sort: pageable.sort
)
let conditionRequest = BaseConditionRequest(
categoryIds: condition.categoryIds,
isRead: condition.isUnreadFlitered,
favorites: condition.isFavoriteFlitered
)
let contentList = try await contentClient.카테고리_내_컨텐츠_목록_조회(
"\(categoryId)",
paeagableRequest,
conditionRequest
).toDomain()
continuation.yield(contentList)
}
continuation.finish()
}
}
var contentItems: BaseContentListInquiry? = nil
for try await contentList in stream {
let items = contentItems?.data ?? []
let newItems = contentList.data ?? []
contentItems = contentList
contentItems?.data = items + newItems
}
guard let contentItems else { return }
await send(.inner(.카테고리_내_컨텐츠_목록_갱신(contentItems)), animation: .pokitSpring)
}
}
}

Expand Down Expand Up @@ -405,7 +453,7 @@ private extension CategoryDetailFeature {
func handleDelegateAction(_ action: Action.DelegateAction, state: inout State) -> Effect<Action> {
switch action {
case .카테고리_내_컨텐츠_목록_조회:
return .send(.async(.카테고리_내_컨텐츠_목록_조회))
return .send(.async(.페이징_재조회))
default:
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private extension CategoryDetailView {

Spacer()
}
.padding(.bottom, 36)
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public struct ContentDetailFeature {
case editButtonTapped(contentId: Int)
case 즐겨찾기_갱신_완료
case 컨텐츠_조회_완료
case 컨텐츠_삭제_완료
}
}

Expand Down Expand Up @@ -250,8 +251,9 @@ private extension ContentDetailFeature {
await send(.inner(.즐겨찾기_갱신(false)))
}
case .컨텐츠_삭제(id: let id):
return .run { _ in
return .run { send in
try await contentClient.컨텐츠_삭제("\(id)")
await send(.delegate(.컨텐츠_삭제_완료))
await dismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public struct ContentListFeature {
case 컨텐츠_삭제(id: Int)
case pagenation_네트워크
case 컨텐츠_목록_갱신
case 페이징_재조회
}

public enum ScopeAction: Equatable {
Expand Down Expand Up @@ -172,7 +173,7 @@ private extension ContentListFeature {
state.domain.pageable.sort = [
state.isListDescending ? "createdAt,desc" : "createdAt,asc"
]
return .send(.inner(.pagenation_초기화))
return .send(.inner(.pagenation_초기화), animation: .pokitDissolve)
case .backButtonTapped:

return .run { _ in await dismiss() }
Expand Down Expand Up @@ -246,7 +247,10 @@ private extension ContentListFeature {
sort: pageable.sort
)
).toDomain()
await send(.inner(.컨텐츠_목록_조회(contentList)), animation: .pokitDissolve)
await send(
.inner(.컨텐츠_목록_조회(contentList)),
animation: pageable.page == 0 ? .pokitDissolve : nil
)
}
case .즐겨찾기_링크모음_조회:
return .run { [pageable = state.domain.pageable] send in
Expand All @@ -257,23 +261,26 @@ private extension ContentListFeature {
sort: pageable.sort
)
).toDomain()
await send(.inner(.컨텐츠_목록_조회(contentList)), animation: .pokitDissolve)
await send(
.inner(.컨텐츠_목록_조회(contentList)),
animation: pageable.page == 0 ? .pokitDissolve : nil
)
}
case .컨텐츠_삭제(id: let id):
return .run { [id] send in
let _ = try await contentClient.컨텐츠_삭제("\(id)")
await send(.inner(.컨텐츠_삭제_반영(id: id)), animation: .pokitSpring)
}

case .pagenation_네트워크:
state.domain.pageable.page += 1
return .run { [type = state.contentType] send in
switch type {
case .unread:
await send(.async(.읽지않음_컨텐츠_조회), animation: .pokitDissolve)
await send(.async(.읽지않음_컨텐츠_조회))
break
case .favorite:
await send(.async(.즐겨찾기_링크모음_조회), animation: .pokitDissolve)
await send(.async(.즐겨찾기_링크모음_조회))
break
}
}
Expand All @@ -292,7 +299,10 @@ private extension ContentListFeature {
sort: pageable.sort
)
).toDomain()
await send(.inner(.컨텐츠_목록_갱신(contentList)), animation: .pokitSpring)
await send(
.inner(.컨텐츠_목록_갱신(contentList)),
animation: pageable.page == 0 ? .pokitDissolve : nil
)
case .favorite:
let contentList = try await remindClient.즐겨찾기_링크모음_조회(
BasePageableRequest(
Expand All @@ -301,10 +311,52 @@ private extension ContentListFeature {
sort: pageable.sort
)
).toDomain()
await send(.inner(.컨텐츠_목록_갱신(contentList)), animation: .pokitSpring)
await send(
.inner(.컨텐츠_목록_갱신(contentList)),
animation: pageable.page == 0 ? .pokitDissolve : nil
)
}

}
case .페이징_재조회:
return .run { [
pageable = state.domain.pageable,
contentType = state.contentType
] send in
let stream = AsyncThrowingStream<BaseContentListInquiry, Error> { continuation in
Task {
for page in 0...pageable.page {
let paeagableRequest = BasePageableRequest(
page: page,
size: pageable.size,
sort: pageable.sort
)
switch contentType {
case .favorite:
let contentList = try await remindClient.즐겨찾기_링크모음_조회(
paeagableRequest
).toDomain()
continuation.yield(contentList)
case .unread:
let contentList = try await remindClient.읽지않음_컨텐츠_조회(
paeagableRequest
).toDomain()
continuation.yield(contentList)
}
}
continuation.finish()
}
}
var contentItems: BaseContentListInquiry? = nil
for try await contentList in stream {
let items = contentItems?.data ?? []
let newItems = contentList.data ?? []
contentItems = contentList
contentItems?.data = items + newItems
}
guard let contentItems else { return }
await send(.inner(.컨텐츠_목록_갱신(contentItems)), animation: .pokitSpring)
}
}
}

Expand Down Expand Up @@ -332,12 +384,7 @@ private extension ContentListFeature {
func handleDelegateAction(_ action: Action.DelegateAction, state: inout State) -> Effect<Action> {
switch action {
case .컨텐츠_목록_조회:
switch state.contentType {
case .favorite:
return .send(.async(.즐겨찾기_링크모음_조회))
case .unread:
return .send(.async(.읽지않음_컨텐츠_조회))
}
return .send(.async(.페이징_재조회))
default:
return .none
}
Expand Down
Loading