From 8a6b61f7d363d7b31f0a7c8f97972ce67d300224 Mon Sep 17 00:00:00 2001 From: "J.H. Moon" Date: Wed, 6 Nov 2024 03:05:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[BUG]=20=EA=B3=B5=EC=A7=80=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=B7=B0=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD=20Empty=EC=8B=9C=20Empty?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=9E=84=EC=8B=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#135)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scene/Setting/Notice/NoticeFeature.swift | 14 ++++++++++++-- .../Feature/Scene/Setting/Notice/NoticeView.swift | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift b/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift index 595c4d24..d901cdd1 100644 --- a/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift +++ b/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift @@ -44,14 +44,24 @@ public struct NoticeFeature { return .run { _ in await self.dismiss() } case .fetchNotice: + guard state.nextPage > -1 else { return .none } + return .run { [page = state.nextPage, size = state.size] send in let response = try await noticeClient.getNotice(page, size) return await send(.setNoticeData(response)) } case let .setNoticeData(noticeData): - state.noticeList.append(contentsOf: noticeData) - state.nextPage += 1 + if noticeData.isEmpty { + if state.nextPage == 0 { + let emptyNotice = NoticeModel(date: "Blink", title: "공지사항이 없어요", content: "아직 공지사항이 없어요!") + state.noticeList.append(emptyNotice) + } + state.nextPage = -1 + } else { + state.noticeList.append(contentsOf: noticeData) + state.nextPage += 1 + } return .none case let .expanding(target): diff --git a/Projects/Feature/Scene/Setting/Notice/NoticeView.swift b/Projects/Feature/Scene/Setting/Notice/NoticeView.swift index 23e14aeb..1f75cf0c 100644 --- a/Projects/Feature/Scene/Setting/Notice/NoticeView.swift +++ b/Projects/Feature/Scene/Setting/Notice/NoticeView.swift @@ -24,6 +24,7 @@ public struct NoticeView: View { leadingType: .dismiss("공지사항", { store.send(.tappedNaviBackButton) }), trailingType: .none ) + .padding(.leading, 16) ScrollView(.vertical) { LazyVStack { From 08ad77284dd799ee32b116e7c8c7c28f06571a7f Mon Sep 17 00:00:00 2001 From: "J.H. Moon" Date: Sun, 10 Nov 2024 03:51:17 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FIX]=20=EB=B6=88=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20NoticeEmptyView=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=20=EA=B5=AC=ED=98=84=20(#139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scene/Setting/Notice/NoticeFeature.swift | 22 +++++++----- .../Scene/Setting/Notice/NoticeView.swift | 36 +++++++++++++++---- .../Scene/Setting/View/SettingView.swift | 2 -- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift b/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift index d901cdd1..50ed70eb 100644 --- a/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift +++ b/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift @@ -20,6 +20,7 @@ public struct NoticeFeature { var noticeList: [NoticeModel] = [] var nextPage: Int = 0 var size: Int = 10 + var existNotFetchedNotice: Bool = true } public enum Action { @@ -28,6 +29,9 @@ public struct NoticeFeature { case setNoticeData(_ noticeData: [NoticeModel]) case expanding(target: UUID?) + //MARK: Business Logic + case isExistNextPage(Int) + //MARK: User Action case tappedNaviBackButton } @@ -44,26 +48,26 @@ public struct NoticeFeature { return .run { _ in await self.dismiss() } case .fetchNotice: - guard state.nextPage > -1 else { return .none } + guard state.existNotFetchedNotice else { return .none } return .run { [page = state.nextPage, size = state.size] send in let response = try await noticeClient.getNotice(page, size) - return await send(.setNoticeData(response)) + await send(.setNoticeData(response)) + await send(.isExistNextPage(response.count)) } case let .setNoticeData(noticeData): - if noticeData.isEmpty { - if state.nextPage == 0 { - let emptyNotice = NoticeModel(date: "Blink", title: "공지사항이 없어요", content: "아직 공지사항이 없어요!") - state.noticeList.append(emptyNotice) - } - state.nextPage = -1 - } else { + if !noticeData.isEmpty { state.noticeList.append(contentsOf: noticeData) state.nextPage += 1 } return .none + case let .isExistNextPage(fetchedNoticeCount): + let isExistNextPage = (fetchedNoticeCount >= state.size) + state.existNotFetchedNotice = isExistNextPage + return .none + case let .expanding(target): state.expandedNoticeID = target return .none diff --git a/Projects/Feature/Scene/Setting/Notice/NoticeView.swift b/Projects/Feature/Scene/Setting/Notice/NoticeView.swift index 1f75cf0c..847aa786 100644 --- a/Projects/Feature/Scene/Setting/Notice/NoticeView.swift +++ b/Projects/Feature/Scene/Setting/Notice/NoticeView.swift @@ -14,9 +14,7 @@ import ComposableArchitecture public struct NoticeView: View { - @Environment(\.dismiss) private var dismiss - - public let store: StoreOf + @Perception.Bindable public var store: StoreOf public var body: some View { WithPerceptionTracking { @@ -25,7 +23,23 @@ public struct NoticeView: View { trailingType: .none ) .padding(.leading, 16) - + .navigationBarBackButtonHidden(true) + + if store.existNotFetchedNotice || !store.noticeList.isEmpty { + NoticeContentView(store: store) + } else { + NoticeEmptyView() + } +// + } + }// body +} + +fileprivate struct NoticeContentView: View { + @Perception.Bindable fileprivate var store: StoreOf + + var body: some View { + WithPerceptionTracking { ScrollView(.vertical) { LazyVStack { ForEach(store.noticeList) { notice in @@ -79,10 +93,18 @@ public struct NoticeView: View { .onAppear(perform: { store.send(.fetchNotice) }) //onAppear - - .navigationBarBackButtonHidden(true) } - }// body + }//Body +} + +fileprivate struct NoticeEmptyView: View { + + var body: some View { + VStack{ + EmptyView() + } + .frame(maxHeight: .infinity) + } } diff --git a/Projects/Feature/Scene/Setting/View/SettingView.swift b/Projects/Feature/Scene/Setting/View/SettingView.swift index 7d85f6c4..aa002b23 100644 --- a/Projects/Feature/Scene/Setting/View/SettingView.swift +++ b/Projects/Feature/Scene/Setting/View/SettingView.swift @@ -14,8 +14,6 @@ import Common import ComposableArchitecture public struct SettingView: View { - @Environment(\.dismiss) private var dismiss - @Perception.Bindable var store: StoreOf public var body: some View {