From 05053c661dff0036d5a26c384d353561d861fda8 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Mon, 16 Jan 2023 13:39:35 +0100 Subject: [PATCH] Editor: Allow to select account --- .../AppAccount/AppAccountsSelectorView.swift | 23 +++++++++++++------ .../Status/Editor/StatusEditorView.swift | 5 +++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift index 4c7f0dbc..2fcd14ec 100644 --- a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift +++ b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift @@ -10,8 +10,15 @@ public struct AppAccountsSelectorView: View { @State private var accountsViewModel: [AppAccountViewModel] = [] - public init(routeurPath: RouterPath) { + private let accountCreationEnabled: Bool + private let avatarSize: AvatarView.Size + + public init(routeurPath: RouterPath, + accountCreationEnabled: Bool = true, + avatarSize: AvatarView.Size = .badge) { self.routeurPath = routeurPath + self.accountCreationEnabled = accountCreationEnabled + self.avatarSize = avatarSize } public var body: some View { @@ -35,15 +42,17 @@ public struct AppAccountsSelectorView: View { } } } - Divider() - Button { - routeurPath.presentedSheet = .addAccount - } label: { - Label("Add Account", systemImage: "person.badge.plus") + if accountCreationEnabled { + Divider() + Button { + routeurPath.presentedSheet = .addAccount + } label: { + Label("Add Account", systemImage: "person.badge.plus") + } } } label: { if let avatar = currentAccount.account?.avatar { - AvatarView(url: avatar, size: .badge) + AvatarView(url: avatar, size: avatarSize) } else { EmptyView() } diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorView.swift b/Packages/Status/Sources/Status/Editor/StatusEditorView.swift index c8a07db4..85035520 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorView.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorView.swift @@ -9,6 +9,7 @@ import PhotosUI import NukeUI import EmojiText import UIKit +import AppAccount public struct StatusEditorView: View { @EnvironmentObject private var preferences: UserPreferences @@ -156,7 +157,9 @@ public struct StatusEditorView: View { private var accountHeaderView: some View { if let account = currentAccount.account { HStack { - AvatarView(url: account.avatar, size: .status) + AppAccountsSelectorView(routeurPath: RouterPath(), + accountCreationEnabled: false, + avatarSize: .status) VStack(alignment: .leading, spacing: 4) { privacyMenu Text("@\(account.acct)")