| 1 | import SwiftUI |
| 2 | |
| 3 | #if os(iOS) |
| 4 | import UIKit |
| 5 | #else |
| 6 | import AppKit |
| 7 | #endif |
| 8 | |
| 9 | @MainActor public struct MeetingShareButton: View { |
| 10 | @ObservedObject private var call: Call |
| 11 | @State private var showing = false |
| 12 | |
| 13 | public init(call: Call) { self.call = call } |
| 14 | |
| 15 | public var body: some View { |
| 16 | if call.standing == "member" { |
| 17 | Button("Share", glyph: "square.and.arrow.up") { showing = true } |
| 18 | .accessibilityLabel("Share meeting link") |
| 19 | .sheet(isPresented: $showing) { |
| 20 | MeetingInvitationView(call: call, close: { showing = false }) |
| 21 | .task { await call.loadInvitation() } |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | @MainActor public struct MeetingInvitationView: View { |
| 28 | @ObservedObject private var call: Call |
| 29 | private let close: () -> Void |
| 30 | @State private var copied = false |
| 31 | |
| 32 | public init(call: Call, close: @escaping () -> Void) { |
| 33 | self.call = call |
| 34 | self.close = close |
| 35 | } |
| 36 | |
| 37 | public var body: some View { |
| 38 | VStack(alignment: .leading, spacing: 20) { |
| 39 | Text("Share meeting").font(.title2.bold()) |
| 40 | Text("Send this invitation to someone you want to join. Guests will wait to be let in.") |
| 41 | if call.loadingInvitation { |
| 42 | ProgressView("Getting invitation…") |
| 43 | } else if let url = call.invitationURL { |
| 44 | Text(url.absoluteString).font(.callout).textSelection(.enabled) |
| 45 | HStack { |
| 46 | ShareLink(item: url) { Text("Share…") } |
| 47 | Button(copied ? "Copied" : "Copy link") { |
| 48 | #if os(iOS) |
| 49 | UIPasteboard.general.url = url |
| 50 | copied = true |
| 51 | #else |
| 52 | NSPasteboard.general.clearContents() |
| 53 | copied = NSPasteboard.general.setString(url.absoluteString, forType: .string) |
| 54 | #endif |
| 55 | } |
| 56 | }.buttonStyle(.bordered) |
| 57 | } else { |
| 58 | Text(call.invitationError).foregroundStyle(.secondary) |
| 59 | Button("Try again") { Task { await call.loadInvitation() } } |
| 60 | } |
| 61 | Button("Done", action: close) |
| 62 | }.padding(24).frame(minWidth: 280, idealWidth: 380, maxWidth: 440) |
| 63 | } |
| 64 | } |
| 65 | |