damus

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

ShareAction.swift (2966B)


      1 //
      2 //  ShareAction.swift
      3 //  damus
      4 //
      5 //  Created by eric on 3/8/23.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct ShareAction: View {
     11     let event: NostrEvent
     12     let bookmarks: BookmarksManager
     13     let userProfile: ProfileModel
     14     @State private var isBookmarked: Bool = false
     15 
     16     @Binding var show_share: Bool
     17     
     18     @Environment(\.dismiss) var dismiss
     19     
     20     init(event: NostrEvent, bookmarks: BookmarksManager, show_share: Binding<Bool>, userProfile: ProfileModel) {
     21         let bookmarked = bookmarks.isBookmarked(event)
     22         self._isBookmarked = State(initialValue: bookmarked)
     23         
     24         self.bookmarks = bookmarks
     25         self.event = event
     26         self.userProfile = userProfile
     27         self._show_share = show_share
     28     }
     29     
     30     var body: some View {
     31         
     32         VStack {
     33             Text("Share Note", comment: "Title text to indicate that the buttons below are meant to be used to share a note with others.")
     34                 .padding()
     35                 .font(.system(size: 17, weight: .bold))
     36             
     37             Spacer()
     38 
     39             HStack(alignment: .top, spacing: 25) {
     40                 
     41                 ShareActionButton(img: "link", text: NSLocalizedString("Copy Link", comment: "Button to copy link to note")) {
     42                     dismiss()
     43                     UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(noteid: event.id, relays: userProfile.getCappedRelayStrings())))
     44                 }
     45                 
     46                 let bookmarkImg = isBookmarked ? "bookmark.fill" : "bookmark"
     47                 let bookmarkTxt = isBookmarked ? NSLocalizedString("Remove Bookmark", comment: "Button text to remove bookmark from a note.") : NSLocalizedString("Add Bookmark", comment: "Button text to add bookmark to a note.")
     48                 ShareActionButton(img: bookmarkImg, text: bookmarkTxt) {
     49                     dismiss()
     50                     self.bookmarks.updateBookmark(event)
     51                     isBookmarked = self.bookmarks.isBookmarked(event)
     52                 }
     53                 
     54                 ShareActionButton(img: "globe", text: NSLocalizedString("Broadcast", comment: "Button to broadcast note to all your relays")) {
     55                     dismiss()
     56                     notify(.broadcast(event))
     57                 }
     58                 
     59                 ShareActionButton(img: "upload", text: NSLocalizedString("Share Via...", comment: "Button to present iOS share sheet")) {
     60                     show_share = true
     61                     dismiss()
     62                 }
     63                 
     64             }
     65             
     66             Spacer()
     67             
     68             HStack {
     69                 BigButton(NSLocalizedString("Cancel", comment: "Button to cancel a repost.")) {
     70                     dismiss()
     71                 }
     72             }
     73         }
     74         .onAppear() {
     75             userProfile.subscribeToFindRelays()
     76         }
     77         .onDisappear() {
     78             userProfile.unsubscribeFindRelays()
     79         }
     80     }
     81 }
     82