diff --git a/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift b/Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift index 595c4d24..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,14 +48,24 @@ public struct NoticeFeature { return .run { _ in await self.dismiss() } case .fetchNotice: + 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): - state.noticeList.append(contentsOf: noticeData) - state.nextPage += 1 + 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): diff --git a/Projects/Feature/Scene/Setting/Notice/NoticeView.swift b/Projects/Feature/Scene/Setting/Notice/NoticeView.swift index 23e14aeb..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 { @@ -24,7 +22,24 @@ public struct NoticeView: View { leadingType: .dismiss("공지사항", { store.send(.tappedNaviBackButton) }), 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 @@ -78,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 {