mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-21 21:26:26 +00:00
Change "Delete" to "Log out"
This commit is contained in:
parent
beee1ff73b
commit
ca04939ad5
3 changed files with 25 additions and 16 deletions
|
@ -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 {
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue