@@ -2,24 +2,27 @@ import SwiftUI
2
2
3
3
struct VPNMenu < VPN: CoderVPN > : View {
4
4
@ObservedObject var vpnService : VPN
5
+ @State var viewAll = false
6
+
7
+ private let defaultVisibleRows = 5
5
8
6
9
var body : some View {
7
10
// Main stack
8
- VStack ( alignment: . leading) {
11
+ VStackLayout ( alignment: . leading) {
9
12
// CoderVPN Stack
10
13
VStack ( alignment: . leading, spacing: 10 ) {
11
14
HStack {
12
15
Toggle ( isOn: Binding (
13
16
get: { self . vpnService. state == . connected || self . vpnService. state == . connecting } ,
14
17
set: { isOn in Task {
15
- if isOn { await self . vpnService. start ( ) } else { await self . vpnService. stop ( ) }
16
- }
18
+ if isOn { await self . vpnService. start ( ) } else { await self . vpnService. stop ( ) }
19
+ }
17
20
}
18
21
) ) {
19
22
Text ( " CoderVPN " )
20
23
. frame ( maxWidth: . infinity, alignment: . leading)
21
24
} . toggleStyle ( . switch)
22
- . disabled ( self . vpnService. state == . connecting || self . vpnService. state == . disconnecting)
25
+ . disabled ( self . vpnService. state == . connecting || self . vpnService. state == . disconnecting)
23
26
}
24
27
Divider ( )
25
28
Text ( " Workspace Agents " )
@@ -35,12 +38,34 @@ struct VPNMenu<VPN: CoderVPN>: View {
35
38
) . padding ( )
36
39
Spacer ( )
37
40
}
41
+ } else if case let . failed( vpnErr) = self . vpnService. state {
42
+ Text ( " \( vpnErr. description) " )
43
+ . font ( . headline)
44
+ . foregroundColor ( . red)
45
+ . multilineTextAlignment ( . center)
46
+ . fixedSize ( horizontal: false , vertical: true )
47
+ . padding ( . horizontal, 15 )
48
+ . padding ( . top, 5 )
49
+ . frame ( maxWidth: . infinity)
38
50
}
39
51
} . padding ( [ . horizontal, . top] , 15 )
52
+ // Workspaces List
40
53
if self . vpnService. state == . connected {
41
- ForEach ( self . vpnService. data) { workspace in
54
+ let visibleData = viewAll ? vpnService. data : Array ( vpnService. data. prefix ( defaultVisibleRows) )
55
+ ForEach ( visibleData) { workspace in
42
56
AgentRowView ( workspace: workspace) . padding ( . horizontal, 5 )
43
57
}
58
+ if vpnService. data. count > defaultVisibleRows {
59
+ Button ( action: {
60
+ viewAll. toggle ( )
61
+ } , label: {
62
+ Text ( viewAll ? " Show Less " : " Show All " )
63
+ . font ( . headline)
64
+ . foregroundColor ( . gray)
65
+ . padding ( . horizontal, 15 )
66
+ . padding ( . top, 5 )
67
+ } ) . buttonStyle ( . plain)
68
+ }
44
69
}
45
70
// Trailing stack
46
71
VStack ( alignment: . leading, spacing: 3 ) {
@@ -49,29 +74,29 @@ struct VPNMenu<VPN: CoderVPN>: View {
49
74
Text ( " Create workspace " )
50
75
EmptyView ( )
51
76
} action: {
52
- // TODO
77
+ // TODO:
53
78
}
54
79
Divider ( ) . padding ( [ . horizontal] , 10 ) . padding ( . vertical, 4 )
55
80
ButtonRowView {
56
81
Text ( " About " )
57
82
} action: {
58
- // TODO
83
+ // TODO:
59
84
}
60
85
ButtonRowView {
61
86
Text ( " Preferences " )
62
87
} action: {
63
- // TODO
88
+ // TODO:
64
89
}
65
90
ButtonRowView {
66
91
Text ( " Sign out " )
67
92
} action: {
68
- // TODO
93
+ // TODO:
69
94
}
70
95
} . padding ( [ . horizontal, . bottom] , 5 )
71
96
} . padding ( . bottom, 5 )
72
97
}
73
98
}
74
99
75
100
#Preview {
76
- VPNMenu ( vpnService: PreviewVPN ( ) ) . frame ( width: 256 )
101
+ VPNMenu ( vpnService: PreviewVPN ( shouldFail : true ) ) . frame ( width: 256 )
77
102
}
0 commit comments