Skip to content

Commit d7eb334

Browse files
committed
feat: 읽지 않은 알림이면 파란색 점을 보여주고, 받은 시간과의 차를 실시간으로 보여주도록 추가
1 parent fefd3a8 commit d7eb334

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

DevLog/UI/PushNotification/PushNotificationView.swift

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,32 @@ struct PushNotificationView: View {
5959
}
6060

6161
private func notificationRow(_ notification: PushNotification) -> some View {
62-
VStack(alignment: .leading, spacing: 5) {
63-
Text(notification.title)
64-
.font(.headline)
65-
.lineLimit(1)
66-
Text(notification.body)
67-
.font(.subheadline)
68-
.foregroundStyle(Color.gray)
69-
.lineLimit(1)
62+
HStack {
63+
Circle()
64+
.fill(Color.blue)
65+
.frame(width: 8, height: 8)
66+
.opacity(notification.isRead ? 0 : 1)
67+
68+
VStack(alignment: .leading, spacing: 5) {
69+
Text(notification.title)
70+
.font(.headline)
71+
.lineLimit(1)
72+
Text(notification.body)
73+
.font(.subheadline)
74+
.foregroundStyle(Color.gray)
75+
.lineLimit(1)
76+
}
77+
78+
Spacer()
79+
80+
TimelineView(.periodic(from: .now, by: 1.0)) { context in
81+
Text(timeAgoText(from: notification.receivedAt, now: context.date))
82+
.font(.caption2)
83+
.foregroundStyle(Color.gray)
84+
}
7085
}
7186
.padding(.vertical, 5)
87+
.listRowBackground(Color.clear)
7288
.swipeActions(edge: .trailing) {
7389
Button(
7490
role: .destructive,
@@ -80,4 +96,21 @@ struct PushNotificationView: View {
8096
}
8197
}
8298
}
99+
100+
private func timeAgoText(from date: Date, now: Date) -> String {
101+
let seconds = Int(now.timeIntervalSince(date))
102+
103+
if seconds < 60 {
104+
return "\(max(0, seconds))초 전"
105+
} else if seconds < 3600 {
106+
let minutes = seconds / 60
107+
return "\(minutes)분 전"
108+
} else if seconds < 86400 {
109+
let hours = seconds / 3600
110+
return "\(hours)시간 전"
111+
} else {
112+
let days = seconds / 86400
113+
return "\(days)일 전"
114+
}
115+
}
83116
}

0 commit comments

Comments
 (0)