Skip to content

Commit f23cdff

Browse files
ShapeKim98stealmh
authored andcommitted
[fix] #120 컨텐츠 목록 개수 표시 오류 수정
1 parent 4668347 commit f23cdff

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

Projects/CoreKit/Sources/Data/DTO/Content/ContentCountResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import Foundation
99

1010
public struct BookmarkCountResponse: Decodable {
11-
let count: Int
11+
public let count: Int
1212
}
1313

1414
public struct UnreadCountResponse: Decodable {
15-
let count: Int
15+
public let count: Int
1616
}
1717

1818
extension UnreadCountResponse {

Projects/Domain/Sources/ContentList/ContentList.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public struct ContentList: Equatable {
1212
/// 콘텐츠 목록
1313
public var contentList: BaseContentListInquiry
1414
public var pageable: BasePageable
15+
public var contentCount: Int
1516

1617
public init() {
1718
self.contentList = .init(
@@ -24,5 +25,6 @@ public struct ContentList: Equatable {
2425
page: 0, size: 10,
2526
sort: ["createdAt,desc"]
2627
)
28+
self.contentCount = 0
2729
}
2830
}

Projects/Feature/FeatureContentList/Sources/ContentList/ContentListFeature.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public struct ContentListFeature {
4040
contentList.forEach { identifiedArray.append($0) }
4141
return identifiedArray
4242
}
43+
var contentCount: Int {
44+
get { domain.contentCount }
45+
}
4346
var isListDescending = true
4447
/// sheet item
4548
var bottomSheetItem: BaseContentItem? = nil
@@ -87,15 +90,16 @@ public struct ContentListFeature {
8790
case pagenation_네트워크_결과(BaseContentListInquiry)
8891
case pagenation_초기화
8992
case 컨텐츠_목록_갱신(BaseContentListInquiry)
93+
case 컨텐츠_개수_갱신(Int)
9094
}
9195

9296
public enum AsyncAction: Equatable {
9397
case 읽지않음_컨텐츠_조회
9498
case 즐겨찾기_링크모음_조회
9599
case 컨텐츠_삭제(id: Int)
96100
case pagenation_네트워크
97-
case 컨텐츠_목록_갱신
98101
case 페이징_재조회
102+
case 컨텐츠_개수_조회
99103
}
100104

101105
public enum ScopeAction: Equatable {
@@ -175,7 +179,6 @@ private extension ContentListFeature {
175179
]
176180
return .send(.inner(.pagenation_초기화), animation: .pokitDissolve)
177181
case .backButtonTapped:
178-
179182
return .run { _ in await dismiss() }
180183
case .contentListViewOnAppeared:
181184
return .run { [type = state.contentType] send in
@@ -193,7 +196,7 @@ private extension ContentListFeature {
193196
}
194197

195198
case .pagenation:
196-
return .run { send in await send(.async(.pagenation_네트워크)) }
199+
return .send(.async(.pagenation_네트워크))
197200
case .링크_공유_완료:
198201
state.shareSheetItem = nil
199202
return .none
@@ -232,6 +235,9 @@ private extension ContentListFeature {
232235
case let .컨텐츠_목록_갱신(contentList):
233236
state.domain.contentList = contentList
234237
return .none
238+
case let .컨텐츠_개수_갱신(count):
239+
state.domain.contentCount = count
240+
return .none
235241
}
236242
}
237243

@@ -240,6 +246,7 @@ private extension ContentListFeature {
240246
switch action {
241247
case .읽지않음_컨텐츠_조회:
242248
return .run { [pageable = state.domain.pageable] send in
249+
await send(.async(.컨텐츠_개수_조회))
243250
let contentList = try await remindClient.읽지않음_컨텐츠_조회(
244251
BasePageableRequest(
245252
page: pageable.page,
@@ -254,6 +261,7 @@ private extension ContentListFeature {
254261
}
255262
case .즐겨찾기_링크모음_조회:
256263
return .run { [pageable = state.domain.pageable] send in
264+
await send(.async(.컨텐츠_개수_조회))
257265
let contentList = try await remindClient.즐겨찾기_링크모음_조회(
258266
BasePageableRequest(
259267
page: pageable.page,
@@ -267,7 +275,9 @@ private extension ContentListFeature {
267275
)
268276
}
269277
case .컨텐츠_삭제(id: let id):
270-
return .run { [id] send in
278+
return .run { [count = state.domain.contentCount] send in
279+
let newCount = count - 1
280+
await send(.inner(.컨텐츠_개수_갱신(newCount)), animation: .pokitSpring)
271281
let _ = try await contentClient.컨텐츠_삭제("\(id)")
272282
await send(.inner(.컨텐츠_삭제_반영(id: id)), animation: .pokitSpring)
273283
}
@@ -323,6 +333,7 @@ private extension ContentListFeature {
323333
pageable = state.domain.pageable,
324334
contentType = state.contentType
325335
] send in
336+
await send(.async(.컨텐츠_개수_조회))
326337
let stream = AsyncThrowingStream<BaseContentListInquiry, Error> { continuation in
327338
Task {
328339
for page in 0...pageable.page {
@@ -357,6 +368,17 @@ private extension ContentListFeature {
357368
guard let contentItems else { return }
358369
await send(.inner(.컨텐츠_목록_갱신(contentItems)), animation: .pokitSpring)
359370
}
371+
case .컨텐츠_개수_조회:
372+
return .run { [ contentType = state.contentType ] send in
373+
switch contentType {
374+
case .favorite:
375+
let count = try await remindClient.즐겨찾기_컨텐츠_개수_조회().count
376+
await send(.inner(.컨텐츠_개수_갱신(count)), animation: .pokitSpring)
377+
case .unread:
378+
let count = try await remindClient.읽지않음_컨텐츠_개수_조회().count
379+
await send(.inner(.컨텐츠_개수_갱신(count)), animation: .pokitSpring)
380+
}
381+
}
360382
}
361383
}
362384

Projects/Feature/FeatureContentList/Sources/ContentList/ContentListView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public extension ContentListView {
6666
private extension ContentListView {
6767
var listHeader: some View {
6868
HStack {
69-
Text("링크 \(store.contents?.count ?? 0)")
69+
Text("링크 \(store.contentCount)")
7070
.pokitFont(.detail1)
7171
.foregroundStyle(.pokit(.text(.secondary)))
7272
.contentTransition(.numericText())

0 commit comments

Comments
 (0)