diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index ad5c7b7e..b2572b64 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -52,6 +52,7 @@ struct ContentView: View { @State private var expandedMessageIDs: Set = [] @State private var showLocationNotes = false @State private var notesGeohash: String? = nil + @State private var sheetNotesCount: Int = 0 // Timer-based refresh removed; use LocationChannelManager live updates instead // Window sizes for rendering (infinite scroll up) @State private var windowCountPublic: Int = 300 @@ -1185,7 +1186,7 @@ struct ContentView: View { showLocationNotes = true }) { HStack(alignment: .center, spacing: 4) { - let hasNotes = (notesCounter.count ?? 0) > 0 + let hasNotes = ((notesCounter.count ?? 0) > 0) || (sheetNotesCount > 0) Image(systemName: "long.text.page.and.pencil") .font(.system(size: 12)) .foregroundColor(hasNotes ? Color(hue: 0.60, saturation: 0.85, brightness: 0.82) : Color.gray) @@ -1234,7 +1235,7 @@ struct ContentView: View { .sheet(isPresented: $showLocationNotes) { Group { if let gh = notesGeohash ?? LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash { - LocationNotesView(geohash: gh) + LocationNotesView(geohash: gh, onNotesCountChanged: { cnt in sheetNotesCount = cnt }) .environmentObject(viewModel) } else { VStack(spacing: 12) { @@ -1276,6 +1277,7 @@ struct ContentView: View { } .onDisappear { LocationChannelManager.shared.endLiveRefresh() + sheetNotesCount = 0 } .onChange(of: locationManager.availableChannels) { channels in if let current = channels.first(where: { $0.level == .building })?.geohash, diff --git a/bitchat/Views/LocationNotesView.swift b/bitchat/Views/LocationNotesView.swift index 52ecc4bb..8f05ca90 100644 --- a/bitchat/Views/LocationNotesView.swift +++ b/bitchat/Views/LocationNotesView.swift @@ -4,15 +4,17 @@ struct LocationNotesView: View { @EnvironmentObject var viewModel: ChatViewModel @StateObject private var manager: LocationNotesManager let geohash: String + let onNotesCountChanged: ((Int) -> Void)? @Environment(\.colorScheme) var colorScheme @ObservedObject private var locationManager = LocationChannelManager.shared @Environment(\.dismiss) private var dismiss @State private var draft: String = "" - init(geohash: String) { + init(geohash: String, onNotesCountChanged: ((Int) -> Void)? = nil) { let gh = geohash.lowercased() self.geohash = gh + self.onNotesCountChanged = onNotesCountChanged _manager = StateObject(wrappedValue: LocationNotesManager(geohash: gh)) } @@ -40,6 +42,10 @@ struct LocationNotesView: View { .onChange(of: geohash) { newValue in manager.setGeohash(newValue) } + .onAppear { onNotesCountChanged?(manager.notes.count) } + .onChange(of: manager.notes.count) { newValue in + onNotesCountChanged?(newValue) + } } private var header: some View {