-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathConversationProgressStepView.swift
More file actions
73 lines (62 loc) · 2.24 KB
/
ConversationProgressStepView.swift
File metadata and controls
73 lines (62 loc) · 2.24 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
import SwiftUI
import ConversationServiceProvider
import ComposableArchitecture
import Combine
struct ProgressStep: View {
let steps: [ConversationProgressStep]
var body: some View {
WithPerceptionTracking {
VStack(alignment: .leading, spacing: 4) {
ForEach(steps) { StatusItemView(step: $0) }
}
.foregroundStyle(.secondary)
}
}
}
struct StatusItemView: View {
let step: ConversationProgressStep
@AppStorage(\.chatFontSize) var chatFontSize
var statusIcon: some View {
Group {
switch step.status {
case .running:
ProgressView()
.controlSize(.small)
.scaleEffect(0.7)
case .completed:
Image(systemName: "checkmark")
.foregroundColor(.green.opacity(0.5))
case .failed:
Image(systemName: "xmark.circle")
.foregroundColor(.red.opacity(0.5))
case .cancelled:
Image(systemName: "slash.circle")
.foregroundColor(.gray.opacity(0.5))
}
}
}
var body: some View {
WithPerceptionTracking {
HStack(spacing: 4) {
statusIcon
.frame(width: 16, height: 16)
Text(step.title)
.font(.system(size: chatFontSize))
.lineLimit(1)
Spacer()
}
}
}
}
struct ProgressStep_Preview: PreviewProvider {
static let steps: [ConversationProgressStep] = [
.init(id: "001", title: "running step", description: "this is running step", status: .running, error: nil),
.init(id: "002", title: "completed step", description: "this is completed step", status: .completed, error: nil),
.init(id: "003", title: "failed step", description: "this is failed step", status: .failed, error: nil),
.init(id: "004", title: "cancelled step", description: "this is cancelled step", status: .cancelled, error: nil)
]
static var previews: some View {
ProgressStep(steps: steps)
.frame(width: 300, height: 300)
}
}