diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index d49e3257e..7e60c810a 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -39,6 +39,9 @@ import Views prefersListLayout: $prefersListLayout, viewModel: viewModel ) + .onAppear { + loadItems(isRefresh: true) + } .refreshable { loadItems(isRefresh: true) } @@ -315,15 +318,10 @@ import Views systemImage: item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" ) }) - Button( - action: { - itemToRemove = item - confirmationShown = true - }, - label: { - Label("Remove Item", systemImage: "trash") - } - ).tint(.red) + Button("Remove Item", role: .destructive) { + itemToRemove = item + confirmationShown = true + } if FeatureFlag.enableSnooze { Button { viewModel.itemToSnoozeID = item.id @@ -416,7 +414,7 @@ import Views .listStyle(PlainListStyle()) .alert("Are you sure you want to delete this item? All associated notes and highlights will be deleted.", isPresented: $confirmationShown) { - Button("Delete Item") { + Button("Remove Item", role: .destructive) { if let itemToRemove = itemToRemove { withAnimation { viewModel.removeLink(dataService: dataService, objectID: itemToRemove.objectID) diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index 6a8bb2559..fea5ddbc9 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -6,6 +6,7 @@ import Utils import Views import WebKit +// swiftlint:disable:next type_body_length struct WebReaderContainerView: View { let item: LinkedItem @@ -16,7 +17,6 @@ struct WebReaderContainerView: View { @State private var showHighlightsView = false @State private var hasPerformedHighlightMutations = false @State var showHighlightAnnotationModal = false - @State var safariWebLink: SafariWebLink? @State private var navBarVisibilityRatio = 1.0 @State private var showDeleteConfirmation = false @State private var progressViewOpacity = 0.0 @@ -31,6 +31,10 @@ struct WebReaderContainerView: View { @State private var showErrorAlertMessage = false @State private var showRecommendSheet = false + @State var safariWebLink: SafariWebLink? + @State var displayLinkSheet = false + @State var linkToOpen: URL? + @EnvironmentObject var dataService: DataService @EnvironmentObject var audioController: AudioController @Environment(\.presentationMode) var presentationMode: Binding @@ -326,7 +330,12 @@ struct WebReaderContainerView: View { #if os(macOS) NSWorkspace.shared.open($0) #elseif os(iOS) - safariWebLink = SafariWebLink(id: UUID(), url: $0) + if UIDevice.current.userInterfaceIdiom == .phone, $0.absoluteString != item.unwrappedPageURLString { + linkToOpen = $0 + displayLinkSheet = true + } else { + safariWebLink = SafariWebLink(id: UUID(), url: $0) + } #endif }, webViewActionHandler: webViewActionHandler, @@ -347,6 +356,22 @@ struct WebReaderContainerView: View { showNavBarActionID = UUID() } } + .confirmationDialog(linkToOpen?.absoluteString ?? "", isPresented: $displayLinkSheet) { + Button(action: { + if let linkToOpen = linkToOpen { + safariWebLink = SafariWebLink(id: UUID(), url: linkToOpen) + } + }, label: { Text("Open") }) + Button(action: { + UIPasteboard.general.string = item.unwrappedPageURLString + showInSnackbar("Link Copied") + }, label: { Text("Copy Link") }) + Button(action: { + if let linkToOpen = linkToOpen { + viewModel.saveLink(dataService: dataService, url: linkToOpen) + } + }, label: { Text("Save to Omnivore") }) + } #if os(iOS) .fullScreenCover(item: $safariWebLink) { SafariView(url: $0.url) diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift index 936516226..73d1e4a01 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderViewModel.swift @@ -195,4 +195,17 @@ struct SafariWebLink: Identifiable { { dataService.setLabelsForHighlight(highlightID: highlightID, labelIDs: labelIDs) } + + func saveLink(dataService: DataService, url: URL) { + Task { + do { + Snackbar.show(message: "Saving link") + print("SAVING: ", url.absoluteString) + _ = try await dataService.createPageFromUrl(id: UUID().uuidString, url: url.absoluteString) + Snackbar.show(message: "Link saved") + } catch { + Snackbar.show(message: "Error saving link") + } + } + } }