Skip to content

Commit ab20600

Browse files
committed
feat: row에 상시 최근 업데이트 시간을 뜨도록 추가
1 parent 2fb2977 commit ab20600

3 files changed

Lines changed: 42 additions & 23 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// RelativeTimeText.swift
3+
// DevLog
4+
//
5+
// Created by opfic on 3/25/26.
6+
//
7+
8+
import SwiftUI
9+
10+
struct RelativeTimeText: View {
11+
let date: Date
12+
var bodyFont: Font = .caption2
13+
var bodyColor: Color = .gray
14+
15+
var body: some View {
16+
TimelineView(.periodic(from: .now, by: 1.0)) { context in
17+
Text(relativeTimeText(from: date, now: context.date) + " 업데이트")
18+
.font(bodyFont)
19+
.foregroundStyle(bodyColor)
20+
}
21+
}
22+
23+
private func relativeTimeText(from date: Date, now: Date) -> String {
24+
let seconds = Int(now.timeIntervalSince(date))
25+
26+
if seconds < 60 {
27+
return "\(max(0, seconds))초 전"
28+
} else if seconds < 3600 {
29+
let minutes = seconds / 60
30+
return "\(minutes)분 전"
31+
} else if seconds < 86400 {
32+
let hours = seconds / 3600
33+
return "\(hours)시간 전"
34+
} else {
35+
let days = seconds / 86400
36+
return "\(days)일 전"
37+
}
38+
}
39+
}

DevLog/UI/Common/Component/TodoItemRow.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct TodoItemRow: View {
3939
.fixedSize(horizontal: true, vertical: false)
4040
}
4141
}
42+
RelativeTimeText(date: item.updatedAt)
4243
if !item.tags.isEmpty {
4344
TagList(item.tags, lineLimit: 1)
4445
}
@@ -48,6 +49,6 @@ struct TodoItemRow: View {
4849
.font(.caption2.bold())
4950
.foregroundStyle(.gray)
5051
}
51-
.padding(.vertical, item.tags.isEmpty ? 20 : 4)
52+
.padding(.vertical, 8)
5253
}
5354
}

DevLog/UI/Home/HomeView.swift

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,7 @@ private struct RecentTodoRow: View {
408408
.font(.caption.weight(.semibold))
409409
.foregroundStyle(todo.kind.color)
410410

411-
TimelineView(.periodic(from: .now, by: 1.0)) { context in
412-
Text(timeAgoText(from: todo.updatedAt, now: context.date))
413-
.font(.caption2)
414-
.foregroundStyle(Color.gray)
415-
}
411+
RelativeTimeText(date: todo.updatedAt)
416412
}
417413

418414
if !todo.tags.isEmpty {
@@ -421,21 +417,4 @@ private struct RecentTodoRow: View {
421417
}
422418
}
423419
}
424-
425-
private func timeAgoText(from date: Date, now: Date) -> String {
426-
let seconds = Int(now.timeIntervalSince(date))
427-
428-
if seconds < 60 {
429-
return "\(max(0, seconds))초 전"
430-
} else if seconds < 3600 {
431-
let minutes = seconds / 60
432-
return "\(minutes)분 전"
433-
} else if seconds < 86400 {
434-
let hours = seconds / 3600
435-
return "\(hours)시간 전"
436-
} else {
437-
let days = seconds / 86400
438-
return "\(days)일 전"
439-
}
440-
}
441420
}

0 commit comments

Comments
 (0)