Edit profile link

This commit is contained in:
Justin Mazzocchi 2022-11-09 23:10:41 -08:00
parent b7644cdd62
commit f071b3b683
12 changed files with 61 additions and 43 deletions

View file

@ -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";

View file

@ -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";

View file

@ -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";

View file

@ -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" = "環境設定";

View file

@ -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" = "설정";

View file

@ -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";

View file

@ -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" = "Настройки";

View file

@ -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" = "偏好设置";

View file

@ -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<URL, Error> {
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")
}
}

View file

@ -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<URL, Error> {
environment.webAuthSessionType.publisher(
url: url,
callbackURLScheme: nil,
presentationContextProvider: webAuthSessionContextProvider)
}
}

View file

@ -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")
}
}

View file

@ -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")
}
}
}