damus

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

BookmarksView.swift (2404B)


      1 //
      2 //  BookmarksView.swift
      3 //  damus
      4 //
      5 //  Created by Joel Klabo on 2/18/23.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct BookmarksView: View {
     11     let state: DamusState
     12     private let noneFilter: (NostrEvent) -> Bool = { _ in true }
     13     private let bookmarksTitle = NSLocalizedString("Bookmarks", comment: "Title of bookmarks view")
     14     @State private var clearAllAlert: Bool = false
     15     
     16     @Environment(\.dismiss) var dismiss
     17     @ObservedObject var manager: BookmarksManager
     18 
     19     init(state: DamusState) {
     20         self.state = state
     21         self._manager = ObservedObject(initialValue: state.bookmarks)
     22     }
     23     
     24     var bookmarks: [NostrEvent] {
     25         manager.bookmarks
     26     }
     27         
     28     var body: some View {
     29         Group {
     30             if bookmarks.isEmpty {
     31                 VStack {
     32                     Image("bookmark")
     33                         .resizable()
     34                         .scaledToFit()
     35                         .frame(width: 32.0, height: 32.0)
     36                     Text("You have no bookmarks yet, add them in the context menu", comment: "Text indicating that there are no bookmarks to be viewed")
     37                 }
     38             } else {
     39                 ScrollView {
     40                     InnerTimelineView(events: EventHolder(events: bookmarks, incoming: []), damus: state, filter: noneFilter)
     41                 }
     42                 .padding(.bottom, 10 + tabHeight + getSafeAreaBottom())
     43             }
     44         }
     45         .onReceive(handle_notify(.switched_timeline)) { _ in
     46             dismiss()
     47         }
     48         .navigationBarTitleDisplayMode(.inline)
     49         .navigationTitle(bookmarksTitle)
     50         .toolbar {
     51             if !bookmarks.isEmpty {
     52                 Button(NSLocalizedString("Clear All", comment: "Button for clearing bookmarks data.")) {
     53                     clearAllAlert = true
     54                 }
     55             }
     56         }
     57         .alert(NSLocalizedString("Are you sure you want to delete all of your bookmarks?", comment: "Alert for deleting all of the bookmarks."), isPresented: $clearAllAlert) {
     58             Button(NSLocalizedString("Cancel", comment: "Cancel deleting bookmarks."), role: .cancel) {
     59             }
     60             Button(NSLocalizedString("Continue", comment: "Continue with bookmarks.")) {
     61                 manager.clearAll()
     62             }
     63         }
     64     }
     65 }
     66 
     67 /*
     68 struct BookmarksView_Previews: PreviewProvider {
     69  static var previews: some View {
     70     BookmarksView()
     71  }
     72 }
     73  */