forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopilotConnectionView.swift
More file actions
115 lines (105 loc) · 3.9 KB
/
CopilotConnectionView.swift
File metadata and controls
115 lines (105 loc) · 3.9 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import ComposableArchitecture
import GitHubCopilotViewModel
import SwiftUI
struct CopilotConnectionView: View {
@AppStorage("username") var username: String = ""
@Environment(\.toast) var toast
@StateObject var viewModel: GitHubCopilotViewModel
let store: StoreOf<General>
var body: some View {
WithPerceptionTracking {
VStack {
connection
.padding(.bottom, 20)
copilotResources
}
}
}
var accountStatus: some View {
SettingsButtonRow(
title: "GitHub Account Status Permissions",
subtitle: "GitHub Account: \(viewModel.status?.description ?? "Loading...")"
) {
if viewModel.isRunningAction || viewModel.waitingForSignIn {
ProgressView().controlSize(.small)
}
Button("Refresh Connection") {
viewModel.checkStatus()
}
if viewModel.waitingForSignIn {
Button("Cancel") {
viewModel.cancelWaiting()
}
} else if viewModel.status == .notSignedIn {
Button("Log in to GitHub") {
viewModel.signIn()
}
.alert(
viewModel.signInResponse?.userCode ?? "",
isPresented: $viewModel.isSignInAlertPresented,
presenting: viewModel.signInResponse) { _ in
Button("Cancel", role: .cancel, action: {})
Button("Copy Code and Open", action: viewModel.copyAndOpen)
} message: { response in
Text("""
Please enter the above code in the \
GitHub website to authorize your \
GitHub account with Copilot for Xcode.
\(response?.verificationURL.absoluteString ?? "")
""")
}
}
if viewModel.status == .ok || viewModel.status == .alreadySignedIn ||
viewModel.status == .notAuthorized
{
Button("Log Out from GitHub") { viewModel.signOut()
viewModel.isSignInAlertPresented = false
}
}
}
}
var connection: some View {
SettingsSection(title: "Account Settings", showWarning: viewModel.status == .notAuthorized) {
accountStatus
Divider()
if viewModel.status == .notAuthorized {
SettingsLink(
url: "https://github.com/features/copilot/plans",
title: "Enable powerful AI features for free with the GitHub Copilot Free plan"
)
Divider()
}
SettingsLink(
url: "https://github.com/settings/copilot",
title: "GitHub Copilot Account Settings"
)
}
}
var copilotResources: some View {
SettingsSection(title: "Copilot Resources") {
SettingsLink(
url: "https://docs.github.com/en/copilot",
title: "View Copilot Documentation"
)
Divider()
SettingsLink(
url: "https://github.com/orgs/community/discussions/categories/copilot",
title: "View Copilot Feedback Forum"
)
}
}
}
#Preview {
CopilotConnectionView(
viewModel: GitHubCopilotViewModel.shared,
store: .init(initialState: .init(), reducer: { General() })
)
}
#Preview("Running") {
let runningModel = GitHubCopilotViewModel.shared
runningModel.isRunningAction = true
return CopilotConnectionView(
viewModel: GitHubCopilotViewModel.shared,
store: .init(initialState: .init(), reducer: { General() })
)
}