Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145module UI.Playlists.Alfred exposing (create, select)
import Alfred exposing (..)import Conditional exposing (ifThenElse)import Dictimport Dict.Extra as Dictimport List.Extra as Listimport Material.Icons.Round as Iconsimport Playlists exposing (..)import Tracks exposing (IdentifiedTrack)import UI.Types as UI
-- CREATE
create : { collectionMode : Bool } -> List IdentifiedTrack -> List Playlist -> Alfred UI.Msgcreate { collectionMode } tracks playlists = let index = makeIndex playlists
subject = ifThenElse collectionMode "collection" "playlist" in Alfred.create { action = createAction collectionMode tracks , index = index , message = if List.length tracks == 1 then "Choose or create a " ++ subject ++ " to add this track to."
else "Choose or create a " ++ subject ++ " to add these tracks to." , operation = QueryOrMutation }
createAction : Bool -> List IdentifiedTrack -> Alfred.Action UI.MsgcreateAction collectionMode tracks ctx = let playlistTracks = Tracks.toPlaylistTracks tracks in case ctx.result of Just result -> -- Add to playlist -- case Alfred.stringValue result.value of Just playlistName -> [ UI.AddTracksToPlaylist { collection = collectionMode , playlistName = playlistName , tracks = playlistTracks } ]
Nothing -> []
Nothing -> -- Create playlist, -- if given a search term. -- case ctx.searchTerm of Just searchTerm -> [ UI.AddTracksToPlaylist { collection = collectionMode , playlistName = searchTerm , tracks = playlistTracks } ]
Nothing -> []
-- SELECT
select : List Playlist -> Alfred UI.Msgselect playlists = let index = makeIndex playlists in Alfred.create { action = selectAction playlists , index = index , message = "Select a playlist to play tracks from." , operation = Query }
selectAction : List Playlist -> Alfred.Action UI.MsgselectAction playlists { result } = case Maybe.andThen (\r -> List.find (.name >> Just >> (==) (stringValue r.value)) playlists) result of Just playlist -> [ UI.SelectPlaylist playlist ]
Nothing -> []
-- ㊙️
makeIndex playlists = playlists |> Dict.groupBy (\p -> case ( p.autoGenerated, p.collection ) of ( Just _, _ ) -> "9 - AutoGenerated Directory Playlists"
( Nothing, True ) -> "1 - Your Collections"
( Nothing, False ) -> "2 - Your Playlists" ) |> Dict.toList |> List.map (\( k, v ) -> ( String.dropLeft 4 k , v |> List.uniqueBy .name |> List.map (\playlist -> { icon = Just (Icons.queue_music 16) , title = playlist.name , value = Alfred.StringValue playlist.name } ) |> List.sortBy (.title >> String.toLower) ) ) |> List.map (\( k, v ) -> { name = Just k, items = v } )