commit e2df7d5df655f9bdbb748efe29ec68703b94da89
parent 0dfea0680f873a084b9dc486bf469baab8dae0e0
Author: William Casarin <jb55@jb55.com>
Date: Sun, 5 Mar 2023 19:44:28 -0500
Notification Filters
Changelog-Added: Add filters to notification view
Diffstat:
3 files changed, 80 insertions(+), 6 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -187,10 +187,8 @@ struct ContentView: View {
PostingTimelineView
case .notifications:
- VStack(spacing: 0) {
- Divider()
- NotificationsView(state: damus, notifications: home.notifications)
- }
+ NotificationsView(state: damus, notifications: home.notifications)
+
case .dms:
DirectMessagesView(damus_state: damus_state!)
.environmentObject(home.dms)
diff --git a/damus/Models/NotificationsModel.swift b/damus/Models/NotificationsModel.swift
@@ -14,6 +14,28 @@ enum NotificationItem {
case event_zap(String, ZapGroup)
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 {
switch self {
case .repost(let evid, _):
diff --git a/damus/Views/Notifications/NotificationsView.swift b/damus/Views/Notifications/NotificationsView.swift
@@ -7,18 +7,72 @@
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 {
let state: DamusState
@ObservedObject var notifications: NotificationsModel
+ @State var filter_state: NotificationFilterState = .all
+
+ @Environment(\.colorScheme) var colorScheme
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
ScrollView {
LazyVStack(alignment: .leading) {
Color.white.opacity(0)
.id("startblock")
.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)
}
}
@@ -45,6 +99,6 @@ struct NotificationsView: View {
struct NotificationsView_Previews: PreviewProvider {
static var previews: some View {
- NotificationsView(state: test_damus_state(), notifications: NotificationsModel())
+ NotificationsView(state: test_damus_state(), notifications: NotificationsModel(), filter_state: .all )
}
}