Show main-screen after login (#540)
This commit is contained in:
parent
e7b8870329
commit
7c14d71630
|
@ -406,7 +406,9 @@ private extension SceneCoordinator {
|
||||||
_viewController.viewModel = viewModel
|
_viewController.viewModel = viewModel
|
||||||
viewController = _viewController
|
viewController = _viewController
|
||||||
case .mastodonLogin:
|
case .mastodonLogin:
|
||||||
let loginViewController = MastodonLoginViewController(appContext: appContext, authenticationViewModel: AuthenticationViewModel(context: appContext, coordinator: self, isAuthenticationExist: false))
|
let loginViewController = MastodonLoginViewController(appContext: appContext,
|
||||||
|
authenticationViewModel: AuthenticationViewModel(context: appContext, coordinator: self, isAuthenticationExist: false),
|
||||||
|
sceneCoordinator: self)
|
||||||
loginViewController.delegate = self
|
loginViewController.delegate = self
|
||||||
|
|
||||||
viewController = loginViewController
|
viewController = loginViewController
|
||||||
|
|
|
@ -21,7 +21,7 @@ enum MastodonLoginViewSection: Hashable {
|
||||||
case servers
|
case servers
|
||||||
}
|
}
|
||||||
|
|
||||||
class MastodonLoginViewController: UIViewController {
|
class MastodonLoginViewController: UIViewController, NeedsDependency {
|
||||||
|
|
||||||
weak var delegate: MastodonLoginViewControllerDelegate?
|
weak var delegate: MastodonLoginViewControllerDelegate?
|
||||||
var dataSource: UITableViewDiffableDataSource<MastodonLoginViewSection, Mastodon.Entity.Server>?
|
var dataSource: UITableViewDiffableDataSource<MastodonLoginViewSection, Mastodon.Entity.Server>?
|
||||||
|
@ -29,24 +29,26 @@ class MastodonLoginViewController: UIViewController {
|
||||||
let authenticationViewModel: AuthenticationViewModel
|
let authenticationViewModel: AuthenticationViewModel
|
||||||
var mastodonAuthenticationController: MastodonAuthenticationController?
|
var mastodonAuthenticationController: MastodonAuthenticationController?
|
||||||
|
|
||||||
weak var appContext: AppContext?
|
weak var context: AppContext!
|
||||||
|
weak var coordinator: SceneCoordinator!
|
||||||
|
|
||||||
var disposeBag = Set<AnyCancellable>()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
|
|
||||||
var contentView: MastodonLoginView {
|
var contentView: MastodonLoginView {
|
||||||
view as! MastodonLoginView
|
view as! MastodonLoginView
|
||||||
}
|
}
|
||||||
|
|
||||||
init(appContext: AppContext, authenticationViewModel: AuthenticationViewModel) {
|
init(appContext: AppContext, authenticationViewModel: AuthenticationViewModel, sceneCoordinator: SceneCoordinator) {
|
||||||
|
|
||||||
viewModel = MastodonLoginViewModel(appContext: appContext)
|
viewModel = MastodonLoginViewModel(appContext: appContext)
|
||||||
self.authenticationViewModel = authenticationViewModel
|
self.authenticationViewModel = authenticationViewModel
|
||||||
self.appContext = appContext
|
self.context = appContext
|
||||||
|
self.coordinator = sceneCoordinator
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
viewModel.delegate = self
|
viewModel.delegate = self
|
||||||
|
|
||||||
navigationItem.hidesBackButton = true
|
navigationItem.hidesBackButton = true
|
||||||
//TODO: @zeitschlag consider keyboard, do the notification-dance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||||
|
@ -137,8 +139,32 @@ class MastodonLoginViewController: UIViewController {
|
||||||
@objc func login(_ sender: Any) {
|
@objc func login(_ sender: Any) {
|
||||||
guard let server = viewModel.selectedServer else { return }
|
guard let server = viewModel.selectedServer else { return }
|
||||||
|
|
||||||
|
authenticationViewModel
|
||||||
|
.authenticated
|
||||||
|
.asyncMap { domain, user -> Result<Bool, Error> 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &disposeBag)
|
||||||
|
|
||||||
authenticationViewModel.isAuthenticating.send(true)
|
authenticationViewModel.isAuthenticating.send(true)
|
||||||
appContext?.apiService.createApplication(domain: server.domain)
|
context.apiService.createApplication(domain: server.domain)
|
||||||
.tryMap { response -> AuthenticationViewModel.AuthenticateInfo in
|
.tryMap { response -> AuthenticationViewModel.AuthenticateInfo in
|
||||||
let application = response.value
|
let application = response.value
|
||||||
guard let info = AuthenticationViewModel.AuthenticateInfo(
|
guard let info = AuthenticationViewModel.AuthenticateInfo(
|
||||||
|
@ -157,15 +183,15 @@ class MastodonLoginViewController: UIViewController {
|
||||||
|
|
||||||
switch completion {
|
switch completion {
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
// self.viewModel.error.send(error)
|
//TODO: @zeitschlag show error
|
||||||
break
|
break
|
||||||
case .finished:
|
case .finished:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} receiveValue: { [weak self] info in
|
} receiveValue: { [weak self] info in
|
||||||
guard let self, let appContext = self.appContext else { return }
|
guard let self else { return }
|
||||||
let authenticationController = MastodonAuthenticationController(
|
let authenticationController = MastodonAuthenticationController(
|
||||||
context: appContext,
|
context: self.context,
|
||||||
authenticateURL: info.authorizeURL
|
authenticateURL: info.authorizeURL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -204,6 +230,7 @@ class MastodonLoginViewController: UIViewController {
|
||||||
let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber
|
let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber
|
||||||
else { return }
|
else { return }
|
||||||
|
|
||||||
|
//FIXME: @zeitschlag on iPad
|
||||||
let adjustmentHeight = keyboardFrameValue.cgRectValue.height - view.safeAreaInsets.bottom
|
let adjustmentHeight = keyboardFrameValue.cgRectValue.height - view.safeAreaInsets.bottom
|
||||||
contentView.bottomConstraint?.constant = adjustmentHeight
|
contentView.bottomConstraint?.constant = adjustmentHeight
|
||||||
|
|
||||||
|
@ -237,7 +264,6 @@ extension MastodonLoginViewController: UITableViewDelegate {
|
||||||
viewModel.selectedServer = server
|
viewModel.selectedServer = server
|
||||||
|
|
||||||
contentView.searchTextField.text = server.domain
|
contentView.searchTextField.text = server.domain
|
||||||
//TODO: @zeitschlag filter server list
|
|
||||||
|
|
||||||
contentView.navigationActionView.nextButton.isEnabled = true
|
contentView.navigationActionView.nextButton.isEnabled = true
|
||||||
tableView.deselectRow(at: indexPath, animated: true)
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
|
|
|
@ -51,9 +51,7 @@ class MastodonLoginViewModel {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredServers = serverList.filter { $0.domain.contains(query) }.sorted {$0.totalUsers > $1.totalUsers }
|
filteredServers = serverList.filter { $0.domain.lowercased().contains(query) }.sorted {$0.totalUsers > $1.totalUsers }
|
||||||
delegate?.serversUpdated(self)
|
delegate?.serversUpdated(self)
|
||||||
|
|
||||||
// AuthenticationViewModel.parseDomain(from: query)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,6 @@ extension MastodonPickServerViewModel {
|
||||||
.compactMap { [weak self] searchText -> AnyPublisher<Result<Mastodon.Response.Content<[Mastodon.Entity.Server]>, Error>, Never>? in
|
.compactMap { [weak self] searchText -> AnyPublisher<Result<Mastodon.Response.Content<[Mastodon.Entity.Server]>, Error>, Never>? in
|
||||||
// Check if searchText is a valid mastodon server domain
|
// Check if searchText is a valid mastodon server domain
|
||||||
guard let self = self else { return nil }
|
guard let self = self else { return nil }
|
||||||
//TODO: @zeitschlag Also allow search for incomplete URLs?
|
|
||||||
guard let domain = AuthenticationViewModel.parseDomain(from: searchText) else {
|
guard let domain = AuthenticationViewModel.parseDomain(from: searchText) else {
|
||||||
return Just(Result.failure(APIService.APIError.implicit(.badRequest))).eraseToAnyPublisher()
|
return Just(Result.failure(APIService.APIError.implicit(.badRequest))).eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue