From f071b3b6839c240b3d8123c63b5091f1808e1278 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Wed, 9 Nov 2022 23:10:41 -0800 Subject: [PATCH] Edit profile link --- Localizations/de.lproj/Localizable.strings | 1 + Localizations/en.lproj/Localizable.strings | 1 + Localizations/es.lproj/Localizable.strings | 1 + Localizations/ja.lproj/Localizable.strings | 1 + Localizations/ko.lproj/Localizable.strings | 1 + Localizations/pl.lproj/Localizable.strings | 1 + Localizations/ru.lproj/Localizable.strings | 1 + .../zh-Hans.lproj/Localizable.strings | 1 + .../Services/AccountSettingsService.swift | 41 ------------------- .../AuthenticatedWebViewService.swift | 22 ++++++++++ .../View Models/NavigationViewModel.swift | 22 +++++++++- Views/SwiftUI/SecondaryNavigationView.swift | 11 ++++- 12 files changed, 61 insertions(+), 43 deletions(-) delete mode 100644 ServiceLayer/Sources/ServiceLayer/Services/AccountSettingsService.swift create mode 100644 ServiceLayer/Sources/ServiceLayer/Services/AuthenticatedWebViewService.swift diff --git a/Localizations/de.lproj/Localizable.strings b/Localizations/de.lproj/Localizable.strings index a3265ac..c2af9d3 100644 --- a/Localizations/de.lproj/Localizable.strings +++ b/Localizations/de.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "Über diese App"; "secondary-navigation.account-settings" = "Kontoeinstellungen"; "secondary-navigation.accounts" = "Accounts"; +"secondary-navigation.edit-profile" = "Profil bearbeiten"; "secondary-navigation.lists" = "Listen"; "secondary-navigation.my-profile" = "Mein Profil"; "secondary-navigation.preferences" = "Einstellungen"; diff --git a/Localizations/en.lproj/Localizable.strings b/Localizations/en.lproj/Localizable.strings index 4689fa2..6c924cf 100644 --- a/Localizations/en.lproj/Localizable.strings +++ b/Localizations/en.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "About This App"; "secondary-navigation.account-settings" = "Account Settings"; "secondary-navigation.accounts" = "Accounts"; +"secondary-navigation.edit-profile" = "Edit Profile"; "secondary-navigation.lists" = "Lists"; "secondary-navigation.my-profile" = "My Profile"; "secondary-navigation.preferences" = "Preferences"; diff --git a/Localizations/es.lproj/Localizable.strings b/Localizations/es.lproj/Localizable.strings index 8894b6d..0aebd56 100644 --- a/Localizations/es.lproj/Localizable.strings +++ b/Localizations/es.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "Acerca de esta aplicación"; "secondary-navigation.account-settings" = "Configuración de Cuenta"; "secondary-navigation.accounts" = "Cuentas"; +"secondary-navigation.edit-profile" = "Editar perfil"; "secondary-navigation.lists" = "Listas"; "secondary-navigation.my-profile" = "Mi perfil"; "secondary-navigation.preferences" = "Ajustes"; diff --git a/Localizations/ja.lproj/Localizable.strings b/Localizations/ja.lproj/Localizable.strings index 6e80048..e445772 100644 --- a/Localizations/ja.lproj/Localizable.strings +++ b/Localizations/ja.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "このアプリについて"; "secondary-navigation.account-settings" = "アカウント設定"; "secondary-navigation.accounts" = "アカウント"; +"secondary-navigation.edit-profile" = "プロフィール編集"; "secondary-navigation.lists" = "リスト"; "secondary-navigation.my-profile" = "マイプロフィール"; "secondary-navigation.preferences" = "環境設定"; diff --git a/Localizations/ko.lproj/Localizable.strings b/Localizations/ko.lproj/Localizable.strings index 805b1cb..e72de25 100644 --- a/Localizations/ko.lproj/Localizable.strings +++ b/Localizations/ko.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "이 앱에 대해서"; "secondary-navigation.account-settings" = "계정 설정"; "secondary-navigation.accounts" = "계정"; +"secondary-navigation.edit-profile" = "프로필 편집"; "secondary-navigation.lists" = "목록"; "secondary-navigation.my-profile" = "내 프로필"; "secondary-navigation.preferences" = "설정"; diff --git a/Localizations/pl.lproj/Localizable.strings b/Localizations/pl.lproj/Localizable.strings index a3ac58b..e72fb3c 100644 --- a/Localizations/pl.lproj/Localizable.strings +++ b/Localizations/pl.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "O aplikacji"; "secondary-navigation.account-settings" = "Ustawienia konta"; "secondary-navigation.accounts" = "Konta"; +"secondary-navigation.edit-profile" = "Edytuj profil"; "secondary-navigation.lists" = "Listy"; "secondary-navigation.my-profile" = "Mój profil"; "secondary-navigation.preferences" = "Właściwości"; diff --git a/Localizations/ru.lproj/Localizable.strings b/Localizations/ru.lproj/Localizable.strings index 9ac2a0d..945cc57 100644 --- a/Localizations/ru.lproj/Localizable.strings +++ b/Localizations/ru.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "О приложении"; "secondary-navigation.account-settings" = "Настройки аккаунта"; "secondary-navigation.accounts" = "Аккаунты"; +"secondary-navigation.edit-profile" = "Редактировать профиль"; "secondary-navigation.lists" = "Списки"; "secondary-navigation.my-profile" = "Профиль"; "secondary-navigation.preferences" = "Настройки"; diff --git a/Localizations/zh-Hans.lproj/Localizable.strings b/Localizations/zh-Hans.lproj/Localizable.strings index 76c88d0..646958d 100644 --- a/Localizations/zh-Hans.lproj/Localizable.strings +++ b/Localizations/zh-Hans.lproj/Localizable.strings @@ -162,6 +162,7 @@ "secondary-navigation.about" = "关于这个应用"; "secondary-navigation.account-settings" = "账号设置"; "secondary-navigation.accounts" = "账户"; +"secondary-navigation.edit-profile" = "修改个人资料"; "secondary-navigation.lists" = "列表"; "secondary-navigation.my-profile" = "我的个人资料"; "secondary-navigation.preferences" = "偏好设置"; diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AccountSettingsService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AccountSettingsService.swift deleted file mode 100644 index 4a0e7d0..0000000 --- a/ServiceLayer/Sources/ServiceLayer/Services/AccountSettingsService.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// File.swift -// -// -// Created by Justin Mazzocchi on 11/8/22. -// - -import Combine -import Foundation - -public struct AccountSettingsService { - private let instanceURI: String - private let webAuthSessionType: WebAuthSession.Type - private let webAuthSessionContextProvider = WebAuthSessionContextProvider() - - public init(instanceURI: String, environment: AppEnvironment) { - self.instanceURI = instanceURI - webAuthSessionType = environment.webAuthSessionType - } -} - -public extension AccountSettingsService { - func openAccountSettings() -> AnyPublisher { - guard let url = URL(string: "https://\(instanceURI)/auth/edit") else { - return Fail(error: URLError(.badURL)).eraseToAnyPublisher() - } - - print(webAuthSessionContextProvider) - - return webAuthSessionType.publisher( - url: url, - callbackURLScheme: nil, - presentationContextProvider: webAuthSessionContextProvider) - } -} - -private extension AccountSettingsService { - func accountSettingsURL(instanceURI: String) -> URL? { - URL(string: "https://\(instanceURI)/auth/edit") - } -} diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AuthenticatedWebViewService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AuthenticatedWebViewService.swift new file mode 100644 index 0000000..67f15c7 --- /dev/null +++ b/ServiceLayer/Sources/ServiceLayer/Services/AuthenticatedWebViewService.swift @@ -0,0 +1,22 @@ +// Copyright © 2020 Metabolist. All rights reserved. + +import Combine +import Foundation + +public struct AuthenticatedWebViewService { + private let environment: AppEnvironment + private let webAuthSessionContextProvider = WebAuthSessionContextProvider() + + public init(environment: AppEnvironment) { + self.environment = environment + } +} + +public extension AuthenticatedWebViewService { + func authenticatedWebViewPublisher(url: URL) -> AnyPublisher { + environment.webAuthSessionType.publisher( + url: url, + callbackURLScheme: nil, + presentationContextProvider: webAuthSessionContextProvider) + } +} diff --git a/ViewModels/Sources/ViewModels/View Models/NavigationViewModel.swift b/ViewModels/Sources/ViewModels/View Models/NavigationViewModel.swift index ab37a22..fd61923 100644 --- a/ViewModels/Sources/ViewModels/View Models/NavigationViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/NavigationViewModel.swift @@ -106,8 +106,18 @@ public extension NavigationViewModel { navigationsSubject.send(.profile(identityContext.service.navigationService.profileService(id: id))) } + func navigateToEditProfile(instanceURI: String) { + guard let editProfileURL = editProfileURL(instanceURI: instanceURI) else { return } + + AuthenticatedWebViewService(environment: environment).authenticatedWebViewPublisher(url: editProfileURL) + .sink { _ in } receiveValue: { _ in } + .store(in: &cancellables) + } + func navigateToAccountSettings(instanceURI: String) { - AccountSettingsService(instanceURI: instanceURI, environment: environment).openAccountSettings() + guard let accountSettingsURL = accountSettingsURL(instanceURI: instanceURI) else { return } + + AuthenticatedWebViewService(environment: environment).authenticatedWebViewPublisher(url: accountSettingsURL) .sink { _ in } receiveValue: { _ in } .store(in: &cancellables) } @@ -211,3 +221,13 @@ public extension NavigationViewModel { identityContext: identityContext) } } + +private extension NavigationViewModel { + func accountSettingsURL(instanceURI: String) -> URL? { + URL(string: "https://\(instanceURI)/auth/edit") + } + + func editProfileURL(instanceURI: String) -> URL? { + URL(string: "https://\(instanceURI)/settings/profile") + } +} diff --git a/Views/SwiftUI/SecondaryNavigationView.swift b/Views/SwiftUI/SecondaryNavigationView.swift index b49a818..f5e51d1 100644 --- a/Views/SwiftUI/SecondaryNavigationView.swift +++ b/Views/SwiftUI/SecondaryNavigationView.swift @@ -23,13 +23,22 @@ struct SecondaryNavigationView: View { } } if let instanceURI = viewModel.identityContext.identity.instance?.uri { + Button { + viewModel.navigateToEditProfile(instanceURI: instanceURI) + } label: { + Label { + Text("secondary-navigation.edit-profile").foregroundColor(.primary) + } icon: { + Image(systemName: "pencil") + } + } Button { viewModel.navigateToAccountSettings(instanceURI: instanceURI) } label: { Label { Text("secondary-navigation.account-settings").foregroundColor(.primary) } icon: { - Image(systemName: "person.crop.square") + Image(systemName: "person.crop.square.filled.and.at.rectangle") } } }