Skip to content

Commit

Permalink
[FIX] 불필요 변수 삭제 및 로직 변경 및 NoticeEmptyView 임시 구현 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ILWAT committed Nov 9, 2024
1 parent 8a6b61f commit 08ad772
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
22 changes: 13 additions & 9 deletions Projects/Feature/Scene/Setting/Notice/NoticeFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
Expand Down
36 changes: 29 additions & 7 deletions Projects/Feature/Scene/Setting/Notice/NoticeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import ComposableArchitecture


public struct NoticeView: View {
@Environment(\.dismiss) private var dismiss

public let store: StoreOf<NoticeFeature>
@Perception.Bindable public var store: StoreOf<NoticeFeature>

public var body: some View {
WithPerceptionTracking {
Expand All @@ -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<NoticeFeature>

var body: some View {
WithPerceptionTracking {
ScrollView(.vertical) {
LazyVStack {
ForEach(store.noticeList) { notice in
Expand Down Expand Up @@ -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)
}
}


Expand Down
2 changes: 0 additions & 2 deletions Projects/Feature/Scene/Setting/View/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import Common
import ComposableArchitecture

public struct SettingView: View {
@Environment(\.dismiss) private var dismiss

@Perception.Bindable var store: StoreOf<SettingFeature>

public var body: some View {
Expand Down

0 comments on commit 08ad772

Please sign in to comment.