Change "Delete" to "Log out"

This commit is contained in:
Justin Mazzocchi 2021-02-21 15:18:52 -08:00
parent beee1ff73b
commit ca04939ad5
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
3 changed files with 25 additions and 16 deletions

View File

@ -18,13 +18,10 @@ final class IdentitiesDataSource: UITableViewDiffableDataSource<IdentitiesSectio
private let updateQueue =
DispatchQueue(label: "com.metabolist.metatext.identities-data-source.update-queue")
private var cancellables = Set<AnyCancellable>()
private let deleteAction: (Identity) -> Void
init(tableView: UITableView,
publisher: AnyPublisher<[Identity], Never>,
viewModelProvider: @escaping (Identity) -> IdentityViewModel,
deleteAction: @escaping (Identity) -> Void) {
self.deleteAction = deleteAction
viewModelProvider: @escaping (Identity) -> IdentityViewModel) {
tableView.register(UITableViewCell.self,
forCellReuseIdentifier: String(describing: UITableViewCell.self))
@ -79,16 +76,6 @@ final class IdentitiesDataSource: UITableViewDiffableDataSource<IdentitiesSectio
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
itemIdentifier(for: indexPath) != .add
}
override func tableView(_ tableView: UITableView,
commit editingStyle: UITableViewCell.EditingStyle,
forRowAt indexPath: IndexPath) {
guard editingStyle == .delete,
case let .identitiy(identity) = itemIdentifier(for: indexPath)
else { return }
deleteAction(identity)
}
}
private extension IdentitiesDataSource {

View File

@ -147,6 +147,7 @@
"secondary-navigation-button.accessibility-title" = "Account Menu";
"identities.accounts" = "Accounts";
"identities.browsing" = "Browsing";
"identities.log-out" = "Log out";
"identities.pending" = "Pending";
"lists.new-list-title" = "New List Title";
"load-more" = "Load More";

View File

@ -10,8 +10,7 @@ final class IdentitiesViewController: UITableViewController {
private lazy var dataSource: IdentitiesDataSource = {
.init(tableView: tableView,
publisher: viewModel.$identities.eraseToAnyPublisher(),
viewModelProvider: viewModel.viewModel(identity:),
deleteAction: { [weak self] in self?.rootViewModel.deleteIdentity(id: $0.id) })
viewModelProvider: viewModel.viewModel(identity:))
}()
init(viewModel: IdentitiesViewModel, rootViewModel: RootViewModel) {
@ -60,4 +59,26 @@ final class IdentitiesViewController: UITableViewController {
rootViewModel.identitySelected(id: identityViewModel.id)
}
}
override func tableView(
_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard dataSource.itemIdentifier(for: indexPath) != .add else { return nil }
let logOutAction = UIContextualAction(
style: .destructive,
title: NSLocalizedString("identities.log-out", comment: "")) { [weak self] _, _, completionHandler in
guard let self = self, case let .identitiy(identity) = self.dataSource.itemIdentifier(for: indexPath) else {
completionHandler(false)
return
}
self.rootViewModel.deleteIdentity(id: identity.id)
completionHandler(true)
}
return UISwipeActionsConfiguration(actions: [logOutAction])
}
}