Skip to content

Commit a9791d6

Browse files
committed
refactor
1 parent b9be729 commit a9791d6

File tree

4 files changed

+20
-50
lines changed

4 files changed

+20
-50
lines changed

Examples/Sources/ChatbotExample/ChatbotApp.swift

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,26 @@ struct ChatbotApp: App {
1515
var body: some Scene {
1616
WindowGroup("ChatBot") {
1717
#hotReloadable {
18-
ZStack {
19-
// Main content with sidebar
20-
HStack(spacing: 0) {
21-
// Thread Sidebar - conditionally shown
22-
if viewModel.showSidebar {
23-
ThreadSidebarView(
24-
threads: Binding(
25-
get: { viewModel.threads },
26-
set: { viewModel.threads = $0 }
27-
),
28-
selectedThread: Binding(
29-
get: { viewModel.selectedThread },
30-
set: { viewModel.selectedThread = $0 }
31-
),
32-
showSidebar: Binding(
33-
get: { viewModel.showSidebar },
34-
set: { viewModel.showSidebar = $0 }
35-
),
36-
onNewThread: viewModel.createNewThread,
37-
onSelectThread: viewModel.selectThread,
38-
onDeleteThread: viewModel.deleteThread
39-
)
40-
.frame(width: 300)
41-
}
42-
43-
// Main chat area
44-
MainChatView(viewModel: viewModel)
45-
}
46-
.frame(maxWidth: .infinity, maxHeight: .infinity)
47-
18+
NavigationSplitView {
19+
// Sidebar content
20+
ThreadSidebarView(
21+
threads: Binding(
22+
get: { viewModel.threads },
23+
set: { viewModel.threads = $0 }
24+
),
25+
selectedThread: Binding(
26+
get: { viewModel.selectedThread },
27+
set: { viewModel.selectedThread = $0 }
28+
),
29+
onNewThread: viewModel.createNewThread,
30+
onSelectThread: viewModel.selectThread,
31+
onDeleteThread: viewModel.deleteThread
32+
)
33+
} detail: {
34+
// Main chat area
35+
MainChatView(viewModel: viewModel)
36+
}
37+
.overlay {
4838
// Settings Overlay
4939
if viewModel.showSettings {
5040
ChatSettingsDialog(

Examples/Sources/ChatbotExample/ViewModels/ChatbotViewModel.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class ChatbotViewModel: SwiftCrossUI.ObservableObject {
99
// MARK: - Published Properties
1010
@SwiftCrossUI.Published var selectedThread: ChatThread?
1111
@SwiftCrossUI.Published var threads: [ChatThread] = []
12-
@SwiftCrossUI.Published var showSidebar = true
1312
@SwiftCrossUI.Published var currentMessage = ""
1413
@SwiftCrossUI.Published var selectedLLM: LLM = .gpt3_5Turbo
1514
@SwiftCrossUI.Published var isLoading = false
@@ -156,10 +155,6 @@ class ChatbotViewModel: SwiftCrossUI.ObservableObject {
156155

157156
// MARK: - UI State Management
158157

159-
func toggleSidebar() {
160-
showSidebar.toggle()
161-
}
162-
163158
func toggleSettings() {
164159
showSettings.toggle()
165160
}

Examples/Sources/ChatbotExample/Views/MainChatView.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ struct ChatHeaderView: View {
5454

5555
var body: some View {
5656
HStack {
57-
// Sidebar toggle button (when hidden)
58-
if !viewModel.showSidebar {
59-
Button("") {
60-
viewModel.toggleSidebar()
61-
}
62-
.iconButtonLargeStyle()
63-
}
64-
6557
// Thread title or placeholder
6658
VStack(alignment: .leading, spacing: AppSpacing.xs) {
6759
if let thread = viewModel.selectedThread {

Examples/Sources/ChatbotExample/Views/ThreadSidebarView.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Foundation
66
struct ThreadSidebarView: View {
77
@Binding var threads: [ChatThread]
88
@Binding var selectedThread: ChatThread?
9-
@Binding var showSidebar: Bool
109

1110
let onNewThread: () -> Void
1211
let onSelectThread: (ChatThread) -> Void
@@ -23,11 +22,6 @@ struct ThreadSidebarView: View {
2322
.fixedSize(horizontal: true, vertical: false)
2423

2524
Spacer()
26-
27-
Button("×") {
28-
showSidebar = false
29-
}
30-
.iconButtonLargeStyle()
3125
}
3226
.padding(.horizontal, AppSpacing.xl)
3327
.padding(.vertical, AppSpacing.sm)
@@ -71,7 +65,6 @@ struct ThreadSidebarView: View {
7165
}
7266
.frame(maxHeight: .infinity)
7367
.background(AppColors.surface)
74-
.frame(width: 300)
7568
}
7669
}
7770

0 commit comments

Comments
 (0)