diff --git a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift index b2bc62da8..2ed541c5c 100644 --- a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift +++ b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewController.swift @@ -123,12 +123,6 @@ extension MastodonPickServerViewController { ) .store(in: &disposeBag) - viewModel - .selectedServer - .map { $0 != nil } - .assign(to: \.isEnabled, on: onboardingNextView.nextButton) - .store(in: &disposeBag) - Publishers.Merge( viewModel.error, authenticationViewModel.error @@ -211,7 +205,7 @@ extension MastodonPickServerViewController { } .store(in: &disposeBag) - onboardingNextView.nextButton.addTarget(self, action: #selector(MastodonPickServerViewController.nextButtonDidPressed(_:)), for: .touchUpInside) + onboardingNextView.nextButton.addTarget(self, action: #selector(MastodonPickServerViewController.next(_:)), for: .touchUpInside) title = L10n.Scene.ServerPicker.title @@ -241,9 +235,18 @@ extension MastodonPickServerViewController { extension MastodonPickServerViewController { - @objc private func nextButtonDidPressed(_ sender: UIButton) { - os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function) - guard let server = viewModel.selectedServer.value else { return } + @objc private func next(_ sender: UIButton) { + + let server: Mastodon.Entity.Server + + if let selectedServer = viewModel.selectedServer.value { + server = selectedServer + } else if let randomServer = viewModel.chooseRandomServer() { + server = randomServer + } else { + return + } + authenticationViewModel.isAuthenticating.send(true) context.apiService.instance(domain: server.domain) diff --git a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift index 8909285cc..c3db6a761 100644 --- a/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift +++ b/Mastodon/Scene/Onboarding/PickServer/MastodonPickServerViewModel.swift @@ -228,6 +228,19 @@ extension MastodonPickServerViewModel { .store(in: &disposeBag) } + func chooseRandomServer() -> Mastodon.Entity.Server? { + + guard let language = Locale.preferredLanguages.first?.lowercased() else { return nil } + + let servers = indexedServers.value + guard servers.isNotEmpty else { return nil } + + let randomServer = servers.filter { + $0.language == language + }.randomElement() + + return randomServer + } } extension MastodonPickServerViewModel { diff --git a/Mastodon/Scene/Onboarding/PickServer/View/OnboardingNextView.swift b/Mastodon/Scene/Onboarding/PickServer/View/OnboardingNextView.swift index 57afdeea0..0bd7dfc35 100644 --- a/Mastodon/Scene/Onboarding/PickServer/View/OnboardingNextView.swift +++ b/Mastodon/Scene/Onboarding/PickServer/View/OnboardingNextView.swift @@ -13,9 +13,7 @@ import MastodonLocalization final class OnboardingNextView: UIView { static let buttonHeight: CGFloat = 50 - - private var observations = Set() - + private let container: UIStackView = { let stackView = UIStackView() stackView.axis = .vertical @@ -24,7 +22,6 @@ final class OnboardingNextView: UIView { return stackView }() - //TODO: Show loading let nextButton: UIButton = { let button = UIButton() button.translatesAutoresizingMaskIntoConstraints = false