diff options
Diffstat (limited to 'Hutch/Views/Lookup')
| -rw-r--r-- | Hutch/Views/Lookup/UserProfileView.swift | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Hutch/Views/Lookup/UserProfileView.swift b/Hutch/Views/Lookup/UserProfileView.swift index 84375de..4fbb5a0 100644 --- a/Hutch/Views/Lookup/UserProfileView.swift +++ b/Hutch/Views/Lookup/UserProfileView.swift @@ -6,6 +6,7 @@ struct UserProfileView: View { let user: User @State private var profileViewModel: UserProfileViewModel? + @State private var pinChangeCount = 0 private static let iso8601Formatter: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() @@ -14,6 +15,16 @@ struct UserProfileView: View { return formatter }() + private var currentUserKey: String? { + appState.currentUser?.canonicalName + } + + private var isPinnedToHome: Bool { + _ = pinChangeCount + guard let currentUserKey else { return false } + return HomePinStore.isPinned(.user(user), for: currentUserKey, defaults: appState.accountDefaults) + } + var body: some View { List { if let avatarURL = user.avatar.flatMap(URL.init(string:)) { @@ -164,6 +175,18 @@ struct UserProfileView: View { .listStyle(.insetGrouped) .navigationTitle(user.canonicalName) .navigationBarTitleDisplayMode(.inline) + .toolbar { + if currentUserKey != nil { + ToolbarItem(placement: .topBarTrailing) { + Button { + togglePinnedState() + } label: { + Image(systemName: isPinnedToHome ? "pin.fill" : "pin") + } + .accessibilityLabel(isPinnedToHome ? "Unpin from Home" : "Pin to Home") + } + } + } .task(id: user.canonicalName) { let owner = user.canonicalName.hasPrefix("~") ? String(user.canonicalName.dropFirst()) @@ -200,6 +223,12 @@ struct UserProfileView: View { } } + private func togglePinnedState() { + guard let currentUserKey else { return } + HomePinStore.togglePin(.user(user), for: currentUserKey, defaults: appState.accountDefaults) + pinChangeCount += 1 + } + private func formattedTimestamp(_ value: String) -> String { guard let date = Self.iso8601Formatter.date(from: value) else { return value |
