mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
On iPhone allow saving links from the reader
This commit is contained in:
parent
bc924f7b12
commit
0c7b8f5036
3 changed files with 48 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<PresentationMode>
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue