From a70d4f3b380c336a987c1fb9bf4a48e75f851ebb Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 13 Nov 2021 16:45:47 +0100 Subject: [PATCH] Fix share URLs --- Model/Applications/VideosAPI.swift | 2 +- Shared/Player/VideoDetails.swift | 6 ++++-- Shared/Views/ChannelPlaylistView.swift | 8 +++++--- Shared/Views/ChannelVideosView.swift | 8 +++++--- Shared/Views/ShareButton.swift | 8 ++++---- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index 8ae486f4..cd3499bb 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -80,6 +80,6 @@ extension VideosAPI { urlComponents.queryItems = queryItems } - return urlComponents.url! + return urlComponents.url } } diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index b42da1fe..dcc08e94 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -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,7 +309,9 @@ struct VideoDetails: View { } #if os(iOS) .sheet(isPresented: $presentingShareSheet) { - ShareSheet(activityItems: [shareURL]) + if let shareURL = shareURL { + ShareSheet(activityItems: [shareURL]) + } } #endif } diff --git a/Shared/Views/ChannelPlaylistView.swift b/Shared/Views/ChannelPlaylistView.swift index b42d2857..fa27911c 100644 --- a/Shared/Views/ChannelPlaylistView.swift +++ b/Shared/Views/ChannelPlaylistView.swift @@ -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() @@ -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 ) } diff --git a/Shared/Views/ChannelVideosView.swift b/Shared/Views/ChannelVideosView.swift index eea3fcc3..dd52bec9 100644 --- a/Shared/Views/ChannelVideosView.swift +++ b/Shared/Views/ChannelVideosView.swift @@ -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() @@ -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 diff --git a/Shared/Views/ShareButton.swift b/Shared/Views/ShareButton.swift index 75620cad..373fb047 100644 --- a/Shared/Views/ShareButton.swift +++ b/Shared/Views/ShareButton.swift @@ -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 private var accounts @EnvironmentObject private var player @@ -11,11 +11,11 @@ struct ShareButton: View { init( contentItem: ContentItem, presentingShareSheet: Binding, - shareURL: Binding? = nil + shareURL: Binding? = 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 }