-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathResponseToolBar.swift
More file actions
65 lines (54 loc) · 1.93 KB
/
ResponseToolBar.swift
File metadata and controls
65 lines (54 loc) · 1.93 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
import SwiftUI
import ComposableArchitecture
import SharedUIComponents
struct ResponseToolBar: View {
let id: String
let chat: StoreOf<Chat>
let text: String
let message: DisplayedChatMessage
@AppStorage(\.chatFontSize) var chatFontSize
var billingMultiplier: String? {
guard let multiplier = message.billingMultiplier else {
return nil
}
let rounded = (multiplier * 100).rounded() / 100
let formatter = NumberFormatter()
formatter.minimumFractionDigits = 0
formatter.maximumFractionDigits = 2
formatter.numberStyle = .decimal
let formattedMultiplier = formatter.string(from: NSNumber(value: rounded)) ?? "\(rounded)"
return "\(formattedMultiplier)x"
}
var modelNameAndMultiplierText: String? {
guard let modelName = message.modelName else {
return nil
}
var text = modelName
if let billingMultiplier = billingMultiplier {
text += " • \(billingMultiplier)"
}
return text
}
var body: some View {
HStack(spacing: 8) {
if let modelNameAndMultiplierText = modelNameAndMultiplierText {
Text(modelNameAndMultiplierText)
.scaledFont(size: chatFontSize - 1)
.lineLimit(1)
.foregroundColor(.secondary)
.help(modelNameAndMultiplierText)
}
UpvoteButton { rating in
chat.send(.upvote(id, rating))
}
DownvoteButton { rating in
chat.send(.downvote(id, rating))
}
CopyButton {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(text, forType: .string)
chat.send(.copyCode(id))
}
}
}
}