forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserMessage.swift
More file actions
82 lines (73 loc) · 2.21 KB
/
UserMessage.swift
File metadata and controls
82 lines (73 loc) · 2.21 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
import ComposableArchitecture
import ChatService
import Foundation
import MarkdownUI
import SharedUIComponents
import SwiftUI
import Status
import Cache
struct UserMessage: View {
var r: Double { messageBubbleCornerRadius }
let id: String
let text: String
let chat: StoreOf<Chat>
@Environment(\.colorScheme) var colorScheme
@ObservedObject private var statusObserver = StatusObserver.shared
struct AvatarView: View {
@ObservedObject private var avatarViewModel = AvatarViewModel.shared
var body: some View {
if let avatarImage = avatarViewModel.avatarImage {
avatarImage
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 24, height: 24)
.clipShape(Circle())
} else {
Image(systemName: "person.circle")
.resizable()
.frame(width: 24, height: 24)
}
}
}
var body: some View {
HStack {
VStack(alignment: .leading, spacing: 8) {
HStack(spacing: 4) {
AvatarView()
Text(statusObserver.authStatus.username ?? "")
.chatMessageHeaderTextStyle()
.padding(2)
Spacer()
}
ThemedMarkdownText(text: text, chat: chat)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.shadow(color: .black.opacity(0.05), radius: 6)
}
}
#Preview {
UserMessage(
id: "A",
text: #"""
Please buy me a coffee!
| Coffee | Milk |
|--------|------|
| Espresso | No |
| Latte | Yes |
```swift
func foo() {}
```
```objectivec
- (void)bar {}
```
"""#,
chat: .init(
initialState: .init(history: [] as [DisplayedChatMessage], isReceivingMessage: false),
reducer: { Chat(service: ChatService.service()) }
)
)
.padding()
.fixedSize(horizontal: true, vertical: true)
.background(Color.yellow)
}