1
1
import SwiftUI
2
2
3
- struct VPNMenu < Conn : CoderVPN > : View {
4
- @ObservedObject var vpnService : Conn
3
+ struct VPNMenu < VPN : CoderVPN > : View {
4
+ @ObservedObject var vpnService : VPN
5
5
6
6
var body : some View {
7
7
// Main stack
@@ -45,24 +45,24 @@ struct VPNMenu<Conn: CoderVPN>: View {
45
45
// Trailing stack
46
46
VStack ( alignment: . leading, spacing: 3 ) {
47
47
Divider ( ) . padding ( [ . horizontal] , 10 ) . padding ( . vertical, 4 )
48
- RowButtonView {
48
+ ButtonRowView {
49
49
Text ( " Create workspace " )
50
50
EmptyView ( )
51
51
} action: {
52
52
// TODO
53
53
}
54
54
Divider ( ) . padding ( [ . horizontal] , 10 ) . padding ( . vertical, 4 )
55
- RowButtonView {
55
+ ButtonRowView {
56
56
Text ( " About " )
57
57
} action: {
58
58
// TODO
59
59
}
60
- RowButtonView {
60
+ ButtonRowView {
61
61
Text ( " Preferences " )
62
62
} action: {
63
63
// TODO
64
64
}
65
- RowButtonView {
65
+ ButtonRowView {
66
66
Text ( " Sign out " )
67
67
} action: {
68
68
// TODO
@@ -72,94 +72,6 @@ struct VPNMenu<Conn: CoderVPN>: View {
72
72
}
73
73
}
74
74
75
- struct AgentRow : Identifiable {
76
- let id : UUID
77
- let name : String
78
- let status : Color
79
- let copyableDNS : String
80
- }
81
-
82
- struct AgentRowView : View {
83
- let workspace : AgentRow
84
- @State private var nameIsSelected : Bool = false
85
- @State private var copyIsSelected : Bool = false
86
-
87
- private var fmtWsName : AttributedString {
88
- var formattedName = AttributedString ( workspace. name)
89
- formattedName. foregroundColor = . primary
90
- var coderPart = AttributedString ( " .coder " )
91
- coderPart. foregroundColor = . gray
92
- formattedName. append ( coderPart)
93
- return formattedName
94
- }
95
-
96
- var body : some View {
97
- HStack ( spacing: 0 ) {
98
- Button {
99
- // TODO: Action
100
- } label: {
101
- HStack ( spacing: 10 ) {
102
- ZStack {
103
- Circle ( )
104
- . fill ( workspace. status. opacity ( 0.4 ) )
105
- . frame ( width: 12 , height: 12 )
106
- Circle ( )
107
- . fill ( workspace. status. opacity ( 1.0 ) )
108
- . frame ( width: 7 , height: 7 )
109
- }
110
- Text ( fmtWsName) . lineLimit ( 1 ) . truncationMode ( . tail)
111
- Spacer ( )
112
- } . padding ( . horizontal, 10 )
113
- . frame ( minHeight: 22 )
114
- . frame ( maxWidth: . infinity, alignment: . leading)
115
- . foregroundStyle ( nameIsSelected ? Color . white : . primary)
116
- . background ( nameIsSelected ? Color . accentColor. opacity ( 0.8 ) : . clear)
117
- . clipShape ( . rect( cornerRadius: 4 ) )
118
- . onHover { hovering in nameIsSelected = hovering }
119
- Spacer ( )
120
- } . buttonStyle ( . plain)
121
- Button {
122
- // TODO: Proper clipboard abstraction
123
- NSPasteboard . general. setString ( workspace. copyableDNS, forType: . string)
124
- } label: {
125
- Image ( systemName: " doc.on.doc " )
126
- . symbolVariant ( . fill)
127
- . padding ( 3 )
128
- } . foregroundStyle ( copyIsSelected ? Color . white : . primary)
129
- . imageScale ( . small)
130
- . background ( copyIsSelected ? Color . accentColor. opacity ( 0.8 ) : . clear)
131
- . clipShape ( . rect( cornerRadius: 4 ) )
132
- . onHover { hovering in copyIsSelected = hovering }
133
- . buttonStyle ( . plain)
134
- . padding ( . trailing, 5 )
135
- }
136
- }
137
- }
138
-
139
- struct RowButtonView < Label: View > : View {
140
- @State private var isSelected : Bool = false
141
- @ViewBuilder var label : ( ) -> Label
142
- var action : ( ) -> Void
143
-
144
- var body : some View {
145
- Button {
146
- action ( )
147
- } label: {
148
- HStack ( spacing: 0 ) {
149
- label ( )
150
- Spacer ( )
151
- }
152
- . padding ( . horizontal, 10 )
153
- . frame ( minHeight: 22 )
154
- . frame ( maxWidth: . infinity, alignment: . leading)
155
- . foregroundStyle ( isSelected ? Color . white : . primary)
156
- . background ( isSelected ? Color . accentColor. opacity ( 0.8 ) : . clear)
157
- . clipShape ( . rect( cornerRadius: 4 ) )
158
- . onHover { hovering in isSelected = hovering }
159
- } . buttonStyle ( . plain)
160
- }
161
- }
162
-
163
75
#Preview {
164
76
VPNMenu ( vpnService: PreviewVPN ( ) ) . frame ( width: 256 )
165
77
}
0 commit comments