diff --git a/Outpost/Features/Collections/DocumentReaderView.swift b/Outpost/Features/Collections/DocumentReaderView.swift index fedb00d..4b6c6d5 100644 --- a/Outpost/Features/Collections/DocumentReaderView.swift +++ b/Outpost/Features/Collections/DocumentReaderView.swift @@ -127,6 +127,13 @@ struct DocumentReaderView: View { } label: { Image(systemName: "ellipsis.circle") } + // SwiftUI's macOS `Menu` doesn't reliably re-evaluate a + // `Toggle`'s checkmark against updated @Observable state on + // its own — without a fresh `.id()` per state combination, + // toggling Subscribed/Viewer Insights/Full Width kept + // showing the pre-toggle checkmark until the whole view was + // torn down and rebuilt (e.g. navigating away and back). + .id(menuIdentity) } } .task { await viewModel.loadFullContent() } @@ -205,6 +212,19 @@ struct DocumentReaderView: View { } } + /// Every toggle-backed piece of state shown as a checkmark inside + /// `menuContent` — see the `.id()` comment on the `Menu` above. + private var menuIdentity: String { + [ + starStore.isStarred(documentId: viewModel.documentId), + viewModel.isSubscribed, + viewModel.isPinned, + viewModel.isInsightsEnabled ?? false, + viewModel.isFullWidth, + viewModel.isEditing + ].map(String.init).joined(separator: "-") + } + @ViewBuilder private var viewerAvatars: some View { if !viewModel.viewers.isEmpty {