mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 22:30:32 +05:30
Improve sharing
This commit is contained in:
parent
786418f82e
commit
634b0187ed
@ -179,9 +179,20 @@ final class NavigationModel: ObservableObject {
|
||||
presentingPlaylistForm = true
|
||||
}
|
||||
|
||||
func presentUnsubscribeAlert(_ channel: Channel?) {
|
||||
func presentUnsubscribeAlert(_ channel: Channel, subscriptions: SubscriptionsModel) {
|
||||
channelToUnsubscribe = channel
|
||||
presentingUnsubscribeAlert = channelToUnsubscribe != nil
|
||||
alert = Alert(
|
||||
title: Text(
|
||||
"Are you sure you want to unsubscribe from \(channelToUnsubscribe.name)?"
|
||||
),
|
||||
primaryButton: .destructive(Text("Unsubscribe")) { [weak self] in
|
||||
if let id = self?.channelToUnsubscribe.id {
|
||||
subscriptions.unsubscribe(id)
|
||||
}
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
)
|
||||
presentingAlert = true
|
||||
}
|
||||
|
||||
func hideKeyboard() {
|
||||
|
@ -15,7 +15,7 @@ struct AppSidebarSubscriptions: View {
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Unsubscribe") {
|
||||
navigation.presentUnsubscribeAlert(channel)
|
||||
navigation.presentUnsubscribeAlert(channel, subscriptions: subscriptions)
|
||||
}
|
||||
}
|
||||
.id("channel\(channel.id)")
|
||||
|
@ -107,17 +107,6 @@ struct ContentView: View {
|
||||
}
|
||||
)
|
||||
#endif
|
||||
.alert(isPresented: $navigation.presentingUnsubscribeAlert) {
|
||||
Alert(
|
||||
title: Text(
|
||||
"Are you sure you want to unsubscribe from \(navigation.channelToUnsubscribe.name)?"
|
||||
),
|
||||
primaryButton: .destructive(Text("Unsubscribe")) {
|
||||
subscriptions.unsubscribe(navigation.channelToUnsubscribe.id)
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
)
|
||||
}
|
||||
.alert(isPresented: $navigation.presentingAlert) { navigation.alert }
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,6 @@ struct VideoDetails: View {
|
||||
|
||||
@State private var subscribed = false
|
||||
@State private var subscriptionToggleButtonDisabled = false
|
||||
@State private var presentingUnsubscribeAlert = false
|
||||
@State private var presentingAddToPlaylist = false
|
||||
@State private var presentingShareSheet = false
|
||||
@State private var shareURL: URL?
|
||||
|
||||
@StateObject private var page: Page = .first()
|
||||
|
||||
@ -262,66 +258,6 @@ struct VideoDetails: View {
|
||||
}
|
||||
}
|
||||
|
||||
var countsSection: some View {
|
||||
Group {
|
||||
if let video = player.currentVideo {
|
||||
HStack {
|
||||
ShareButton(
|
||||
contentItem: contentItem,
|
||||
presentingShareSheet: $presentingShareSheet,
|
||||
shareURL: $shareURL
|
||||
)
|
||||
|
||||
Spacer()
|
||||
|
||||
if let views = video.viewsCount {
|
||||
videoDetail(label: "Views", value: views, symbol: "eye")
|
||||
}
|
||||
|
||||
if let likes = video.likesCount {
|
||||
Divider()
|
||||
.frame(minHeight: 35)
|
||||
|
||||
videoDetail(label: "Likes", value: likes, symbol: "hand.thumbsup")
|
||||
}
|
||||
|
||||
if let dislikes = video.dislikesCount {
|
||||
Divider()
|
||||
.frame(minHeight: 35)
|
||||
|
||||
videoDetail(label: "Dislikes", value: dislikes, symbol: "hand.thumbsdown")
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
presentingAddToPlaylist = true
|
||||
} label: {
|
||||
Label("Add to Playlist", systemImage: "text.badge.plus")
|
||||
.labelStyle(.iconOnly)
|
||||
.help("Add to Playlist...")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.opacity(accounts.app.supportsUserPlaylists ? 1 : 0)
|
||||
#if os(macOS)
|
||||
.frame(minWidth: 35, alignment: .trailing)
|
||||
#endif
|
||||
}
|
||||
.frame(maxHeight: 35)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
#if os(iOS)
|
||||
.background(
|
||||
EmptyView().sheet(isPresented: $presentingShareSheet) {
|
||||
if let shareURL = shareURL {
|
||||
ShareSheet(activityItems: [shareURL])
|
||||
}
|
||||
}
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
private var contentItem: ContentItem {
|
||||
ContentItem(video: player.currentVideo!)
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ struct ControlsBar: View {
|
||||
@EnvironmentObject<PlayerModel> private var model
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@State private var presentingShareSheet = false
|
||||
@State private var shareURL: URL?
|
||||
|
||||
@StateObject private var controlsPage = Page.first()
|
||||
|
||||
@ -36,6 +40,15 @@ struct ControlsBar: View {
|
||||
.borderTop(height: 0.4, color: Color("ControlsBorderColor"))
|
||||
.borderBottom(height: 0.4, color: Color("ControlsBorderColor"))
|
||||
.modifier(ControlBackgroundModifier(edgesIgnoringSafeArea: .bottom))
|
||||
#if os(iOS)
|
||||
.background(
|
||||
EmptyView().sheet(isPresented: $presentingShareSheet) {
|
||||
if let shareURL = shareURL {
|
||||
ShareSheet(activityItems: [shareURL])
|
||||
}
|
||||
}
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
var controls: some View {
|
||||
@ -116,7 +129,20 @@ struct ControlsBar: View {
|
||||
var details: some View {
|
||||
HStack {
|
||||
HStack(spacing: 8) {
|
||||
ZStack(alignment: .bottomTrailing) {
|
||||
authorAvatar
|
||||
|
||||
if accounts.app.supportsSubscriptions,
|
||||
accounts.signedIn,
|
||||
let video = model.currentVideo,
|
||||
subscriptions.isSubscribing(video.channel.id)
|
||||
{
|
||||
Image(systemName: "star.circle.fill")
|
||||
.background(Color.background)
|
||||
.clipShape(Circle())
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.contextMenu {
|
||||
if let video = model.currentVideo {
|
||||
Group {
|
||||
@ -138,11 +164,13 @@ struct ControlsBar: View {
|
||||
Label("Add to \(playlist.title)", systemImage: "text.badge.star")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {} label: {
|
||||
Label("Share", systemImage: "square.and.arrow.up")
|
||||
}
|
||||
}
|
||||
ShareButton(
|
||||
contentItem: .init(video: model.currentVideo),
|
||||
presentingShareSheet: $presentingShareSheet,
|
||||
shareURL: $shareURL
|
||||
)
|
||||
}
|
||||
|
||||
Section {
|
||||
@ -157,9 +185,27 @@ struct ControlsBar: View {
|
||||
Label("\(video.author) Channel", systemImage: "rectangle.stack.fill.badge.person.crop")
|
||||
}
|
||||
|
||||
Button {} label: {
|
||||
if accounts.app.supportsSubscriptions, accounts.signedIn {
|
||||
if subscriptions.isSubscribing(video.channel.id) {
|
||||
Button {
|
||||
#if os(tvOS)
|
||||
subscriptions.unsubscribe(video.channel.id)
|
||||
#else
|
||||
navigation.presentUnsubscribeAlert(video.channel, subscriptions: subscriptions)
|
||||
#endif
|
||||
} label: {
|
||||
Label("Unsubscribe", systemImage: "xmark.circle")
|
||||
}
|
||||
} else {
|
||||
Button {
|
||||
subscriptions.subscribe(video.channel.id) {
|
||||
navigation.sidebarSectionChanged.toggle()
|
||||
}
|
||||
} label: {
|
||||
Label("Subscribe", systemImage: "star.circle")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ struct ShareButton: View {
|
||||
youtubeActions
|
||||
} label: {
|
||||
Label("Share", systemImage: "square.and.arrow.up")
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
.menuStyle(.borderlessButton)
|
||||
#if os(macOS)
|
||||
|
@ -67,16 +67,6 @@ struct VideoContextMenuView: View {
|
||||
addToQueueButton
|
||||
}
|
||||
|
||||
if !inChannelView, !inChannelPlaylistView {
|
||||
Section {
|
||||
openChannelButton
|
||||
|
||||
if accounts.app.supportsSubscriptions, accounts.api.signedIn {
|
||||
subscriptionButton
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if accounts.app.supportsUserPlaylists, accounts.signedIn {
|
||||
Section {
|
||||
addToPlaylistButton
|
||||
@ -88,6 +78,16 @@ struct VideoContextMenuView: View {
|
||||
}
|
||||
}
|
||||
|
||||
if !inChannelView, !inChannelPlaylistView {
|
||||
Section {
|
||||
openChannelButton
|
||||
|
||||
if accounts.app.supportsSubscriptions, accounts.api.signedIn {
|
||||
subscriptionButton
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
Button("Cancel", role: .cancel) {}
|
||||
#endif
|
||||
@ -205,7 +205,7 @@ struct VideoContextMenuView: View {
|
||||
#if os(tvOS)
|
||||
subscriptions.unsubscribe(video.channel.id)
|
||||
#else
|
||||
navigation.presentUnsubscribeAlert(video.channel)
|
||||
navigation.presentUnsubscribeAlert(video.channel, subscriptions: subscriptions)
|
||||
#endif
|
||||
} label: {
|
||||
Label("Unsubscribe", systemImage: "xmark.circle")
|
||||
|
Loading…
Reference in New Issue
Block a user