Change "Delete" to "Log out"
This commit is contained in:
parent
beee1ff73b
commit
ca04939ad5
|
@ -18,13 +18,10 @@ final class IdentitiesDataSource: UITableViewDiffableDataSource<IdentitiesSectio
|
||||||
private let updateQueue =
|
private let updateQueue =
|
||||||
DispatchQueue(label: "com.metabolist.metatext.identities-data-source.update-queue")
|
DispatchQueue(label: "com.metabolist.metatext.identities-data-source.update-queue")
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
private let deleteAction: (Identity) -> Void
|
|
||||||
|
|
||||||
init(tableView: UITableView,
|
init(tableView: UITableView,
|
||||||
publisher: AnyPublisher<[Identity], Never>,
|
publisher: AnyPublisher<[Identity], Never>,
|
||||||
viewModelProvider: @escaping (Identity) -> IdentityViewModel,
|
viewModelProvider: @escaping (Identity) -> IdentityViewModel) {
|
||||||
deleteAction: @escaping (Identity) -> Void) {
|
|
||||||
self.deleteAction = deleteAction
|
|
||||||
|
|
||||||
tableView.register(UITableViewCell.self,
|
tableView.register(UITableViewCell.self,
|
||||||
forCellReuseIdentifier: String(describing: 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 {
|
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
|
||||||
itemIdentifier(for: indexPath) != .add
|
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 {
|
private extension IdentitiesDataSource {
|
||||||
|
|
|
@ -147,6 +147,7 @@
|
||||||
"secondary-navigation-button.accessibility-title" = "Account Menu";
|
"secondary-navigation-button.accessibility-title" = "Account Menu";
|
||||||
"identities.accounts" = "Accounts";
|
"identities.accounts" = "Accounts";
|
||||||
"identities.browsing" = "Browsing";
|
"identities.browsing" = "Browsing";
|
||||||
|
"identities.log-out" = "Log out";
|
||||||
"identities.pending" = "Pending";
|
"identities.pending" = "Pending";
|
||||||
"lists.new-list-title" = "New List Title";
|
"lists.new-list-title" = "New List Title";
|
||||||
"load-more" = "Load More";
|
"load-more" = "Load More";
|
||||||
|
|
|
@ -10,8 +10,7 @@ final class IdentitiesViewController: UITableViewController {
|
||||||
private lazy var dataSource: IdentitiesDataSource = {
|
private lazy var dataSource: IdentitiesDataSource = {
|
||||||
.init(tableView: tableView,
|
.init(tableView: tableView,
|
||||||
publisher: viewModel.$identities.eraseToAnyPublisher(),
|
publisher: viewModel.$identities.eraseToAnyPublisher(),
|
||||||
viewModelProvider: viewModel.viewModel(identity:),
|
viewModelProvider: viewModel.viewModel(identity:))
|
||||||
deleteAction: { [weak self] in self?.rootViewModel.deleteIdentity(id: $0.id) })
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
init(viewModel: IdentitiesViewModel, rootViewModel: RootViewModel) {
|
init(viewModel: IdentitiesViewModel, rootViewModel: RootViewModel) {
|
||||||
|
@ -60,4 +59,26 @@ final class IdentitiesViewController: UITableViewController {
|
||||||
rootViewModel.identitySelected(id: identityViewModel.id)
|
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])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue