gemenon

[ACTIVE] The Safari of the Gemini ecosystem
git clone git://git.figbert.com/gemenon.git
Log | Files | Refs

BookmarksView.swift (1844B)


      1 //
      2 //  BookmarksView.swift
      3 //  Gemenon
      4 //
      5 //  Created by figbert on 10/21/22.
      6 //
      7 
      8 import SwiftUI
      9 
     10 struct BookmarksView: View {
     11     @EnvironmentObject var data: BrowserData
     12     @State private var editing: UUID?
     13     @State private var url = ""
     14     @State private var name = ""
     15 
     16     var body: some View {
     17         List {
     18             ForEach(data.bookmarks.sorted(by: { a, b in a.timestamp < b.timestamp })) { bookmark in
     19                 HStack {
     20                     if editing == bookmark.id {
     21                         TextField("Bookmark URL", text: $url)
     22                             .textFieldStyle(.roundedBorder)
     23                             .autocorrectionDisabled(true)
     24                         TextField("Bookmark Name", text: $name)
     25                             .textFieldStyle(.roundedBorder)
     26                             .autocorrectionDisabled(true)
     27                         Button(action: {
     28                             if let url = URL(string: url) {
     29                                 data.dropURLFromBookmarks(bookmark.url)
     30                                 data.addURLToBookmarks(url, label: name, timestamp: bookmark.timestamp)
     31                             }
     32                             self.editing = nil
     33                         }) { Text("Done") }
     34                     } else {
     35                         Link(destination: bookmark.url) { Text(bookmark.name) }
     36                         Spacer()
     37                         Button(action: {
     38                             self.url = bookmark.url.absoluteString
     39                             self.name = bookmark.name
     40                             self.editing = bookmark.id
     41                         }) { Text("Edit") }
     42                     }
     43                 }
     44             }
     45         }
     46     }
     47 }
     48 
     49 struct BookmarksView_Previews: PreviewProvider {
     50     static var previews: some View {
     51         BookmarksView()
     52     }
     53 }