damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit dba1799df097014298c52aa16238b4f33ec09ed2
parent 2db3d7310f9c0c1baf4659fb524678e3b92796d8
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Wed, 24 Jul 2024 10:53:00 -0700

Merge pull request #2338 from ericholguin/move-posting-timeline

refactor: move posting timeline
Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Mdamus/ContentView.swift | 60+-----------------------------------------------------------
Adamus/Views/Timeline/PostingTimelineView.swift | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 85 insertions(+), 59 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -407,6 +407,7 @@ 5C7389B12B6EFA7100781E0A /* ProxyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7389B02B6EFA7100781E0A /* ProxyView.swift */; }; 5C7389B72B9E692E00781E0A /* MutinyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7389B62B9E692E00781E0A /* MutinyButton.swift */; }; 5C7389B92B9E69ED00781E0A /* MutinyGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7389B82B9E69ED00781E0A /* MutinyGradient.swift */; }; + 5C8711DE2C460C06007879C2 /* PostingTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C8711DD2C460C06007879C2 /* PostingTimelineView.swift */; }; 5CC8529D2BD741CD0039FFC5 /* HighlightEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC8529C2BD741CD0039FFC5 /* HighlightEvent.swift */; }; 5CC8529F2BD744F60039FFC5 /* HighlightView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC8529E2BD744F60039FFC5 /* HighlightView.swift */; }; 5CC852A22BDED9B90039FFC5 /* HighlightDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC852A12BDED9B90039FFC5 /* HighlightDescription.swift */; }; @@ -1348,6 +1349,7 @@ 5C7389B02B6EFA7100781E0A /* ProxyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyView.swift; sourceTree = "<group>"; }; 5C7389B62B9E692E00781E0A /* MutinyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutinyButton.swift; sourceTree = "<group>"; }; 5C7389B82B9E69ED00781E0A /* MutinyGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutinyGradient.swift; sourceTree = "<group>"; }; + 5C8711DD2C460C06007879C2 /* PostingTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostingTimelineView.swift; sourceTree = "<group>"; }; 5CC8529C2BD741CD0039FFC5 /* HighlightEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightEvent.swift; sourceTree = "<group>"; }; 5CC8529E2BD744F60039FFC5 /* HighlightView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightView.swift; sourceTree = "<group>"; }; 5CC852A12BDED9B90039FFC5 /* HighlightDescription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightDescription.swift; sourceTree = "<group>"; }; @@ -2447,6 +2449,7 @@ isa = PBXGroup; children = ( 4CE0E2B529A3ED5500DB4CA2 /* InnerTimelineView.swift */, + 5C8711DD2C460C06007879C2 /* PostingTimelineView.swift */, ); path = Timeline; sourceTree = "<group>"; @@ -3175,6 +3178,7 @@ 4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */, 4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */, 4CC14FF12A73FCDB007AEB17 /* Pubkey.swift in Sources */, + 5C8711DE2C460C06007879C2 /* PostingTimelineView.swift in Sources */, 4CA9275D2A28FF630098A105 /* LongformView.swift in Sources */, 4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */, D7EDED1E2B11797D0018B19C /* LongformEvent.swift in Sources */, diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -79,73 +79,15 @@ struct ContentView: View { @State var hide_bar: Bool = false @State var user_muted_confirm: Bool = false @State var confirm_overwrite_mutelist: Bool = false - @SceneStorage("ContentView.filter_state") var filter_state : FilterState = .posts_and_replies @State private var isSideBarOpened = false var home: HomeModel = HomeModel() @StateObject var navigationCoordinator: NavigationCoordinator = NavigationCoordinator() @AppStorage("has_seen_suggested_users") private var hasSeenOnboardingSuggestions = false let sub_id = UUID().description - - @Environment(\.colorScheme) var colorScheme // connect retry timer let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() - var mystery: some View { - Text("Are you lost?", comment: "Text asking the user if they are lost in the app.") - .id("what") - } - - func content_filter(_ fstate: FilterState) -> ((NostrEvent) -> Bool) { - var filters = ContentFilters.defaults(damus_state: damus_state!) - filters.append(fstate.filter) - return ContentFilters(filters: filters).filter - } - - var PostingTimelineView: some View { - VStack { - ZStack { - TabView(selection: $filter_state) { - // This is needed or else there is a bug when switching from the 3rd or 2nd tab to first. no idea why. - mystery - - contentTimelineView(filter: content_filter(.posts)) - .tag(FilterState.posts) - .id(FilterState.posts) - contentTimelineView(filter: content_filter(.posts_and_replies)) - .tag(FilterState.posts_and_replies) - .id(FilterState.posts_and_replies) - } - .tabViewStyle(.page(indexDisplayMode: .never)) - - if privkey != nil { - PostButtonContainer(is_left_handed: damus_state?.settings.left_handed ?? false) { - self.active_sheet = .post(.posting(.none)) - } - } - } - } - .safeAreaInset(edge: .top, spacing: 0) { - 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(colorScheme == .dark ? Color.black : Color.white) - } - } - - func contentTimelineView(filter: (@escaping (NostrEvent) -> Bool)) -> some View { - TimelineView(events: home.events, loading: .constant(false), damus: damus_state, show_friend_icon: false, filter: filter) { - PullDownSearchView(state: damus_state, on_cancel: {}) - } - } - func navIsAtRoot() -> Bool { return navigationCoordinator.isAtRoot() } @@ -173,7 +115,7 @@ struct ContentView: View { } case .home: - PostingTimelineView + PostingTimelineView(damus_state: damus_state!, home: home, active_sheet: $active_sheet) case .notifications: NotificationsView(state: damus, notifications: home.notifications) diff --git a/damus/Views/Timeline/PostingTimelineView.swift b/damus/Views/Timeline/PostingTimelineView.swift @@ -0,0 +1,80 @@ +// +// PostingTimelineView.swift +// damus +// +// Created by eric on 7/15/24. +// + +import SwiftUI + +struct PostingTimelineView: View { + + let damus_state: DamusState + var home: HomeModel + @State var search: String = "" + @State var results: [NostrEvent] = [] + @State var initialOffset: CGFloat? + @State var offset: CGFloat? + @State var showSearch: Bool = true + @Binding var active_sheet: Sheets? + @FocusState private var isSearchFocused: Bool + @State private var contentOffset: CGFloat = 0 + @State private var indicatorWidth: CGFloat = 0 + @State private var indicatorPosition: CGFloat = 0 + @SceneStorage("PostingTimelineView.filter_state") var filter_state : FilterState = .posts_and_replies + + var mystery: some View { + Text("Are you lost?", comment: "Text asking the user if they are lost in the app.") + .id("what") + } + + func content_filter(_ fstate: FilterState) -> ((NostrEvent) -> Bool) { + var filters = ContentFilters.defaults(damus_state: damus_state) + filters.append(fstate.filter) + return ContentFilters(filters: filters).filter + } + + func contentTimelineView(filter: (@escaping (NostrEvent) -> Bool)) -> some View { + TimelineView(events: home.events, loading: .constant(false), damus: damus_state, show_friend_icon: false, filter: filter) { + PullDownSearchView(state: damus_state, on_cancel: {}) + } + } + + var body: some View { + VStack { + ZStack { + TabView(selection: $filter_state) { + // This is needed or else there is a bug when switching from the 3rd or 2nd tab to first. no idea why. + mystery + + contentTimelineView(filter: content_filter(.posts)) + .tag(FilterState.posts) + .id(FilterState.posts) + contentTimelineView(filter: content_filter(.posts_and_replies)) + .tag(FilterState.posts_and_replies) + .id(FilterState.posts_and_replies) + } + .tabViewStyle(.page(indexDisplayMode: .never)) + + if damus_state.keypair.privkey != nil { + PostButtonContainer(is_left_handed: damus_state.settings.left_handed) { + self.active_sheet = .post(.posting(.none)) + } + } + } + } + .safeAreaInset(edge: .top, spacing: 0) { + 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) + } + } +}