Integrate share capability

This commit is contained in:
2025-08-18 21:20:14 +10:00
parent 78eb01be23
commit db2aaac981
2 changed files with 70 additions and 2 deletions
+29
View File
@@ -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
}
+39
View File
@@ -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,15 +487,39 @@ struct MarkdownContentView: View {
}
}
ToolbarItem(placement: .navigationBarTrailing) {
HStack(spacing: 16) {
Button(action: {
showingShareSheet = true
}) {
Image(systemName: "square.and.arrow.up")
}
Button("Done") {
presentationMode.wrappedValue.dismiss()
}
}
}
}
.sheet(isPresented: $showingEditLink) {
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
}
}