mirror of
https://github.com/wahyd4/links.git
synced 2026-08-08 21:04:53 +10:00
Integrate share capability
This commit is contained in:
@@ -9,6 +9,23 @@ struct LinkDetailView: View {
|
||||
@State private var showingEdit = false
|
||||
@State private var templateParameters: [String: String] = [:]
|
||||
@State private var showingTemplateDialog = false
|
||||
@State private var showingShareSheet = false
|
||||
|
||||
private var shareItems: [Any] {
|
||||
var items: [Any] = []
|
||||
|
||||
// Add the alias and URL for link/template types
|
||||
if link.linkTypeEnum == .link || link.linkTypeEnum == .template {
|
||||
if let url = link.originalURL, !url.isEmpty {
|
||||
items.append("\(link.alias): \(url)")
|
||||
items.append(URL(string: url) ?? url)
|
||||
} else {
|
||||
items.append(link.alias)
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
enum TimeRange: String, CaseIterable {
|
||||
case threeMonths = "3m"
|
||||
@@ -141,6 +158,9 @@ struct LinkDetailView: View {
|
||||
}
|
||||
)
|
||||
}
|
||||
.sheet(isPresented: $showingShareSheet) {
|
||||
ShareSheet(activityItems: shareItems)
|
||||
}
|
||||
}
|
||||
|
||||
private var headerSection: some View {
|
||||
@@ -341,6 +361,15 @@ struct LinkDetailView: View {
|
||||
|
||||
private var toolbarMenu: some View {
|
||||
Menu {
|
||||
// Share button for link and template types (not for custom)
|
||||
if link.linkTypeEnum == .link || link.linkTypeEnum == .template {
|
||||
Button(action: {
|
||||
showingShareSheet = true
|
||||
}) {
|
||||
Label("Share", systemImage: "square.and.arrow.up")
|
||||
}
|
||||
}
|
||||
|
||||
Button("edit") {
|
||||
showingEdit = true
|
||||
}
|
||||
|
||||
@@ -425,6 +425,21 @@ struct MarkdownContentView: View {
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@EnvironmentObject var linkViewModel: LinkViewModel
|
||||
@State private var showingEditLink = false
|
||||
@State private var showingShareSheet = false
|
||||
|
||||
private var shareItems: [Any] {
|
||||
var items: [Any] = []
|
||||
|
||||
// Add the alias as title
|
||||
items.append("Custom Content: \(link.alias)")
|
||||
|
||||
// Add the markdown content if available
|
||||
if let content = link.text, !content.isEmpty {
|
||||
items.append(content)
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
@@ -472,8 +487,16 @@ struct MarkdownContentView: View {
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Done") {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
HStack(spacing: 16) {
|
||||
Button(action: {
|
||||
showingShareSheet = true
|
||||
}) {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
}
|
||||
|
||||
Button("Done") {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,6 +504,22 @@ struct MarkdownContentView: View {
|
||||
LinkFormView(link: link)
|
||||
.environmentObject(linkViewModel)
|
||||
}
|
||||
.sheet(isPresented: $showingShareSheet) {
|
||||
ShareSheet(activityItems: shareItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ShareSheet: UIViewControllerRepresentable {
|
||||
let activityItems: [Any]
|
||||
|
||||
func makeUIViewController(context: Context) -> UIActivityViewController {
|
||||
let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
|
||||
return controller
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {
|
||||
// No updates needed
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user