Skip to content

Commit 16795e5

Browse files
committed
[feat] #211 알림함 안읽음 처리 구성
1 parent ece0601 commit 16795e5

4 files changed

Lines changed: 31 additions & 9 deletions

File tree

Projects/DSKit/Sources/Components/PokitCaution.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public enum CautionType {
6363
case .링크부족:
6464
return "링크를 5개 이상 저장하고 추천을 받아보세요"
6565
case .알림없음:
66-
return "리마인드 알림을 설정하세요"
66+
return "공동 편집 포킷을 만들어보세요"
6767
case .추천_링크없음:
6868
return "다른 사용자들이 링크를 저장하면\n추천해드릴게요"
6969
}

Projects/Domain/Sources/Alert/AlertItem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public struct AlertItem: Identifiable, Equatable {
1515
public var title: String
1616
public var body: String
1717
public let createdAt: String
18-
18+
1919
public init(
2020
id: Int,
2121
userId: Int,
2222
contentId: Int,
23-
thumbNail: String,
23+
thumbNail: String,
2424
title: String,
2525
body: String,
2626
createdAt: String

Projects/Feature/FeatureSetting/Sources/Alert/PokitAlertBoxFeature.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public struct PokitAlertBoxFeature {
2626
public init() {}
2727

2828
fileprivate var domain = Alert()
29-
29+
@Shared(.appStorage("lastAlertCheckDate"))
30+
var lastAlertCheckDate: String?
31+
3032
var alertContents: IdentifiedArrayOf<AlertItem>? {
3133
guard let list = domain.alertList.data else { return nil }
3234
var identifiedArray = IdentifiedArrayOf<AlertItem>()
@@ -134,6 +136,10 @@ private extension PokitAlertBoxFeature {
134136
switch action {
135137
case let .뷰가_나타났을때_알람_목록_조회_API_반영(list):
136138
state.domain.alertList = list
139+
/// 가장 최신 알림의 날짜를 저장 (읽음 처리용)
140+
if let latestAlert = list.data?.first {
141+
state.lastAlertCheckDate = latestAlert.createdAt
142+
}
137143
return .none
138144

139145
case let .pagenation_알람_목록_조회_API_반영(alertList):

Projects/Feature/FeatureSetting/Sources/Alert/PokitAlertBoxView.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ public extension PokitAlertBoxView {
3737
List {
3838
ForEach(alertContents, id: \.id) { item in
3939
Button(action: { send(.알람_항목_선택했을때(item: item)) }) {
40-
AlertContent(item: item)
40+
AlertContent(
41+
item: item,
42+
lastCheckDate: store.lastAlertCheckDate
43+
)
4144
}
4245
.listRowSeparator(.hidden)
4346
.listRowInsets(EdgeInsets())
4447
.onDelete(deleteAction: { delete(item) })
48+
.id(item.id)
4549
}
4650
.listRowBackground(Color.pokit(.bg(.base)))
4751
.padding(.top, 16)
@@ -76,12 +80,19 @@ private extension PokitAlertBoxView {
7680
}
7781

7882
struct AlertContent: View {
79-
var item: AlertItem
80-
81-
init(item: AlertItem) {
83+
let item: AlertItem
84+
let lastCheckDate: String?
85+
86+
init(item: AlertItem, lastCheckDate: String?) {
8287
self.item = item
88+
self.lastCheckDate = lastCheckDate
89+
}
90+
91+
private var isUnread: Bool {
92+
guard let lastCheckDate else { return true }
93+
return item.createdAt > lastCheckDate
8394
}
84-
95+
8596
var body: some View {
8697
VStack(alignment: .leading, spacing: 20) {
8798
HStack(spacing: 16) {
@@ -117,6 +128,11 @@ private extension PokitAlertBoxView {
117128
.foregroundStyle(.pokit(.border(.tertiary)))
118129
}
119130
.padding(.top, 20)
131+
.background(
132+
isUnread
133+
? .pokit(.color(.orange(._50)))
134+
: .clear
135+
)
120136
}
121137
}
122138
}

0 commit comments

Comments
 (0)