Repository navigation
Expand file tree
/
Copy pathHistoryView.swift
More file actions
105 lines (97 loc) · 4.26 KB
/
Copy pathHistoryView.swift
File metadata and controls
105 lines (97 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import SwiftUI
/// Cache / history backed by SQLite: searchable, sortable, and paged (show N,
/// load more) so it stays usable as it grows — the full set is reachable via
/// search/sort without loading or rendering everything at once.
struct HistoryView: View {
@EnvironmentObject var app: AppState
@State private var search = ""
@State private var sort: HistorySort = .recent
@State private var limit = 50
@State private var results: [HistoryEntry] = []
@State private var total = 0
private let page = 50
var body: some View {
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("히스토리").font(.headline)
Text(countLabel).font(.caption).foregroundStyle(.secondary)
Spacer()
Picker("정렬", selection: $sort) {
ForEach(HistorySort.allCases) { Text($0.label).tag($0) }
}
.controlSize(.small).fixedSize()
Button(role: .destructive) { app.clearHistory() } label: {
Label("전체 삭제", systemImage: "trash")
}
.controlSize(.small).disabled(total == 0)
}
HStack(spacing: 6) {
Image(systemName: "magnifyingglass").foregroundStyle(.secondary)
TextField("검색 (본문·보이스)", text: $search).textFieldStyle(.plain)
if !search.isEmpty {
Button { search = "" } label: { Image(systemName: "xmark.circle.fill") }
.buttonStyle(.plain).foregroundStyle(.tertiary)
}
}
.padding(6).background(Color.secondary.opacity(0.08)).cornerRadius(6)
if total == 0 {
emptyState(search.isEmpty ? "아직 생성 기록이 없습니다." : "검색 결과가 없습니다.")
} else {
List {
ForEach(results) { row($0) }
if results.count < total {
HStack {
Spacer()
Button("더 보기 (+\(min(page, total - results.count)))") {
limit = results.count + page; reload()
}
Button("모두 표시 (\(total))") { limit = total; reload() }
.foregroundStyle(.secondary)
Spacer()
}
.padding(.vertical, 4)
}
}
}
}
.padding()
.onAppear(perform: reload)
.onChange(of: app.historyRevision) { _, _ in reload() }
.onChange(of: sort) { _, _ in reload() }
.onChange(of: search) { _, _ in limit = page; reload() }
}
private func reload() {
total = app.historyTotal(search: search)
results = app.historyPage(search: search, sort: sort, limit: limit, offset: 0)
}
private var countLabel: String {
if search.isEmpty {
return results.count < total ? "· 전체 \(total)개 중 \(results.count)개 표시" : "· \(total)개"
}
return "· 검색 \(total)개 중 \(results.count)개 표시"
}
@ViewBuilder private func emptyState(_ text: String) -> some View {
Spacer()
Text(text).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .center)
Spacer()
}
@ViewBuilder private func row(_ e: HistoryEntry) -> some View {
HStack(alignment: .top) {
VStack(alignment: .leading, spacing: 2) {
Text(e.text).lineLimit(2)
Text("\(e.voiceName) · \(e.modelId) · "
+ e.createdAt.formatted(date: .abbreviated, time: .shortened)
+ " · \(e.bytes / 1024)KB")
.font(.caption).foregroundStyle(.secondary)
}
Spacer()
Button { app.replay(e) } label: { Image(systemName: "play.circle") }
.buttonStyle(.borderless).help("재생")
Button(role: .destructive) { app.deleteHistory(e.id) } label: {
Image(systemName: "trash")
}
.buttonStyle(.borderless).help("삭제")
}
.padding(.vertical, 2)
}
}