commit b6a7f52596aff4208e526a9bc3c3a65b591f01ad
parent cff98161ee274684775d7c6d25b6d1763c6f4a92
Author: ericholguin <eric.holguinsanchez@gmail.com>
Date: Fri, 10 Feb 2023 23:57:20 -0700
Add menu ellipsis button to notes
Changelog-Added: Add ellipsis button to notes
Diffstat:
7 files changed, 107 insertions(+), 59 deletions(-)
diff --git a/damus/Components/ImageCarousel.swift b/damus/Components/ImageCarousel.swift
@@ -210,11 +210,11 @@ struct ImageCarousel: View {
Text(url.absoluteString)
}
.id(url.absoluteString)
- .contextMenu {
- Button(NSLocalizedString("Copy Image", comment: "Context menu option to copy an image to clipboard.")) {
- UIPasteboard.general.string = url.absoluteString
- }
- }
+// .contextMenu {
+// Button(NSLocalizedString("Copy Image", comment: "Context menu option to copy an image to clipboard.")) {
+// UIPasteboard.general.string = url.absoluteString
+// }
+// }
}
}
}
diff --git a/damus/Views/ChatroomView.swift b/damus/Views/ChatroomView.swift
@@ -25,7 +25,7 @@ struct ChatroomView: View {
next_ev: ind == count-1 ? nil : thread.events[ind+1],
damus_state: damus
)
- .event_context_menu(ev, keypair: damus.keypair, target_pubkey: ev.pubkey, bookmarks: damus.bookmarks)
+ .contextMenu{MenuItems(event: ev, keypair: damus.keypair, target_pubkey: ev.pubkey, bookmarks: damus.bookmarks)}
.onTapGesture {
if thread.event.id == ev.id {
//dismiss()
diff --git a/damus/Views/DMChatView.swift b/damus/Views/DMChatView.swift
@@ -19,7 +19,7 @@ struct DMChatView: View {
VStack(alignment: .leading) {
ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in
DMView(event: dms.events[ind], damus_state: damus_state)
- .event_context_menu(ev, keypair: damus_state.keypair, target_pubkey: ev.pubkey, bookmarks: damus_state.bookmarks)
+ .contextMenu{MenuItems(event: ev, keypair: damus_state.keypair, target_pubkey: ev.pubkey, bookmarks: damus_state.bookmarks)}
}
EndBlock(height: 80)
}
diff --git a/damus/Views/Events/EmbeddedEventView.swift b/damus/Views/Events/EmbeddedEventView.swift
@@ -18,12 +18,20 @@ struct EmbeddedEventView: View {
var body: some View {
VStack(alignment: .leading) {
let profile = damus_state.profiles.lookup(id: pubkey)
-
- EventProfile(damus_state: damus_state, pubkey: pubkey, profile: profile, size: .small)
+ HStack {
+ EventProfile(damus_state: damus_state, pubkey: pubkey, profile: profile, size: .small)
+
+ Spacer()
+
+ EventMenuContext(event: event, keypair: damus_state.keypair, target_pubkey: event.pubkey, bookmarks: damus_state.bookmarks)
+ .padding([.bottom], 4)
+
+ }
+ .minimumScaleFactor(0.75)
+ .lineLimit(1)
EventBody(damus_state: damus_state, event: event, size: .small)
}
- .event_context_menu(event, keypair: damus_state.keypair, target_pubkey: pubkey, bookmarks: damus_state.bookmarks)
}
}
diff --git a/damus/Views/Events/EventMenu.swift b/damus/Views/Events/EventMenu.swift
@@ -13,6 +13,29 @@ struct EventMenuContext: View {
let target_pubkey: String
let bookmarks: BookmarksManager
+ var body: some View {
+ HStack {
+ Menu {
+
+ MenuItems(event: event, keypair: keypair, target_pubkey: target_pubkey, bookmarks: bookmarks)
+
+ } label: {
+ Label(NSLocalizedString("", comment: "Context menu"), systemImage: "ellipsis")
+ .foregroundColor(Color.gray)
+ }
+ }
+ .contentShape(Rectangle())
+ .onTapGesture {}
+
+ }
+}
+
+struct MenuItems: View {
+ let event: NostrEvent
+ let keypair: Keypair
+ let target_pubkey: String
+ let bookmarks: BookmarksManager
+
@State private var isBookmarked: Bool = false
init(event: NostrEvent, keypair: Keypair, target_pubkey: String, bookmarks: BookmarksManager) {
@@ -26,60 +49,62 @@ struct EventMenuContext: View {
}
var body: some View {
-
- Button {
- UIPasteboard.general.string = event.get_content(keypair.privkey)
- } label: {
- Label(NSLocalizedString("Copy Text", comment: "Context menu option for copying the text from an note."), systemImage: "doc.on.doc")
- }
- Button {
- UIPasteboard.general.string = bech32_pubkey(target_pubkey)
- } label: {
- Label(NSLocalizedString("Copy User Pubkey", comment: "Context menu option for copying the ID of the user who created the note."), systemImage: "person")
- }
-
- Button {
- UIPasteboard.general.string = bech32_note_id(event.id) ?? event.id
- } label: {
- Label(NSLocalizedString("Copy Note ID", comment: "Context menu option for copying the ID of the note."), systemImage: "note.text")
- }
+ Group {
+ Button {
+ UIPasteboard.general.string = event.get_content(keypair.privkey)
+ } label: {
+ Label(NSLocalizedString("Copy Text", comment: "Context menu option for copying the text from an note."), systemImage: "doc.on.doc")
+ }
- Button {
- UIPasteboard.general.string = event_to_json(ev: event)
- } label: {
- Label(NSLocalizedString("Copy Note JSON", comment: "Context menu option for copying the JSON text from the note."), systemImage: "square.on.square")
- }
-
- Button {
- self.bookmarks.updateBookmark(event)
- isBookmarked = self.bookmarks.isBookmarked(event)
- } label: {
- let imageName = isBookmarked ? "bookmark.fill" : "bookmark"
- let removeBookmarkString = NSLocalizedString("Remove Bookmark", comment: "Context menu option for removing a note bookmark.")
- let addBookmarkString = NSLocalizedString("Add Bookmark", comment: "Context menu option for adding a note bookmark.")
- Label(isBookmarked ? removeBookmarkString : addBookmarkString, systemImage: imageName)
- }
+ Button {
+ UIPasteboard.general.string = bech32_pubkey(target_pubkey)
+ } label: {
+ Label(NSLocalizedString("Copy User Pubkey", comment: "Context menu option for copying the ID of the user who created the note."), systemImage: "person")
+ }
- Button {
- NotificationCenter.default.post(name: .broadcast_event, object: event)
- } label: {
- Label(NSLocalizedString("Broadcast", comment: "Context menu option for broadcasting the user's note to all of the user's connected relay servers."), systemImage: "globe")
- }
+ Button {
+ UIPasteboard.general.string = bech32_note_id(event.id) ?? event.id
+ } label: {
+ Label(NSLocalizedString("Copy Note ID", comment: "Context menu option for copying the ID of the note."), systemImage: "note.text")
+ }
- // Only allow reporting if logged in with private key and the currently viewed profile is not the logged in profile.
- if keypair.pubkey != target_pubkey && keypair.privkey != nil {
- Button(role: .destructive) {
- let target: ReportTarget = .note(ReportNoteTarget(pubkey: target_pubkey, note_id: event.id))
- notify(.report, target)
+ Button {
+ UIPasteboard.general.string = event_to_json(ev: event)
} label: {
- Label(NSLocalizedString("Report", comment: "Context menu option for reporting content."), systemImage: "exclamationmark.bubble")
+ Label(NSLocalizedString("Copy Note JSON", comment: "Context menu option for copying the JSON text from the note."), systemImage: "square.on.square")
+ }
+
+ Button {
+ self.bookmarks.updateBookmark(event)
+ isBookmarked = self.bookmarks.isBookmarked(event)
+ } label: {
+ let imageName = isBookmarked ? "bookmark.fill" : "bookmark"
+ let removeBookmarkString = NSLocalizedString("Remove Bookmark", comment: "Context menu option for removing a note bookmark.")
+ let addBookmarkString = NSLocalizedString("Add Bookmark", comment: "Context menu option for adding a note bookmark.")
+ Label(isBookmarked ? removeBookmarkString : addBookmarkString, systemImage: imageName)
}
- Button(role: .destructive) {
- notify(.block, target_pubkey)
+ Button {
+ NotificationCenter.default.post(name: .broadcast_event, object: event)
} label: {
- Label(NSLocalizedString("Block", comment: "Context menu option for blocking users."), systemImage: "exclamationmark.octagon")
+ Label(NSLocalizedString("Broadcast", comment: "Context menu option for broadcasting the user's note to all of the user's connected relay servers."), systemImage: "globe")
+ }
+
+ // Only allow reporting if logged in with private key and the currently viewed profile is not the logged in profile.
+ if keypair.pubkey != target_pubkey && keypair.privkey != nil {
+ Button(role: .destructive) {
+ let target: ReportTarget = .note(ReportNoteTarget(pubkey: target_pubkey, note_id: event.id))
+ notify(.report, target)
+ } label: {
+ Label(NSLocalizedString("Report", comment: "Context menu option for reporting content."), systemImage: "exclamationmark.bubble")
+ }
+
+ Button(role: .destructive) {
+ notify(.block, target_pubkey)
+ } label: {
+ Label(NSLocalizedString("Block", comment: "Context menu option for blocking users."), systemImage: "exclamationmark.octagon")
+ }
}
}
}
diff --git a/damus/Views/Events/SelectedEventView.swift b/damus/Views/Events/SelectedEventView.swift
@@ -28,7 +28,18 @@ struct SelectedEventView: View {
let profile = damus.profiles.lookup(id: pubkey)
VStack(alignment: .leading) {
- EventProfile(damus_state: damus, pubkey: pubkey, profile: profile, size: .normal)
+ HStack {
+ EventProfile(damus_state: damus, pubkey: pubkey, profile: profile, size: .normal)
+
+ Spacer()
+
+ EventMenuContext(event: event, keypair: damus.keypair, target_pubkey: event.pubkey, bookmarks: damus.bookmarks)
+ .padding([.bottom], 4)
+
+ }
+ .minimumScaleFactor(0.75)
+ .lineLimit(1)
+
EventBody(damus_state: damus, event: event, size: .selected)
if let mention = first_eref_mention(ev: event, privkey: damus.keypair.privkey) {
@@ -60,7 +71,6 @@ struct SelectedEventView: View {
self.bar.update(damus: self.damus, evid: target)
}
.padding([.leading], 2)
- .event_context_menu(event, keypair: damus.keypair, target_pubkey: event.pubkey, bookmarks: damus.bookmarks)
}
}
}
diff --git a/damus/Views/Events/TextEvent.swift b/damus/Views/Events/TextEvent.swift
@@ -44,7 +44,13 @@ struct TextEvent: View {
.foregroundColor(.gray)
Spacer()
+
+ EventMenuContext(event: event, keypair: damus.keypair, target_pubkey: event.pubkey, bookmarks: damus.bookmarks)
+ .padding([.bottom], 4)
+
}
+ .minimumScaleFactor(0.75)
+ .lineLimit(1)
EventBody(damus_state: damus, event: event, size: .normal)
@@ -66,7 +72,6 @@ struct TextEvent: View {
.id(event.id)
.frame(maxWidth: .infinity, minHeight: PFP_SIZE)
.padding([.bottom], 2)
- .event_context_menu(event, keypair: damus.keypair, target_pubkey: pubkey, bookmarks: damus.bookmarks)
}
}