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

View File

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

View File

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

View File

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