Skip to content

Commit c674551

Browse files
committed
Add icons to chat tab
1 parent 6cfab90 commit c674551

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

Core/Sources/ChatGPTChatTab/ChatGPTChatTab.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public class ChatGPTChatTab: ChatTab {
4646
ChatTabItemView(chat: chat)
4747
}
4848

49+
public func buildIcon() -> any View {
50+
WithViewStore(chat, observe: \.isReceivingMessage) { viewStore in
51+
if viewStore.state {
52+
Image(systemName: "ellipsis.message")
53+
} else {
54+
Image(systemName: "message")
55+
}
56+
}
57+
}
58+
4959
public func buildMenu() -> any View {
5060
ChatContextMenu(store: chat.scope(state: \.chatMenu, action: Chat.Action.chatMenu))
5161
}
@@ -125,3 +135,4 @@ public class ChatGPTChatTab: ChatTab {
125135
}.store(in: &cancellable)
126136
}
127137
}
138+

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ struct ChatTabBar: View {
177177
store: store,
178178
info: info,
179179
content: { tab.tabItem },
180+
icon: { tab.icon },
180181
isSelected: info.id == viewStore.state.selectedTabId
181182
)
182183
.contextMenu {
@@ -280,7 +281,7 @@ struct ChatTabBarDropDelegate: DropDelegate {
280281
let tabs: IdentifiedArray<String, ChatTabInfo>
281282
let itemId: String
282283
@Binding var draggingTabId: String?
283-
284+
284285
func dropUpdated(info: DropInfo) -> DropProposal? {
285286
return DropProposal(operation: .move)
286287
}
@@ -299,20 +300,24 @@ struct ChatTabBarDropDelegate: DropDelegate {
299300
}
300301
}
301302

302-
struct ChatTabBarButton<Content: View>: View {
303+
struct ChatTabBarButton<Content: View, Icon: View>: View {
303304
let store: StoreOf<ChatPanelFeature>
304305
let info: ChatTabInfo
305306
let content: () -> Content
307+
let icon: () -> Icon
306308
let isSelected: Bool
307309
@State var isHovered: Bool = false
308310

309311
var body: some View {
310312
HStack(spacing: 0) {
311-
content()
313+
HStack(spacing: 4) {
314+
icon().foregroundColor(.secondary)
315+
content()
316+
}
312317
.font(.callout)
313318
.lineLimit(1)
314319
.frame(maxWidth: 120)
315-
.padding(.horizontal, 32)
320+
.padding(.horizontal, 28)
316321
.contentShape(Rectangle())
317322
.onTapGesture {
318323
store.send(.tabClicked(id: info.id))

Pro

Submodule Pro updated from 691ee9a to c0e446d

Tool/Sources/ChatTab/ChatTab.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public protocol ChatTabType {
2626
/// Build the tabItem for this chat tab.
2727
@ViewBuilder
2828
func buildTabItem() -> any View
29+
/// Build the icon for this chat tab.
30+
@ViewBuilder
31+
func buildIcon() -> any View
2932
/// Build the menu for this chat tab.
3033
@ViewBuilder
3134
func buildMenu() -> any View
@@ -88,7 +91,7 @@ open class BaseChatTab {
8891
/// The tab item for this chat tab.
8992
@ViewBuilder
9093
public var tabItem: some View {
91-
let id = "ChatTabMenu\(id)"
94+
let id = "ChatTabTab\(id)"
9295
if let tab = self as? (any ChatTabType) {
9396
ContentView(buildView: tab.buildTabItem).id(id)
9497
.onAppear {
@@ -99,6 +102,17 @@ open class BaseChatTab {
99102
}
100103
}
101104

105+
/// The icon for this chat tab.
106+
@ViewBuilder
107+
public var icon: some View {
108+
let id = "ChatTabIcon\(id)"
109+
if let tab = self as? (any ChatTabType) {
110+
ContentView(buildView: tab.buildIcon).id(id)
111+
} else {
112+
EmptyView().id(id)
113+
}
114+
}
115+
102116
/// The tab item for this chat tab.
103117
@ViewBuilder
104118
public var menu: some View {
@@ -183,6 +197,10 @@ public class EmptyChatTab: ChatTab {
183197
Text("Empty-\(id)")
184198
}
185199

200+
public func buildIcon() -> any View {
201+
Image(systemName: "square")
202+
}
203+
186204
public func buildMenu() -> any View {
187205
Text("Empty-\(id)")
188206
}

0 commit comments

Comments
 (0)