Add replies filter and tabs
Closes: #31 Changelog-Added: Tabs to switch between posts and replies in home view Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
7bdd8048b0
commit
72900894c0
@@ -35,6 +35,11 @@ enum ThreadState {
|
||||
case chatroom
|
||||
}
|
||||
|
||||
enum FilterState : Int {
|
||||
case posts_and_replies = 1
|
||||
case posts = 0
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
let keypair: Keypair
|
||||
|
||||
@@ -59,6 +64,7 @@ struct ContentView: View {
|
||||
@State var profile_open: Bool = false
|
||||
@State var thread_open: Bool = false
|
||||
@State var search_open: Bool = false
|
||||
@State var filter_state : FilterState = .posts_and_replies
|
||||
@StateObject var home: HomeModel = HomeModel()
|
||||
|
||||
// connect retry timer
|
||||
@@ -88,18 +94,39 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
var PostingTimelineView: some View {
|
||||
ZStack {
|
||||
if let damus = self.damus_state {
|
||||
TimelineView(events: $home.events, loading: $home.loading, damus: damus, show_friend_icon: false)
|
||||
}
|
||||
if privkey != nil {
|
||||
PostButtonContainer {
|
||||
self.active_sheet = .post
|
||||
VStack{
|
||||
FiltersView
|
||||
ZStack {
|
||||
if let damus = self.damus_state {
|
||||
TimelineView(events: $home.events, loading: $home.loading, damus: damus, show_friend_icon: false, filter: filter_event)
|
||||
}
|
||||
if privkey != nil {
|
||||
PostButtonContainer {
|
||||
self.active_sheet = .post
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var FiltersView: some View {
|
||||
VStack{
|
||||
Picker("Filter State", selection: $filter_state) {
|
||||
Text("Posts").tag(FilterState.posts)
|
||||
Text("Posts & Replies").tag(FilterState.posts_and_replies)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
}
|
||||
}
|
||||
|
||||
func filter_event(_ ev: NostrEvent) -> Bool {
|
||||
if self.filter_state == .posts {
|
||||
return !ev.is_reply(nil)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func MainContent(damus: DamusState) -> some View {
|
||||
VStack {
|
||||
NavigationLink(destination: MaybeProfileView, isActive: $profile_open) {
|
||||
@@ -119,7 +146,7 @@ struct ContentView: View {
|
||||
PostingTimelineView
|
||||
|
||||
case .notifications:
|
||||
TimelineView(events: $home.notifications, loading: $home.loading, damus: damus, show_friend_icon: true)
|
||||
TimelineView(events: $home.notifications, loading: $home.loading, damus: damus, show_friend_icon: true, filter: { _ in true })
|
||||
.navigationTitle("Notifications")
|
||||
|
||||
case .dms:
|
||||
|
||||
@@ -147,7 +147,7 @@ struct ProfileView: View {
|
||||
|
||||
Divider()
|
||||
|
||||
InnerTimelineView(events: $profile.events, damus: damus_state, show_friend_icon: false)
|
||||
InnerTimelineView(events: $profile.events, damus: damus_state, show_friend_icon: false, filter: { _ in true })
|
||||
}
|
||||
.frame(maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ struct SearchHomeView: View {
|
||||
}
|
||||
|
||||
var GlobalContent: some View {
|
||||
TimelineView(events: $model.events, loading: $model.loading, damus: damus_state, show_friend_icon: true)
|
||||
TimelineView(events: $model.events, loading: $model.loading, damus: damus_state, show_friend_icon: true, filter: { _ in true })
|
||||
}
|
||||
|
||||
var SearchContent: some View {
|
||||
|
||||
@@ -13,7 +13,7 @@ struct SearchView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
TimelineView(events: $search.events, loading: $search.loading, damus: appstate, show_friend_icon: true)
|
||||
TimelineView(events: $search.events, loading: $search.loading, damus: appstate, show_friend_icon: true, filter: { _ in true })
|
||||
.navigationBarTitle(describe_search(search.search))
|
||||
.padding([.leading, .trailing], 6)
|
||||
.onReceive(handle_notify(.switched_timeline)) { obj in
|
||||
|
||||
@@ -16,10 +16,11 @@ struct InnerTimelineView: View {
|
||||
@Binding var events: [NostrEvent]
|
||||
let damus: DamusState
|
||||
let show_friend_icon: Bool
|
||||
let filter: (NostrEvent) -> Bool
|
||||
|
||||
var body: some View {
|
||||
LazyVStack {
|
||||
ForEach(events, id: \.id) { (ev: NostrEvent) in
|
||||
ForEach(events.filter(filter), id: \.id) { (ev: NostrEvent) in
|
||||
let tm = ThreadModel(event: inner_event_or_self(ev: ev), damus_state: damus)
|
||||
let is_chatroom = should_show_chatroom(ev)
|
||||
let tv = ThreadView(thread: tm, damus: damus, is_chatroom: is_chatroom)
|
||||
@@ -40,6 +41,7 @@ struct TimelineView: View {
|
||||
|
||||
let damus: DamusState
|
||||
let show_friend_icon: Bool
|
||||
let filter: (NostrEvent) -> Bool
|
||||
|
||||
var body: some View {
|
||||
MainContent
|
||||
@@ -52,7 +54,7 @@ struct TimelineView: View {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
}
|
||||
InnerTimelineView(events: $events, damus: damus, show_friend_icon: show_friend_icon)
|
||||
InnerTimelineView(events: $events, damus: damus, show_friend_icon: show_friend_icon, filter: filter)
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .scroll_to_top)) { _ in
|
||||
guard let event = events.first else {
|
||||
|
||||
Reference in New Issue
Block a user