Skip to content

Commit a8affe1

Browse files
committed
expand first
1 parent 0327dc2 commit a8affe1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct Agents<VPN: VPNService>: View {
55
@EnvironmentObject var state: AppState
66
@State private var viewAll = false
77
@State private var expandedItem: VPNMenuItem.ID?
8+
@State private var hasToggledExpansion: Bool = false
89
private let defaultVisibleRows = 5
910

1011
let inspection = Inspection<Self>()
@@ -16,8 +17,25 @@ struct Agents<VPN: VPNService>: View {
1617
let items = vpn.menuState.sorted
1718
let visibleItems = viewAll ? items[...] : items.prefix(defaultVisibleRows)
1819
ForEach(visibleItems, id: \.id) { agent in
19-
MenuItemView(item: agent, baseAccessURL: state.baseAccessURL!, expandedItem: $expandedItem)
20-
.padding(.horizontal, Theme.Size.trayMargin)
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
32+
}
33+
// If an active workspace is expanded, or has been
34+
if hasToggledExpansion {
35+
return
36+
}
37+
expandedItem = visibleItems.first?.id
38+
hasToggledExpansion = true
2139
}
2240
if items.count == 0 {
2341
Text("No workspaces!")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct MenuItemView: View {
6666
let item: VPNMenuItem
6767
let baseAccessURL: URL
6868
@Binding var expandedItem: VPNMenuItem.ID?
69+
@Binding var userInteracted: Bool
6970

7071
@State private var nameIsSelected: Bool = false
7172

@@ -95,6 +96,7 @@ struct MenuItemView: View {
9596
}
9697

9798
private func toggleExpanded() {
99+
userInteracted = true
98100
if isExpanded {
99101
withAnimation(.snappy(duration: Theme.Animation.collapsibleDuration)) {
100102
expandedItem = nil
@@ -254,6 +256,5 @@ struct AnimatedChevron: View {
254256
.font(.system(size: 12, weight: .semibold))
255257
.foregroundColor(color)
256258
.rotationEffect(.degrees(isExpanded ? 90 : 0))
257-
.animation(.easeInOut(duration: Theme.Animation.collapsibleDuration), value: isExpanded)
258259
}
259260
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy