From 1189e5f3d0617ad4a6f12f28b72cb6907db08ac9 Mon Sep 17 00:00:00 2001 From: Jon Petersson Date: Thu, 15 Feb 2024 17:28:00 +0100 Subject: [PATCH] Allow deleting custom lists --- .../CustomListRepository.swift | 2 +- .../AddCustomListCoordinator.swift | 4 +-- .../CustomListViewController.swift | 29 ++++++++++++++----- .../EditCustomListCoordinator.swift | 8 ++--- .../SelectLocationCoordinator.swift | 2 -- .../Edit/EditAccessMethodViewController.swift | 2 +- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ios/MullvadSettings/CustomListRepository.swift b/ios/MullvadSettings/CustomListRepository.swift index deb0162d160e..2170bfe0f350 100644 --- a/ios/MullvadSettings/CustomListRepository.swift +++ b/ios/MullvadSettings/CustomListRepository.swift @@ -18,7 +18,7 @@ public enum CustomRelayListError: LocalizedError, Equatable { switch self { case .duplicateName: NSLocalizedString( - "DUPLICATE_CUSTOM_LIST_ERROR", + "DUPLICATE_CUSTOM_LISTS_ERROR", tableName: "CustomListRepository", value: "Name is already taken.", comment: "" diff --git a/ios/MullvadVPN/Coordinators/CustomLists/AddCustomListCoordinator.swift b/ios/MullvadVPN/Coordinators/CustomLists/AddCustomListCoordinator.swift index c85147f37c7c..6692471ba443 100644 --- a/ios/MullvadVPN/Coordinators/CustomLists/AddCustomListCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/CustomLists/AddCustomListCoordinator.swift @@ -42,14 +42,14 @@ class AddCustomListCoordinator: Coordinator, Presentable, Presenting { controller.delegate = self controller.navigationItem.title = NSLocalizedString( - "CUSTOM_LIST_NAVIGATION_EDIT_TITLE", + "CUSTOM_LISTS_NAVIGATION_EDIT_TITLE", tableName: "CustomLists", value: "New custom list", comment: "" ) controller.saveBarButton.title = NSLocalizedString( - "CUSTOM_LIST_NAVIGATION_CREATE_BUTTON", + "CUSTOM_LISTS_NAVIGATION_CREATE_BUTTON", tableName: "CustomLists", value: "Create", comment: "" diff --git a/ios/MullvadVPN/Coordinators/CustomLists/CustomListViewController.swift b/ios/MullvadVPN/Coordinators/CustomLists/CustomListViewController.swift index e171bf66245f..f14213ed29db 100644 --- a/ios/MullvadVPN/Coordinators/CustomLists/CustomListViewController.swift +++ b/ios/MullvadVPN/Coordinators/CustomLists/CustomListViewController.swift @@ -158,26 +158,39 @@ class CustomListViewController: UIViewController { } private func onDelete() { - // TODO: Show error dialog. - delegate?.customListDidDelete() + showDeleteAlert() } - private func showSaveErrorAlert() { + private func showDeleteAlert() { let presentation = AlertPresentation( - id: "api-custom-lists-save-list-alert", + id: "api-custom-lists-delete-list-alert", icon: .alert, message: NSLocalizedString( - "CUSTOM_LISTS_SAVE_ERROR_PROMPT", + "CUSTOM_LISTS_DELETE_PROMPT", tableName: "APIAccess", - value: "List name is already taken.", + value: "Delete \(subject.value.name)?", comment: "" ), buttons: [ AlertAction( title: NSLocalizedString( - "CUSTOM_LISTS_OK_BUTTON", + "CUSTOM_LISTS_DELETE_BUTTON", tableName: "APIAccess", - value: "Got it!", + value: "Delete", + comment: "" + ), + style: .destructive, + handler: { + self.interactor.deleteCustomList(id: self.subject.value.id) + self.dismiss(animated: true) + self.delegate?.customListDidDelete() + } + ), + AlertAction( + title: NSLocalizedString( + "CUSTOM_LISTS_CANCEL_BUTTON", + tableName: "APIAccess", + value: "Cancel", comment: "" ), style: .default diff --git a/ios/MullvadVPN/Coordinators/CustomLists/EditCustomListCoordinator.swift b/ios/MullvadVPN/Coordinators/CustomLists/EditCustomListCoordinator.swift index 2da41754b873..5bab11701269 100644 --- a/ios/MullvadVPN/Coordinators/CustomLists/EditCustomListCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/CustomLists/EditCustomListCoordinator.swift @@ -29,12 +29,12 @@ class EditCustomListCoordinator: Coordinator, Presentable, Presenting { self.customListInteractor = customListInteractor } - func start() { + func start(customList: CustomList) { let subject = CurrentValueSubject( CustomListViewModel( - id: UUID(), - name: "A list", - locations: [], + id: customList.id, + name: customList.name, + locations: customList.locations, tableSections: [.name, .editLocations, .deleteList] ) ) diff --git a/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift b/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift index dcaf47347d87..b421067ca94c 100644 --- a/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift @@ -11,8 +11,6 @@ import MullvadTypes import Routing import UIKit -import MullvadSettings - class SelectLocationCoordinator: Coordinator, Presentable, Presenting, RelayCacheTrackerObserver { private let tunnelManager: TunnelManager private let relayCacheTracker: RelayCacheTracker diff --git a/ios/MullvadVPN/Coordinators/Settings/APIAccess/Edit/EditAccessMethodViewController.swift b/ios/MullvadVPN/Coordinators/Settings/APIAccess/Edit/EditAccessMethodViewController.swift index e7606d3c8108..55a907677aa8 100644 --- a/ios/MullvadVPN/Coordinators/Settings/APIAccess/Edit/EditAccessMethodViewController.swift +++ b/ios/MullvadVPN/Coordinators/Settings/APIAccess/Edit/EditAccessMethodViewController.swift @@ -333,7 +333,7 @@ class EditAccessMethodViewController: UITableViewController { id: "api-access-methods-delete-method-alert", icon: .alert, message: NSLocalizedString( - "METHOD_SETTINGS_SAVE_PROMPT", + "METHOD_SETTINGS_DELETE_PROMPT", tableName: "APIAccess", value: "Delete \(methodName)?", comment: ""