Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Add link to account settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jzzocc committed Nov 8, 2022
1 parent 2497dae commit dd47dc6
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 8 deletions.
1 change: 1 addition & 0 deletions Localizations/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "Ich stimme den Serverregeln und Nutzungsbedingungen zu";
"registration.password-confirmation-mismatch" = "Das Passwort und die Passwortbestätigung stimmen nicht überein";
"secondary-navigation.about" = "Über diese App";
"secondary-navigation.account-settings" = "Kontoeinstellungen";
"secondary-navigation.accounts" = "Accounts";
"secondary-navigation.lists" = "Listen";
"secondary-navigation.my-profile" = "Mein Profil";
Expand Down
1 change: 1 addition & 0 deletions Localizations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "I agree to the server rules and terms of service";
"registration.password-confirmation-mismatch" = "Password and password confirmation do not match";
"secondary-navigation.about" = "About This App";
"secondary-navigation.account-settings" = "Account Settings";
"secondary-navigation.accounts" = "Accounts";
"secondary-navigation.lists" = "Lists";
"secondary-navigation.my-profile" = "My Profile";
Expand Down
1 change: 1 addition & 0 deletions Localizations/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "Estoy de acuerdo con las reglas del servidor y los términos del servicio";
"registration.password-confirmation-mismatch" = "La contraseña no coincide con su confirmación";
"secondary-navigation.about" = "Acerca de esta aplicación";
"secondary-navigation.account-settings" = "Configuración de Cuenta";
"secondary-navigation.accounts" = "Cuentas";
"secondary-navigation.lists" = "Listas";
"secondary-navigation.my-profile" = "Mi perfil";
Expand Down
1 change: 1 addition & 0 deletions Localizations/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "サーバーのルールとプライバシーポリシーに同意します";
"registration.password-confirmation-mismatch" = "パスワードと確認用パスワードが一致しません";
"secondary-navigation.about" = "このアプリについて";
"secondary-navigation.account-settings" = "アカウント設定";
"secondary-navigation.accounts" = "アカウント";
"secondary-navigation.lists" = "リスト";
"secondary-navigation.my-profile" = "マイプロフィール";
Expand Down
1 change: 1 addition & 0 deletions Localizations/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "서버 규칙 및 개인정보처리방침에 동의해요";
"registration.password-confirmation-mismatch" = "입력한 비밀번호가 일치하지 않아요";
"secondary-navigation.about" = "이 앱에 대해서";
"secondary-navigation.account-settings" = "계정 설정";
"secondary-navigation.accounts" = "계정";
"secondary-navigation.lists" = "목록";
"secondary-navigation.my-profile" = "내 프로필";
Expand Down
1 change: 1 addition & 0 deletions Localizations/pl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "Zgadzam się na zasady stosowane na serwerze i warunki świadczenia usługi";
"registration.password-confirmation-mismatch" = "Hasło i powtórzone hasło się nie zgadzają";
"secondary-navigation.about" = "O aplikacji";
"secondary-navigation.account-settings" = "Ustawienia konta";
"secondary-navigation.accounts" = "Konta";
"secondary-navigation.lists" = "Listy";
"secondary-navigation.my-profile" = "Mój profil";
Expand Down
1 change: 1 addition & 0 deletions Localizations/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "Я принимаю правила сервера и условия предоставления услуг";
"registration.password-confirmation-mismatch" = "Пароли не совпадают";
"secondary-navigation.about" = "О приложении";
"secondary-navigation.account-settings" = "Настройки аккаунта";
"secondary-navigation.accounts" = "Аккаунты";
"secondary-navigation.lists" = "Списки";
"secondary-navigation.my-profile" = "Профиль";
Expand Down
1 change: 1 addition & 0 deletions Localizations/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"registration.agree-to-server-rules-and-terms-of-service" = "我同意实例规则和服务条款";
"registration.password-confirmation-mismatch" = "密码和确认密码不匹配";
"secondary-navigation.about" = "关于这个应用";
"secondary-navigation.account-settings" = "账号设置";
"secondary-navigation.accounts" = "账户";
"secondary-navigation.lists" = "列表";
"secondary-navigation.my-profile" = "我的个人资料";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// 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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ extension WebAuthSession {
}
}

webAuthSession.presentationContextProvider = presentationContextProvider

DispatchQueue.main.async {
webAuthSession.presentationContextProvider = presentationContextProvider
webAuthSession.start()
}
}
Expand Down
4 changes: 4 additions & 0 deletions ViewModels/Sources/PreviewViewModels/PreviewViewModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ extension ContentDatabase {
keychain: MockKeychain.self)
}

public extension AppEnvironment {
static let preview = environment
}

public extension URL {
static let previewInstanceURL = URL(string: "https://mastodon.social")!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public final class NavigationViewModel: ObservableObject {
@Published public var alertItem: AlertItem?

private let navigationsSubject = PassthroughSubject<Navigation, Never>()
private let environment: AppEnvironment
private var cancellables = Set<AnyCancellable>()

public init(identityContext: IdentityContext) {
public init(identityContext: IdentityContext, environment: AppEnvironment) {
self.identityContext = identityContext
self.environment = environment
navigations = navigationsSubject.eraseToAnyPublisher()

identityContext.$identity
Expand Down Expand Up @@ -104,6 +106,12 @@ public extension NavigationViewModel {
navigationsSubject.send(.profile(identityContext.service.navigationService.profileService(id: id)))
}

func navigateToAccountSettings(instanceURI: String) {
AccountSettingsService(instanceURI: instanceURI, environment: environment).openAccountSettings()
.sink { _ in } receiveValue: { _ in }
.store(in: &cancellables)
}

func navigate(timeline: Timeline) {
presentingSecondaryNavigation = false
presentedNewStatusViewModel = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private extension RootViewModel {
self.notifyIdentityChange(identityContext: identityContext)
}

return NavigationViewModel(identityContext: identityContext)
return NavigationViewModel(identityContext: identityContext, environment: self.environment)
}
.assign(to: &$navigationViewModel)
}
Expand Down
2 changes: 1 addition & 1 deletion Views/SwiftUI/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import PreviewViewModels

struct AboutView_Previews: PreviewProvider {
static var previews: some View {
AboutView(viewModel: NavigationViewModel(identityContext: .preview))
AboutView(viewModel: NavigationViewModel(identityContext: .preview, environment: .preview))
}
}
#endif
2 changes: 1 addition & 1 deletion Views/SwiftUI/ListsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import PreviewViewModels
struct ListsView_Previews: PreviewProvider {
static var previews: some View {
ListsView(viewModel: .init(identityContext: .preview))
.environmentObject(NavigationViewModel(identityContext: .preview))
.environmentObject(NavigationViewModel(identityContext: .preview, environment: .preview))
}
}
#endif
13 changes: 12 additions & 1 deletion Views/SwiftUI/SecondaryNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ struct SecondaryNavigationView: View {
}
}
}
if let instanceURI = viewModel.identityContext.identity.instance?.uri {
Button {
viewModel.navigateToAccountSettings(instanceURI: instanceURI)
} label: {
Label {
Text("secondary-navigation.account-settings").foregroundColor(.primary)
} icon: {
Image(systemName: "person.crop.square")
}
}
}
NavigationLink(
destination: IdentitiesView { .init(identityContext: viewModel.identityContext) }
.environmentObject(rootViewModel)) {
Expand Down Expand Up @@ -84,7 +95,7 @@ import PreviewViewModels

struct SecondaryNavigationView_Previews: PreviewProvider {
static var previews: some View {
SecondaryNavigationView(viewModel: NavigationViewModel(identityContext: .preview))
SecondaryNavigationView(viewModel: NavigationViewModel(identityContext: .preview, environment: .preview))
.environmentObject(RootViewModel.preview)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import PreviewViewModels

struct MainNavigationView_Previews: PreviewProvider {
static var previews: some View {
MainNavigationView { NavigationViewModel(identityContext: .preview) }
MainNavigationView { NavigationViewModel(identityContext: .preview, environment: .preview) }
.environmentObject(RootViewModel.preview)
}
}
Expand Down

0 comments on commit dd47dc6

Please sign in to comment.