diff options
Diffstat (limited to 'Hutch/Views/Projects/ProjectMailingListView.swift')
| -rw-r--r-- | Hutch/Views/Projects/ProjectMailingListView.swift | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Hutch/Views/Projects/ProjectMailingListView.swift b/Hutch/Views/Projects/ProjectMailingListView.swift index 478e471..4ff93e9 100644 --- a/Hutch/Views/Projects/ProjectMailingListView.swift +++ b/Hutch/Views/Projects/ProjectMailingListView.swift @@ -229,6 +229,17 @@ struct MailingListDetailView: View { @Environment(AppState.self) private var appState @State private var viewModel: MailingListDetailViewModel? + @State private var pinChangeCount = 0 + + private var currentUserKey: String? { + appState.currentUser?.canonicalName + } + + private var isPinnedToHome: Bool { + _ = pinChangeCount + guard let currentUserKey else { return false } + return HomePinStore.isPinned(.mailingList(mailingList), for: currentUserKey, defaults: appState.accountDefaults) + } var body: some View { Group { @@ -240,6 +251,18 @@ struct MailingListDetailView: View { } .navigationTitle(mailingList.name) .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 { if viewModel == nil { let viewModel = MailingListDetailViewModel( @@ -260,6 +283,12 @@ struct MailingListDetailView: View { } } + private func togglePinnedState() { + guard let currentUserKey else { return } + HomePinStore.togglePin(.mailingList(mailingList), for: currentUserKey, defaults: appState.accountDefaults) + pinChangeCount += 1 + } + @ViewBuilder private func content(_ viewModel: MailingListDetailViewModel) -> some View { @Bindable var vm = viewModel |
