Skip to content

Commit 374edfb

Browse files
committed
feat: make workspaces list scrollable on overflow
1 parent c19b39a commit 374edfb

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

Coder-Desktop/Coder-Desktop/Views/VPN/Agents.swift

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,32 @@ struct Agents<VPN: VPNService>: View {
1616
if vpn.state == .connected {
1717
let items = vpn.menuState.sorted
1818
let visibleItems = viewAll ? items[...] : items.prefix(defaultVisibleRows)
19-
ForEach(visibleItems, id: \.id) { agent in
20-
MenuItemView(
21-
item: agent,
22-
baseAccessURL: state.baseAccessURL!,
23-
expandedItem: $expandedItem,
24-
userInteracted: $hasToggledExpansion
25-
)
26-
.padding(.horizontal, Theme.Size.trayMargin)
27-
}.onChange(of: visibleItems) {
28-
// If no workspaces are online, we should expand the first one to come online
29-
if visibleItems.filter({ $0.status != .off }).isEmpty {
30-
hasToggledExpansion = false
31-
return
19+
ScrollView(showsIndicators: false) {
20+
ForEach(visibleItems, id: \.id) { agent in
21+
MenuItemView(
22+
item: agent,
23+
baseAccessURL: state.baseAccessURL!,
24+
expandedItem: $expandedItem,
25+
userInteracted: $hasToggledExpansion
26+
)
27+
.padding(.horizontal, Theme.Size.trayMargin)
28+
}.onChange(of: visibleItems) {
29+
// If no workspaces are online, we should expand the first one to come online
30+
if visibleItems.filter({ $0.status != .off }).isEmpty {
31+
hasToggledExpansion = false
32+
return
33+
}
34+
if hasToggledExpansion {
35+
return
36+
}
37+
withAnimation(.snappy(duration: Theme.Animation.collapsibleDuration)) {
38+
expandedItem = visibleItems.first?.id
39+
}
40+
hasToggledExpansion = true
3241
}
33-
if hasToggledExpansion {
34-
return
35-
}
36-
withAnimation(.snappy(duration: Theme.Animation.collapsibleDuration)) {
37-
expandedItem = visibleItems.first?.id
38-
}
39-
hasToggledExpansion = true
4042
}
43+
.scrollBounceBehavior(.basedOnSize)
44+
.frame(maxHeight: 400)
4145
if items.count == 0 {
4246
Text("No workspaces!")
4347
.font(.body)

Coder-Desktop/Coder-Desktop/Views/VPN/VPNMenuItem.swift

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,25 @@ struct MenuItemView: View {
138138
MenuItemIcons(item: item, wsURL: wsURL)
139139
}
140140
if isExpanded {
141-
switch (loadingApps, hasApps) {
142-
case (true, _):
143-
CircularProgressView(value: nil, strokeWidth: 3, diameter: 15)
144-
.padding(.top, 5)
145-
case (false, true):
146-
MenuItemCollapsibleView(apps: apps)
147-
case (false, false):
148-
HStack {
149-
Text(item.status == .off ? "Workspace is offline." : "No apps available.")
150-
.font(.body)
151-
.foregroundColor(.secondary)
152-
.padding(.horizontal, Theme.Size.trayInset)
153-
.padding(.top, 7)
141+
Group {
142+
switch (loadingApps, hasApps) {
143+
case (true, _):
144+
CircularProgressView(value: nil, strokeWidth: 3, diameter: 15)
145+
.padding(.top, 5)
146+
case (false, true):
147+
MenuItemCollapsibleView(apps: apps)
148+
case (false, false):
149+
HStack {
150+
Text(item.status == .off ? "Workspace is offline." : "No apps available.")
151+
.font(.body)
152+
.foregroundColor(.secondary)
153+
.padding(.horizontal, Theme.Size.trayInset)
154+
.padding(.top, 7)
155+
}
154156
}
155-
}
157+
}.task { await loadApps() }
156158
}
157159
}
158-
.task { await loadApps() }
159160
}
160161

161162
func loadApps() async {

0 commit comments

Comments
 (0)