Fix share URLs

This commit is contained in:
Arkadiusz Fal 2021-11-13 16:45:47 +01:00
parent 6328bfbfab
commit a70d4f3b38
5 changed files with 19 additions and 13 deletions

View File

@ -80,6 +80,6 @@ extension VideosAPI {
urlComponents.queryItems = queryItems
}
return urlComponents.url!
return urlComponents.url
}
}

View File

@ -14,7 +14,7 @@ struct VideoDetails: View {
@State private var confirmationShown = false
@State private var presentingAddToPlaylist = false
@State private var presentingShareSheet = false
@State private var shareURL = ""
@State private var shareURL: URL?
@State private var currentPage = Page.details
@ -309,8 +309,10 @@ struct VideoDetails: View {
}
#if os(iOS)
.sheet(isPresented: $presentingShareSheet) {
if let shareURL = shareURL {
ShareSheet(activityItems: [shareURL])
}
}
#endif
}

View File

@ -5,6 +5,7 @@ struct ChannelPlaylistView: View {
var playlist: ChannelPlaylist
@State private var presentingShareSheet = false
@State private var shareURL: URL?
@StateObject private var store = Store<ChannelPlaylist>()
@ -56,8 +57,8 @@ struct ChannelPlaylistView: View {
}
#if os(iOS)
.sheet(isPresented: $presentingShareSheet) {
if let url = accounts.api.shareURL(contentItem) {
ShareSheet(activityItems: [url])
if let shareURL = shareURL {
ShareSheet(activityItems: [shareURL])
}
}
#endif
@ -70,7 +71,8 @@ struct ChannelPlaylistView: View {
ToolbarItem(placement: .navigation) {
ShareButton(
contentItem: contentItem,
presentingShareSheet: $presentingShareSheet
presentingShareSheet: $presentingShareSheet,
shareURL: $shareURL
)
}

View File

@ -5,6 +5,7 @@ struct ChannelVideosView: View {
let channel: Channel
@State private var presentingShareSheet = false
@State private var shareURL: URL?
@StateObject private var store = Store<Channel>()
@ -79,7 +80,8 @@ struct ChannelVideosView: View {
ToolbarItem(placement: .navigation) {
ShareButton(
contentItem: contentItem,
presentingShareSheet: $presentingShareSheet
presentingShareSheet: $presentingShareSheet,
shareURL: $shareURL
)
}
@ -100,8 +102,8 @@ struct ChannelVideosView: View {
#endif
#if os(iOS)
.sheet(isPresented: $presentingShareSheet) {
if let url = accounts.api.shareURL(contentItem) {
ShareSheet(activityItems: [url])
if let shareURL = shareURL {
ShareSheet(activityItems: [shareURL])
}
}
#endif

View File

@ -3,7 +3,7 @@ import SwiftUI
struct ShareButton: View {
let contentItem: ContentItem
@Binding var presentingShareSheet: Bool
@Binding var shareURL: String
@Binding var shareURL: URL?
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlayerModel> private var player
@ -11,11 +11,11 @@ struct ShareButton: View {
init(
contentItem: ContentItem,
presentingShareSheet: Binding<Bool>,
shareURL: Binding<String>? = nil
shareURL: Binding<URL?>? = nil
) {
self.contentItem = contentItem
_presentingShareSheet = presentingShareSheet
_shareURL = shareURL ?? .constant("")
_shareURL = shareURL ?? .constant(nil)
}
var body: some View {
@ -81,7 +81,7 @@ struct ShareButton: View {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(url.absoluteString, forType: .string)
#else
shareURL = url.absoluteString
shareURL = url
presentingShareSheet = true
#endif
}