2020-04-26 00:11:07 +01:00
|
|
|
//
|
|
|
|
// PlaylistList.swift
|
2022-08-07 13:31:15 +01:00
|
|
|
// Mixonomer
|
2020-04-26 00:11:07 +01:00
|
|
|
//
|
|
|
|
// Created by Andy Pack on 25/04/2020.
|
|
|
|
// Copyright © 2020 Sarsoo. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlaylistList: View {
|
|
|
|
|
|
|
|
@EnvironmentObject var liveUser: LiveUser
|
|
|
|
@State private var showAdd = false // State for showing add modal view
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
|
|
|
List{
|
|
|
|
if(liveUser.playlists.count > 0){
|
|
|
|
ForEach(liveUser.playlists.indices, id:\.self) { idx in
|
|
|
|
PlaylistRow(playlist: self.$liveUser.playlists[idx])
|
|
|
|
}
|
|
|
|
.onDelete { indexSet in
|
|
|
|
|
|
|
|
indexSet.forEach { index in
|
|
|
|
let api = PlaylistApi.deletePlaylist(name: self.liveUser.playlists[index].name)
|
|
|
|
RequestBuilder.buildRequest(apiRequest: api).responseJSON{ response in
|
|
|
|
|
2022-04-21 15:02:44 +01:00
|
|
|
}
|
2020-04-26 00:11:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.liveUser.playlists.remove(atOffsets: indexSet)
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
Text("No Playlists")
|
|
|
|
}
|
|
|
|
}
|
2022-04-21 15:02:44 +01:00
|
|
|
.refreshable
|
|
|
|
{
|
2020-04-26 00:11:07 +01:00
|
|
|
self.liveUser.refreshPlaylists()
|
|
|
|
}
|
|
|
|
.navigationBarTitle(Text("Playlists 📻"))
|
|
|
|
.navigationBarItems(trailing:
|
|
|
|
Button(
|
|
|
|
action: { self.showAdd = true },
|
|
|
|
label: { Text("Add") }
|
|
|
|
).sheet(isPresented: $showAdd) {
|
|
|
|
AddPlaylistSheet(playlists: self.$liveUser.playlists, username: self.$liveUser.username)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PlaylistList_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
PlaylistList()
|
|
|
|
}
|
|
|
|
}
|