From 2bea2faf3f3559977bacaea30c2106d8fdf80edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 5 Sep 2025 17:55:08 -0700 Subject: [PATCH] Add load more content button to the top bar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel D’Aquino --- damus/ContentView.swift | 2 +- .../Timeline/Views/InnerTimelineView.swift | 20 ---- .../Timeline/Views/PostingTimelineView.swift | 104 +++++++++++------- 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/damus/ContentView.swift b/damus/ContentView.swift index e7e1e502..c024145d 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -174,7 +174,7 @@ struct ContentView: View { } case .home: - PostingTimelineView(damus_state: damus_state!, home: home, isSideBarOpened: $isSideBarOpened, active_sheet: $active_sheet, headerOffset: $headerOffset) + PostingTimelineView(damus_state: damus_state!, home: home, homeEvents: home.events, isSideBarOpened: $isSideBarOpened, active_sheet: $active_sheet, headerOffset: $headerOffset) case .notifications: NotificationsView(state: damus, notifications: home.notifications, subtitle: $menu_subtitle) diff --git a/damus/Features/Timeline/Views/InnerTimelineView.swift b/damus/Features/Timeline/Views/InnerTimelineView.swift index 49e83296..0e572f8f 100644 --- a/damus/Features/Timeline/Views/InnerTimelineView.swift +++ b/damus/Features/Timeline/Views/InnerTimelineView.swift @@ -29,26 +29,6 @@ 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() diff --git a/damus/Features/Timeline/Views/PostingTimelineView.swift b/damus/Features/Timeline/Views/PostingTimelineView.swift index 06848ba7..42985e61 100644 --- a/damus/Features/Timeline/Views/PostingTimelineView.swift +++ b/damus/Features/Timeline/Views/PostingTimelineView.swift @@ -11,6 +11,8 @@ struct PostingTimelineView: View { let damus_state: DamusState @ObservedObject var home: HomeModel + /// Set this to `home.events`. This is separate from `home` because we need the events object to be directly observed so that we get instant view updates + @ObservedObject var homeEvents: EventHolder @State var search: String = "" @State var results: [NostrEvent] = [] @State var initialOffset: CGFloat? @@ -44,53 +46,75 @@ struct PostingTimelineView: View { TimelineView(events: home.events, loading: self.loading, headerHeight: $headerHeight, headerOffset: $headerOffset, damus: damus_state, show_friend_icon: false, filter: filter) } - func HeaderView()->some View { + func HeaderView() -> some View { VStack { - VStack(spacing: 0) { - // This is needed for the Dynamic Island - HStack {} - .frame(height: getSafeAreaTop()) - - HStack(alignment: .top) { - TopbarSideMenuButton(damus_state: damus_state, isSideBarOpened: $isSideBarOpened) + VStack { + VStack(spacing: 0) { + // This is needed for the Dynamic Island + HStack {} + .frame(height: getSafeAreaTop()) - Spacer() - - Image("damus-home") - .resizable() - .frame(width:30,height:30) - .shadow(color: DamusColors.purple, radius: 2) - .opacity(isSideBarOpened ? 0 : 1) - .animation(isSideBarOpened ? .none : .default, value: isSideBarOpened) - .onTapGesture { - isSideBarOpened.toggle() + HStack(alignment: .top) { + TopbarSideMenuButton(damus_state: damus_state, isSideBarOpened: $isSideBarOpened) + + Spacer() + + Image("damus-home") + .resizable() + .frame(width:30,height:30) + .shadow(color: DamusColors.purple, radius: 2) + .opacity(isSideBarOpened ? 0 : 1) + .animation(isSideBarOpened ? .none : .default, value: isSideBarOpened) + .onTapGesture { + isSideBarOpened.toggle() + } + .padding(.leading) + + Spacer() + + HStack(alignment: .center) { + SignalView(state: damus_state, signal: home.signal) } - .padding(.leading) - - Spacer() - - HStack(alignment: .center) { - SignalView(state: damus_state, signal: home.signal) } + .frame(maxWidth: .infinity, alignment: .trailing) } - .frame(maxWidth: .infinity, alignment: .trailing) - } - .padding(.horizontal, 20) - - VStack(spacing: 0) { - CustomPicker(tabs: [ - (NSLocalizedString("Notes", comment: "Label for filter for seeing only notes (instead of notes and replies)."), FilterState.posts), - (NSLocalizedString("Notes & Replies", comment: "Label for filter for seeing notes and replies (instead of only notes)."), FilterState.posts_and_replies) - ], - selection: $filter_state) + .padding(.horizontal, 20) - Divider() - .frame(height: 1) + VStack(spacing: 0) { + CustomPicker(tabs: [ + (NSLocalizedString("Notes", comment: "Label for filter for seeing only notes (instead of notes and replies)."), FilterState.posts), + (NSLocalizedString("Notes & Replies", comment: "Label for filter for seeing notes and replies (instead of only notes)."), FilterState.posts_and_replies) + ], + selection: $filter_state) + + Divider() + .frame(height: 1) + } + } + .background { + DamusColors.adaptableWhite + .ignoresSafeArea() + } + + if homeEvents.incoming.count > 0 { + Button( + action: { + notify(.scroll_to_top) + }, + label: { + HStack(spacing: 6) { + CondensedProfilePicturesView(state: damus_state, pubkeys: homeEvents.incoming.map({ $0.pubkey }), maxPictures: 3) + .scaleEffect(0.75) + Text("Load new content", comment: "Button to load new notes in the timeline") + .bold() + } + .padding(.horizontal, 10) + .padding(.vertical, 5) + } + ) + .buttonStyle(NeutralButtonStyle(cornerRadius: 50)) + .padding(.vertical, 10) } - } - .background { - DamusColors.adaptableWhite - .ignoresSafeArea() } }