Fix occasional stale timeline issue

Changelog-Changed: Added UX hint to make it easier to load new notes
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-09-03 11:37:43 -07:00
parent c43a37d2d3
commit 4478672c10
4 changed files with 27 additions and 10 deletions

View File

@@ -66,7 +66,7 @@ struct FollowPackTimelineView<Content: View>: View {
.coordinateSpace(name: "scroll")
.onReceive(handle_notify(.scroll_to_top)) { () in
events.flush()
self.events.should_queue = false
self.events.set_should_queue(false)
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
}
}

View File

@@ -29,6 +29,26 @@ struct InnerTimelineView: View {
var body: some View {
LazyVStack(spacing: 0) {
let incomingEvents = events.incoming.filter({ filter($0) })
if incomingEvents.count > 0 {
Button(
action: {
notify(.scroll_to_top)
},
label: {
HStack(spacing: 6) {
CondensedProfilePicturesView(state: state, pubkeys: incomingEvents.map({ $0.pubkey }), maxPictures: 3)
Text("Load new content", comment: "Button to load new notes in the timeline")
.bold()
}
.padding(.horizontal, 20)
.padding(.vertical, 10)
}
)
.buttonStyle(NeutralButtonStyle(cornerRadius: 50))
.padding(.vertical, 10)
}
let events = self.events.events
if events.isEmpty {
EmptyTimelineView()

View File

@@ -97,7 +97,7 @@ struct TimelineView<Content: View>: View {
.coordinateSpace(name: "scroll")
.onReceive(handle_notify(.scroll_to_top)) { () in
events.flush()
self.events.should_queue = false
self.events.set_should_queue(false)
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
}
}
@@ -122,11 +122,8 @@ protocol ScrollQueue {
func handle_scroll_queue(_ proxy: GeometryProxy, queue: ScrollQueue) {
let offset = -proxy.frame(in: .named("scroll")).origin.y
guard offset >= 0 else {
return
}
let val = offset > 0
if queue.should_queue != val {
queue.set_should_queue(val)
let new_should_queue = offset > 0
if queue.should_queue != new_should_queue {
queue.set_should_queue(new_should_queue)
}
}

View File

@@ -11,8 +11,8 @@ import Foundation
class EventHolder: ObservableObject, ScrollQueue {
private var has_event = Set<NoteId>()
@Published var events: [NostrEvent]
var incoming: [NostrEvent]
var should_queue = false
@Published var incoming: [NostrEvent]
private(set) var should_queue = false
var on_queue: ((NostrEvent) -> Void)?
func set_should_queue(_ val: Bool) {