Skip to content

Commit 495e03d

Browse files
authored
[#311] TodoListView에서 제목만 있을 경우 UI를 개선한다 (#315)
* feat: row에 상시 최근 업데이트 시간을 뜨도록 추가 * ui: 완료 여부 ui를 상시 보여주도록 수정 * ui: 중요 표시 UI 이동
1 parent 2fb2977 commit 495e03d

3 files changed

Lines changed: 56 additions & 34 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: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99

1010
struct TodoItemRow: View {
11+
@Environment(\.sceneWidth) private var sceneWidth
1112
private let item: TodoListItem
1213

1314
init(_ item: TodoListItem) {
@@ -16,18 +17,12 @@ struct TodoItemRow: View {
1617

1718
var body: some View {
1819
HStack {
19-
VStack(alignment: .leading, spacing: 5) {
20+
Image(systemName: "checkmark.circle")
21+
.resizable()
22+
.frame(width: sceneWidth * 0.08, height: sceneWidth * 0.08)
23+
.foregroundStyle(item.isCompleted ? .green : .secondary)
24+
VStack(alignment: .leading, spacing: 0) {
2025
HStack {
21-
if item.isPinned {
22-
Image(systemName: "star.fill")
23-
.font(.headline)
24-
.foregroundStyle(.orange)
25-
}
26-
if item.isCompleted {
27-
Image(systemName: "checkmark.circle.fill")
28-
.font(.headline)
29-
.foregroundStyle(.green)
30-
}
3126
Text(item.title)
3227
.font(.headline)
3328
.foregroundStyle(Color(.label))
@@ -39,6 +34,15 @@ struct TodoItemRow: View {
3934
.fixedSize(horizontal: true, vertical: false)
4035
}
4136
}
37+
HStack(spacing: 4) {
38+
if item.isPinned {
39+
Image(systemName: "star.fill")
40+
.font(.headline)
41+
.foregroundStyle(.orange)
42+
}
43+
RelativeTimeText(date: item.updatedAt)
44+
}
45+
.frame(height: UIFont.preferredFont(forTextStyle: .headline).lineHeight)
4246
if !item.tags.isEmpty {
4347
TagList(item.tags, lineLimit: 1)
4448
}
@@ -48,6 +52,6 @@ struct TodoItemRow: View {
4852
.font(.caption2.bold())
4953
.foregroundStyle(.gray)
5054
}
51-
.padding(.vertical, item.tags.isEmpty ? 20 : 4)
55+
.padding(.vertical, 12)
5256
}
5357
}

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)