From 082e0933d2d029f4b442f55194e9a4525e703261 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Mon, 14 Nov 2022 17:53:37 +0100 Subject: [PATCH] Slash some todos (#540) --- Mastodon/Coordinator/SceneCoordinator.swift | 2 +- .../Login/MastodonLoginViewController.swift | 55 +++++++++---------- .../Resources/en.lproj/Localizable.strings | 2 +- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index 365002256..9e6307a38 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -548,6 +548,6 @@ extension SceneCoordinator: MastodonLoginViewControllerDelegate { } func nextButtonPressed(_ viewController: MastodonLoginViewController) { - //TODO: @zeitschlag implement, show ASWebAuthentication and stuff + viewController.login() } } diff --git a/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift b/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift index 5811de40b..a1daf77bd 100644 --- a/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift +++ b/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift @@ -133,35 +133,34 @@ class MastodonLoginViewController: UIViewController, NeedsDependency { } @objc func nextButtonPressed(_ sender: Any) { - login(sender) + delegate?.nextButtonPressed(self) } - @objc func login(_ sender: Any) { + @objc func login() { guard let server = viewModel.selectedServer else { return } authenticationViewModel - .authenticated - .asyncMap { domain, user -> Result in - do { - let result = try await self.context.authenticationService.activeMastodonUser(domain: domain, userID: user.id) - return .success(result) - } catch { - return .failure(error) - } + .authenticated + .asyncMap { domain, user -> Result in + do { + let result = try await self.context.authenticationService.activeMastodonUser(domain: domain, userID: user.id) + return .success(result) + } catch { + return .failure(error) } - .receive(on: DispatchQueue.main) - .sink { [weak self] result in - guard let self = self else { return } - switch result { - case .failure(let error): - assertionFailure(error.localizedDescription) - case .success(let isActived): - assert(isActived) - // self.dismiss(animated: true, completion: nil) - self.coordinator.setup() - } + } + .receive(on: DispatchQueue.main) + .sink { [weak self] result in + guard let self = self else { return } + switch result { + case .failure(let error): + assertionFailure(error.localizedDescription) + case .success(let isActived): + assert(isActived) + self.coordinator.setup() } - .store(in: &disposeBag) + } + .store(in: &disposeBag) authenticationViewModel.isAuthenticating.send(true) context.apiService.createApplication(domain: server.domain) @@ -183,9 +182,10 @@ class MastodonLoginViewController: UIViewController, NeedsDependency { switch completion { case .failure(let error): - //TODO: @zeitschlag show error - break + let alert = UIAlertController.standardAlert(of: error) + self.present(alert, animated: true) case .finished: + // do nothing. There's a subscriber above resulting in `coordinator.setup()` break } } receiveValue: { [weak self] info in @@ -251,7 +251,6 @@ class MastodonLoginViewController: UIViewController, NeedsDependency { self.view.layoutIfNeeded() } } - } // MARK: - OnboardingViewControllerAppearance @@ -290,7 +289,7 @@ extension MastodonLoginViewController: MastodonLoginViewModelDelegate { // MARK: - ASWebAuthenticationPresentationContextProviding extension MastodonLoginViewController: ASWebAuthenticationPresentationContextProviding { - func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { - return view.window! - } + func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { + return view.window! + } } diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings index 0ede22a38..1a48d8c55 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/en.lproj/Localizable.strings @@ -317,7 +317,7 @@ uploaded to Mastodon."; "Scene.Register.LetsGetYouSetUpOnDomain" = "Let’s get you set up on %@"; "Scene.Login.Title" = "Welcome Back!"; "Scene.Login.Subtitle" = "Log you in with the server where you created your account"; -"Scene.Login.ServerSearchField.Placeholder" = "Search for your server"; +"Scene.Login.ServerSearchField.Placeholder" = "Search server or enter URL"; "Scene.Register.Title" = "Let’s get you set up on %@"; "Scene.Report.Content1" = "Are there any other posts you’d like to add to the report?"; "Scene.Report.Content2" = "Is there anything the moderators should know about this report?";