mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Remaining playlists fixes
This commit is contained in:
parent
03d5eefab0
commit
e539fb0067
@ -360,7 +360,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
|||||||
}
|
}
|
||||||
return ChannelPlaylist(
|
return ChannelPlaylist(
|
||||||
id: id,
|
id: id,
|
||||||
title: details["name"]!.stringValue,
|
title: details["name"]?.stringValue ?? "",
|
||||||
thumbnailURL: thumbnailURL,
|
thumbnailURL: thumbnailURL,
|
||||||
channel: extractChannel(from: json)!,
|
channel: extractChannel(from: json)!,
|
||||||
videos: videos,
|
videos: videos,
|
||||||
|
@ -9,6 +9,7 @@ struct AddToPlaylistView: View {
|
|||||||
|
|
||||||
@State private var error = ""
|
@State private var error = ""
|
||||||
@State private var presentingErrorAlert = false
|
@State private var presentingErrorAlert = false
|
||||||
|
@State private var submitButtonDisabled = false
|
||||||
|
|
||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
@Environment(\.presentationMode) private var presentationMode
|
@Environment(\.presentationMode) private var presentationMode
|
||||||
@ -122,7 +123,7 @@ struct AddToPlaylistView: View {
|
|||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("Add to Playlist", action: addToPlaylist)
|
Button("Add to Playlist", action: addToPlaylist)
|
||||||
.disabled(selectedPlaylist.isNil)
|
.disabled(submitButtonDisabled || selectedPlaylist.isNil)
|
||||||
.padding(.top, 30)
|
.padding(.top, 30)
|
||||||
.alert(isPresented: $presentingErrorAlert) {
|
.alert(isPresented: $presentingErrorAlert) {
|
||||||
Alert(
|
Alert(
|
||||||
@ -165,6 +166,8 @@ struct AddToPlaylistView: View {
|
|||||||
|
|
||||||
Defaults[.lastUsedPlaylistID] = id
|
Defaults[.lastUsedPlaylistID] = id
|
||||||
|
|
||||||
|
submitButtonDisabled = true
|
||||||
|
|
||||||
model.addVideo(
|
model.addVideo(
|
||||||
playlistID: id,
|
playlistID: id,
|
||||||
videoID: video.videoID,
|
videoID: video.videoID,
|
||||||
@ -174,6 +177,7 @@ struct AddToPlaylistView: View {
|
|||||||
onFailure: { requestError in
|
onFailure: { requestError in
|
||||||
error = "(\(requestError.httpStatusCode ?? -1)) \(requestError.userMessage)"
|
error = "(\(requestError.httpStatusCode ?? -1)) \(requestError.userMessage)"
|
||||||
presentingErrorAlert = true
|
presentingErrorAlert = true
|
||||||
|
submitButtonDisabled = false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -125,13 +125,15 @@ struct PlaylistFormView: View {
|
|||||||
.disabled(editing && !accounts.app.userPlaylistsAreEditable)
|
.disabled(editing && !accounts.app.userPlaylistsAreEditable)
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
if accounts.app.userPlaylistsHaveVisibility {
|
||||||
Text("Visibility")
|
HStack {
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
Text("Visibility")
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
|
||||||
visibilityFormItem
|
visibilityFormItem
|
||||||
|
}
|
||||||
|
.padding(.top, 10)
|
||||||
}
|
}
|
||||||
.padding(.top, 10)
|
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
@ -11,6 +11,8 @@ struct PlaylistsView: View {
|
|||||||
@State private var showingEditPlaylist = false
|
@State private var showingEditPlaylist = false
|
||||||
@State private var editedPlaylist: Playlist?
|
@State private var editedPlaylist: Playlist?
|
||||||
|
|
||||||
|
@StateObject private var store = Store<ChannelPlaylist>()
|
||||||
|
|
||||||
@EnvironmentObject<AccountsModel> private var accounts
|
@EnvironmentObject<AccountsModel> private var accounts
|
||||||
@EnvironmentObject<PlayerModel> private var player
|
@EnvironmentObject<PlayerModel> private var player
|
||||||
@EnvironmentObject<PlaylistsModel> private var model
|
@EnvironmentObject<PlaylistsModel> private var model
|
||||||
@ -18,7 +20,36 @@ struct PlaylistsView: View {
|
|||||||
@Namespace private var focusNamespace
|
@Namespace private var focusNamespace
|
||||||
|
|
||||||
var items: [ContentItem] {
|
var items: [ContentItem] {
|
||||||
ContentItem.array(of: currentPlaylist?.videos ?? [])
|
var videos = currentPlaylist?.videos ?? []
|
||||||
|
|
||||||
|
if videos.isEmpty {
|
||||||
|
videos = store.item?.videos ?? []
|
||||||
|
if !player.accounts.app.userPlaylistsEndpointIncludesVideos {
|
||||||
|
var i = 0
|
||||||
|
|
||||||
|
for index in videos.indices {
|
||||||
|
var video = videos[index]
|
||||||
|
video.indexID = "\(i)"
|
||||||
|
i += 1
|
||||||
|
videos[index] = video
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ContentItem.array(of: videos)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var resource: Resource? {
|
||||||
|
guard !player.accounts.app.userPlaylistsEndpointIncludesVideos,
|
||||||
|
let playlist = currentPlaylist
|
||||||
|
else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let resource = player.accounts.api.playlist(playlist.id)
|
||||||
|
resource?.addObserver(store)
|
||||||
|
|
||||||
|
return resource
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -112,10 +143,17 @@ struct PlaylistsView: View {
|
|||||||
#endif
|
#endif
|
||||||
.onAppear {
|
.onAppear {
|
||||||
model.load()
|
model.load()
|
||||||
|
resource?.load()
|
||||||
}
|
}
|
||||||
.onChange(of: accounts.current) { _ in
|
.onChange(of: accounts.current) { _ in
|
||||||
model.load(force: true)
|
model.load(force: true)
|
||||||
}
|
}
|
||||||
|
.onChange(of: selectedPlaylistID) { _ in
|
||||||
|
resource?.load()
|
||||||
|
}
|
||||||
|
.onChange(of: model.reloadPlaylists) { _ in
|
||||||
|
resource?.load()
|
||||||
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user