Notification Filters
Changelog-Added: Add filters to notification view
This commit is contained in:
@@ -187,10 +187,8 @@ struct ContentView: View {
|
|||||||
PostingTimelineView
|
PostingTimelineView
|
||||||
|
|
||||||
case .notifications:
|
case .notifications:
|
||||||
VStack(spacing: 0) {
|
NotificationsView(state: damus, notifications: home.notifications)
|
||||||
Divider()
|
|
||||||
NotificationsView(state: damus, notifications: home.notifications)
|
|
||||||
}
|
|
||||||
case .dms:
|
case .dms:
|
||||||
DirectMessagesView(damus_state: damus_state!)
|
DirectMessagesView(damus_state: damus_state!)
|
||||||
.environmentObject(home.dms)
|
.environmentObject(home.dms)
|
||||||
|
|||||||
@@ -14,6 +14,28 @@ enum NotificationItem {
|
|||||||
case event_zap(String, ZapGroup)
|
case event_zap(String, ZapGroup)
|
||||||
case reply(NostrEvent)
|
case reply(NostrEvent)
|
||||||
|
|
||||||
|
var is_reply: NostrEvent? {
|
||||||
|
if case .reply(let ev) = self {
|
||||||
|
return ev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var is_zap: ZapGroup? {
|
||||||
|
switch self {
|
||||||
|
case .profile_zap(let zapgrp):
|
||||||
|
return zapgrp
|
||||||
|
case .event_zap(_, let zapgrp):
|
||||||
|
return zapgrp
|
||||||
|
case .reaction:
|
||||||
|
return nil
|
||||||
|
case .reply:
|
||||||
|
return nil
|
||||||
|
case .repost:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var id: String {
|
var id: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .repost(let evid, _):
|
case .repost(let evid, _):
|
||||||
|
|||||||
@@ -7,18 +7,72 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
|
enum NotificationFilterState {
|
||||||
|
case all
|
||||||
|
case zaps
|
||||||
|
case replies
|
||||||
|
|
||||||
|
func filter(_ item: NotificationItem) -> Bool {
|
||||||
|
switch self {
|
||||||
|
case .all:
|
||||||
|
return true
|
||||||
|
case .replies:
|
||||||
|
return item.is_reply != nil
|
||||||
|
case .zaps:
|
||||||
|
return item.is_zap != nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct NotificationsView: View {
|
struct NotificationsView: View {
|
||||||
let state: DamusState
|
let state: DamusState
|
||||||
@ObservedObject var notifications: NotificationsModel
|
@ObservedObject var notifications: NotificationsModel
|
||||||
|
@State var filter_state: NotificationFilterState = .all
|
||||||
|
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
TabView(selection: $filter_state) {
|
||||||
|
NotificationTab(NotificationFilterState.all)
|
||||||
|
.tag(NotificationFilterState.all)
|
||||||
|
.id(NotificationFilterState.all)
|
||||||
|
|
||||||
|
NotificationTab(NotificationFilterState.zaps)
|
||||||
|
.tag(NotificationFilterState.zaps)
|
||||||
|
.id(NotificationFilterState.zaps)
|
||||||
|
|
||||||
|
NotificationTab(NotificationFilterState.replies)
|
||||||
|
.tag(NotificationFilterState.replies)
|
||||||
|
.id(NotificationFilterState.replies)
|
||||||
|
}
|
||||||
|
.safeAreaInset(edge: .top, spacing: 0) {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
CustomPicker(selection: $filter_state, content: {
|
||||||
|
Text("All", comment: "Label for filter for all notifications.")
|
||||||
|
.tag(NotificationFilterState.all)
|
||||||
|
|
||||||
|
Text("Zaps", comment: "Label for filter for zap notifications.")
|
||||||
|
.tag(NotificationFilterState.zaps)
|
||||||
|
|
||||||
|
Text("Mentions", comment: "Label for filter for seeing mention notifications (replies, etc).")
|
||||||
|
.tag(NotificationFilterState.replies)
|
||||||
|
|
||||||
|
})
|
||||||
|
Divider()
|
||||||
|
.frame(height: 1)
|
||||||
|
}
|
||||||
|
.background(colorScheme == .dark ? Color.black : Color.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NotificationTab(_ filter: NotificationFilterState) -> some View {
|
||||||
ScrollViewReader { scroller in
|
ScrollViewReader { scroller in
|
||||||
ScrollView {
|
ScrollView {
|
||||||
LazyVStack(alignment: .leading) {
|
LazyVStack(alignment: .leading) {
|
||||||
Color.white.opacity(0)
|
Color.white.opacity(0)
|
||||||
.id("startblock")
|
.id("startblock")
|
||||||
.frame(height: 5)
|
.frame(height: 5)
|
||||||
ForEach(notifications.notifications, id: \.id) { item in
|
ForEach(notifications.notifications.filter(filter.filter), id: \.id) { item in
|
||||||
NotificationItemView(state: state, item: item)
|
NotificationItemView(state: state, item: item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +99,6 @@ struct NotificationsView: View {
|
|||||||
|
|
||||||
struct NotificationsView_Previews: PreviewProvider {
|
struct NotificationsView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
NotificationsView(state: test_damus_state(), notifications: NotificationsModel())
|
NotificationsView(state: test_damus_state(), notifications: NotificationsModel(), filter_state: .all )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user