[FIX] AppIDsView and authentication workflow

This commit is contained in:
Fabian Thies
2023-02-03 18:19:07 +01:00
committed by Joe Mattiello
parent 5af6f825ee
commit 0239dfcd6d
2 changed files with 78 additions and 14 deletions

View File

@@ -39,8 +39,8 @@ final class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, A
{
let context: AuthenticatedOperationContext
// private weak var presentingViewController: UIViewController?
//
private weak var presentingViewController: UIViewController?
// private lazy var navigationController: UINavigationController = {
// let navigationController = self.storyboard.instantiateViewController(withIdentifier: "navigationController") as! UINavigationController
// if #available(iOS 13.0, *)
@@ -63,7 +63,7 @@ final class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, A
init(context: AuthenticatedOperationContext, presentingViewController: UIViewController?)
{
self.context = context
// self.presentingViewController = presentingViewController
self.presentingViewController = presentingViewController
super.init()
@@ -312,7 +312,10 @@ private extension AuthenticationOperation
}
func dismiss() {
UIApplication.shared.keyWindow?.rootViewController?.presentedViewController?.dismiss(animated: true)
if let presentingViewController {
presentingViewController.dismiss(animated: true)
}
// UIApplication.shared.keyWindow?.rootViewController?.presentedViewController?.dismiss(animated: true)
}
}

View File

@@ -19,6 +19,8 @@ struct AppIDsView: View {
NSSortDescriptor(keyPath: \AppID.expirationDate, ascending: true)
], predicate: NSPredicate(format: "%K == %@", #keyPath(AppID.team), DatabaseManager.shared.activeTeam() ?? Team()))
var appIDs: FetchedResults<AppID>
@State var isLoading: Bool = false
var body: some View {
@@ -28,31 +30,90 @@ struct AppIDsView: View {
.foregroundColor(.secondary)
ForEach(appIDs, id: \.identifier) { appId in
VStack {
Text(appId.name)
Text(appId.identifier)
.font(.callout)
.foregroundColor(.secondary)
HStack {
VStack(alignment: .leading) {
Text(appId.name)
.bold()
Text(appId.bundleIdentifier)
.font(.footnote)
.foregroundColor(.secondary)
}
Spacer()
if let expirationDate = appId.expirationDate {
VStack(spacing: 4) {
Text("Expires in")
.font(.caption)
.foregroundColor(.accentColor)
SwiftUI.Button {
} label: {
Text(DateFormatterHelper.string(forExpirationDate: expirationDate).uppercased())
.bold()
}
.buttonStyle(PillButtonStyle(tintColor: .altPrimary))
.disabled(true)
}
}
}
.padding()
.tintedBackground(.accentColor)
.clipShape(RoundedRectangle(cornerRadius: 30, style: .circular))
.clipShape(RoundedRectangle(cornerRadius: 24, style: .circular))
}
}
.padding()
}
.navigationTitle(L10n.AppIDsView.title)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
if self.isLoading {
ProgressView()
.progressViewStyle(.circular)
}
}
ToolbarItem(placement: .confirmationAction) {
SwiftUI.Button(L10n.Action.done, action: self.dismiss)
}
}
.onAppear(performAsync: self.updateAppIDs)
}
func updateAppIDs() async {
self.isLoading = true
defer { self.isLoading = false }
await withCheckedContinuation { continuation in
AppManager.shared.fetchAppIDs { result in
do {
let (_, context) = try result.get()
try context.save()
} catch {
print(error)
NotificationManager.shared.reportError(error: error)
}
continuation.resume()
}
}
}
}
struct AppIDsView_Previews: PreviewProvider {
static var previews: some View {
AppIDsView()
extension View {
func onAppear(performAsync task: @escaping () async -> Void) -> some View {
self.onAppear(perform: { Task { await task() } })
}
}
struct AppIDsView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
AppIDsView()
}
}
}