-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
282 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import Foundation | ||
import SwiftUI | ||
import WordPressAPI | ||
import AuthenticationServices | ||
import WordPressAPIInternal | ||
|
||
struct AutoDiscoveryResultView: View { | ||
let results: [AutoDiscoveryAttemptViewData] | ||
|
||
var body: some View { | ||
Text("N") | ||
} | ||
} | ||
|
||
struct AutoDiscoveryStepView: View { | ||
let icon: String | ||
let label: String | ||
|
||
var body: some View { | ||
VStack(alignment: .leading) { | ||
HStack(alignment: .firstTextBaseline) { | ||
Image(systemName: icon) | ||
.font(.title) | ||
Text(label).font(.title) | ||
Spacer() | ||
} | ||
}.padding(.horizontal) | ||
} | ||
} | ||
|
||
struct AutoDiscoveryErrorView: View { | ||
let errorMessage: String | ||
|
||
var body: some View { | ||
Text(errorMessage) | ||
} | ||
} | ||
|
||
struct AutodiscoveryReportView: View { | ||
let report: AutoDiscoveryResult? | ||
|
||
var body: some View { | ||
if let report { | ||
if let success = report.successfulAttempt { | ||
if let url = success.domainWithSubdomain { | ||
Text(url) | ||
} | ||
|
||
if success.couldConnectToUrl { | ||
AutoDiscoveryStepView(icon: "checkmark.circle", label: "Site Connection") | ||
} | ||
|
||
if success.couldUseHttps { | ||
AutoDiscoveryStepView(icon: "checkmark.circle", label: "Can connect using HTTPS") | ||
} | ||
|
||
if success.foundApiRoot { | ||
AutoDiscoveryStepView(icon: "checkmark.circle", label: "Supports JSON API") | ||
} | ||
|
||
if success.foundAuthenticationUrl { | ||
AutoDiscoveryStepView(icon: "checkmark.circle", label: "Found authentication URL") | ||
} | ||
} else { | ||
Text("Unable to connect") | ||
} | ||
} else { | ||
ProgressView() | ||
} | ||
} | ||
} | ||
|
||
struct AutoDiscoveryAttemptViewData { | ||
|
||
enum ErrorType { | ||
case network | ||
case missingRootUrl | ||
} | ||
|
||
enum StepType { | ||
case siteWasFound | ||
case supportsHTTPS | ||
case canFindRootURL | ||
case apiRootHasAuthUrl | ||
} | ||
|
||
// let userInput: String | ||
|
||
let isError: Bool | ||
|
||
let errorType: ErrorType? | ||
let errorMessage: String? | ||
|
||
let step: StepType | ||
|
||
// var url: URL? { | ||
// URL(string: userInput) | ||
// } | ||
|
||
var icon: String { | ||
// if url?.scheme == "https" { | ||
// return "checkmark.shield" | ||
// } | ||
|
||
return switch errorType { | ||
case .network: "network.slash" | ||
case .missingRootUrl: "questionmark.circle.dashed" | ||
case nil: "checkmark.circle" | ||
} | ||
} | ||
|
||
var attemptTypeString: String { | ||
switch step { | ||
case .siteWasFound: "Site Connection" | ||
case .supportsHTTPS: "Can connect using HTTPS" | ||
case .canFindRootURL: "Supports JSON API" | ||
case .apiRootHasAuthUrl: "Found authentication URL" | ||
} | ||
} | ||
} | ||
|
||
#Preview("Live data") { | ||
|
||
struct AsyncTestView: View { | ||
|
||
@State var report: AutoDiscoveryResult? | ||
|
||
private let loginApi = WordPressLoginClient(requestExecutor: URLSession.shared) | ||
|
||
var body: some View { | ||
AutodiscoveryReportView(report: report) | ||
.task { | ||
let result = await loginApi.autodiscoveryResult(forSite: "http://vanilla.wpmt.co") | ||
|
||
self.report = result | ||
} | ||
} | ||
} | ||
|
||
return AsyncTestView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.