A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 201 lines 5.3 kB view raw
1module UI.Playlists.ContextMenu exposing (listMenu) 2 3import ContextMenu exposing (..) 4import Coordinates exposing (Coordinates) 5import Html.Events.Extra.Mouse 6import Material.Icons.Round as Icons 7import Playlists exposing (Playlist) 8import Playlists.Matching 9import Tracks exposing (IdentifiedTrack) 10import UI.Page 11import UI.Playlists.Page 12import UI.Queue.Types as Queue 13import UI.Tracks.Types as Tracks 14import UI.Types exposing (Msg(..)) 15import Url 16 17 18 19-- 🔱 20 21 22listMenu : Playlist -> List IdentifiedTrack -> Maybe String -> Coordinates -> ContextMenu Msg 23listMenu playlist allTracks confirmation coordinates = 24 let 25 identifiedTracksFromPlaylist = 26 case playlist.autoGenerated of 27 Just _ -> 28 List.filter 29 (Tuple.second >> Tracks.matchesAutoGeneratedPlaylist playlist) 30 allTracks 31 32 Nothing -> 33 allTracks 34 |> Playlists.Matching.match playlist 35 |> Tuple.first 36 37 tracksFromPlaylist = 38 identifiedTracksFromPlaylist 39 |> (if playlist.collection then 40 identity 41 42 else 43 Tracks.sortByIndexInPlaylist 44 ) 45 |> List.map Tuple.second 46 47 menuMsg = 48 ShowPlaylistListMenu 49 playlist 50 { button = Html.Events.Extra.Mouse.MainButton 51 , clientPos = Coordinates.toTuple coordinates 52 , keys = { alt = False, ctrl = False, shift = False } 53 , offsetPos = ( 0, 0 ) 54 , pagePos = ( 0, 0 ) 55 , screenPos = ( 0, 0 ) 56 } 57 in 58 case playlist.autoGenerated of 59 Just _ -> 60 ContextMenu 61 [ addToQueue identifiedTracksFromPlaylist 62 , convertToRegularCollection tracksFromPlaylist playlist 63 , downloadAsZip tracksFromPlaylist playlist 64 , storeInCache tracksFromPlaylist 65 ] 66 coordinates 67 68 Nothing -> 69 ContextMenu 70 [ addToQueue identifiedTracksFromPlaylist 71 , downloadAsZip tracksFromPlaylist playlist 72 , removePlaylist menuMsg confirmation playlist 73 , renamePlaylist playlist 74 , storeInCache tracksFromPlaylist 75 , convert playlist 76 ] 77 coordinates 78 79 80 81-- ITEMS 82 83 84addToQueue identifiedTracks = 85 Item 86 { icon = Icons.update 87 , label = "Add to queue" 88 , msg = 89 { inFront = False, tracks = identifiedTracks } 90 |> Queue.AddTracks 91 |> QueueMsg 92 93 -- 94 , active = False 95 } 96 97 98convert playlist = 99 Item 100 { icon = Icons.waves 101 , label = 102 if playlist.collection then 103 "Convert to playlist" 104 105 else 106 "Convert to collection" 107 , msg = 108 if playlist.collection then 109 ConvertCollectionToPlaylist { name = playlist.name } 110 111 else 112 ConvertPlaylistToCollection { name = playlist.name } 113 114 -- 115 , active = False 116 } 117 118 119convertToRegularCollection tracksFromPlaylist playlist = 120 Item 121 { icon = Icons.waves 122 , label = "Save as regular collection" 123 , msg = 124 AddTracksToPlaylist 125 { collection = True 126 , playlistName = playlist.name 127 , tracks = List.map Tracks.playlistTrackFromTrack tracksFromPlaylist 128 } 129 130 -- 131 , active = False 132 } 133 134 135downloadAsZip tracksFromPlaylist playlist = 136 Item 137 { icon = Icons.archive 138 , label = "Download as zip file" 139 , msg = 140 tracksFromPlaylist 141 |> Tracks.Download 142 { prefixTrackNumber = not playlist.collection 143 , zipName = playlist.name 144 } 145 |> TracksMsg 146 147 -- 148 , active = False 149 } 150 151 152removePlaylist menuMsg confirmation playlist = 153 let 154 playlistId = 155 "Playlist - " ++ playlist.name 156 157 askForConfirmation = 158 confirmation == Just playlistId 159 in 160 Item 161 { icon = Icons.delete 162 , label = 163 if askForConfirmation then 164 "Are you sure?" 165 166 else 167 "Remove playlist" 168 , msg = 169 if askForConfirmation then 170 DeletePlaylist { playlistName = playlist.name } 171 172 else 173 ContextMenuConfirmation playlistId menuMsg 174 , active = 175 askForConfirmation 176 } 177 178 179renamePlaylist playlist = 180 Item 181 { icon = Icons.font_download 182 , label = "Rename playlist" 183 , msg = 184 playlist.name 185 |> Url.percentEncode 186 |> UI.Playlists.Page.Edit 187 |> UI.Page.Playlists 188 |> ChangeUrlUsingPage 189 190 -- 191 , active = False 192 } 193 194 195storeInCache tracksFromPlaylist = 196 Item 197 { icon = Icons.offline_bolt 198 , label = "Store in cache" 199 , msg = TracksMsg (Tracks.StoreInCache tracksFromPlaylist) 200 , active = False 201 }