BookmarksView.swift (2332B)
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 } 43 } 44 .onReceive(handle_notify(.switched_timeline)) { _ in 45 dismiss() 46 } 47 .navigationBarTitleDisplayMode(.inline) 48 .navigationTitle(bookmarksTitle) 49 .toolbar { 50 if !bookmarks.isEmpty { 51 Button(NSLocalizedString("Clear All", comment: "Button for clearing bookmarks data.")) { 52 clearAllAlert = true 53 } 54 } 55 } 56 .alert(NSLocalizedString("Are you sure you want to delete all of your bookmarks?", comment: "Alert for deleting all of the bookmarks."), isPresented: $clearAllAlert) { 57 Button(NSLocalizedString("Cancel", comment: "Cancel deleting bookmarks."), role: .cancel) { 58 } 59 Button(NSLocalizedString("Continue", comment: "Continue with bookmarks.")) { 60 manager.clearAll() 61 } 62 } 63 } 64 } 65 66 /* 67 struct BookmarksView_Previews: PreviewProvider { 68 static var previews: some View { 69 BookmarksView() 70 } 71 } 72 */