forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountView.swift
More file actions
94 lines (83 loc) · 2.47 KB
/
AccountView.swift
File metadata and controls
94 lines (83 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import AppKit
import Client
import CopilotModel
import SwiftUI
struct AccountView: View {
enum Location {
case account
case gitHubCopilot
case openAI
}
@State var location: Location = .account
func navigate(to: Location) {
withAnimation(.easeInOut(duration: 0.2)) {
location = to
}
}
var body: some View {
Section {
switch location {
case .account:
VStack(alignment: .leading, spacing: 8) {
Text("Accounts")
.font(.title)
.padding(.bottom, 12)
HStack {
Button {
navigate(to: .gitHubCopilot)
} label: {
Text("GitHub Copilot")
}.buttonStyle(CopilotButtonStyle())
Button {
navigate(to: .openAI)
} label: {
Text("OpenAI")
}.buttonStyle(CopilotButtonStyle())
Spacer()
}
}
case .gitHubCopilot:
ChildPage(content: {
CopilotView()
}, onBackButtonClick: {
navigate(to: .account)
})
case .openAI:
ChildPage(content: {
OpenAIView()
}, onBackButtonClick: {
navigate(to: .account)
})
}
}
}
struct ChildPage<V: View>: View {
var content: () -> V
var onBackButtonClick: () -> Void
var body: some View {
VStack(alignment: .leading) {
Button(action: onBackButtonClick) {
HStack {
Image(systemName: "chevron.left")
Text("Accounts")
}
.font(.title3)
}
.buttonStyle(.plain)
content()
}
}
}
}
struct AccountView_Previews: PreviewProvider {
static var previews: some View {
VStack(alignment: .leading, spacing: 8) {
AccountView()
AccountView(location: .gitHubCopilot)
AccountView(location: .openAI)
}
.frame(height: 800)
.padding(.all, 8)
.background(Color.black)
}
}