forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserMessage.swift
More file actions
76 lines (68 loc) · 2.07 KB
/
UserMessage.swift
File metadata and controls
76 lines (68 loc) · 2.07 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
import ComposableArchitecture
import Foundation
import MarkdownUI
import SwiftUI
struct UserMessage: View {
var r: Double { messageBubbleCornerRadius }
let id: String
let text: String
let chat: StoreOf<Chat>
@Environment(\.colorScheme) var colorScheme
var body: some View {
ThemedMarkdownText(text)
.frame(alignment: .leading)
.padding()
.background {
RoundedCorners(tl: r, tr: r, bl: r, br: 0)
.fill(Color.userChatContentBackground)
}
.overlay {
RoundedCorners(tl: r, tr: r, bl: r, br: 0)
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
}
.padding(.leading)
.padding(.trailing, 8)
.shadow(color: .black.opacity(0.05), radius: 6)
.frame(maxWidth: .infinity, alignment: .trailing)
.contextMenu {
Button("Copy") {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
}
Button("Send Again") {
chat.send(.resendMessageButtonTapped(id))
}
Button("Set as Extra System Prompt") {
chat.send(.setAsExtraPromptButtonTapped(id))
}
Divider()
Button("Delete") {
chat.send(.deleteMessageButtonTapped(id))
}
}
}
}
#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: .init()) }
)
)
.padding()
.fixedSize(horizontal: true, vertical: true)
}