From 2758b8166794d414978b606bf52b2bafbae23f27 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Wed, 29 Jan 2025 19:53:45 +0100 Subject: [PATCH] feat: Closes #437 --- src/Core/UI.elm | 6 +++ src/Core/UI/Commands/Alfred.elm | 20 ++++++++ src/Core/UI/Playlists/ContextMenu.elm | 22 +++++++++ src/Core/UI/Playlists/State.elm | 68 +++++++++++++++++++++++++++ src/Core/UI/Types.elm | 2 + 5 files changed, 118 insertions(+) diff --git a/src/Core/UI.elm b/src/Core/UI.elm index ded1014c..cbcf546d 100644 --- a/src/Core/UI.elm +++ b/src/Core/UI.elm @@ -436,6 +436,12 @@ update msg = AssistWithSelectingPlaylist -> Playlists.assistWithSelectingPlaylist + ConvertCollectionToPlaylist a -> + Playlists.convertCollectionToPlaylist a + + ConvertPlaylistToCollection a -> + Playlists.convertPlaylistToCollection a + CreateCollection -> Playlists.createCollection diff --git a/src/Core/UI/Commands/Alfred.elm b/src/Core/UI/Commands/Alfred.elm index 716da491..1fab0dcd 100644 --- a/src/Core/UI/Commands/Alfred.elm +++ b/src/Core/UI/Commands/Alfred.elm @@ -215,6 +215,26 @@ playlistCommands model = |> UI.TracksMsg |> Command } + + -- + , { icon = Just (Icons.waves 16) + , title = + if playlist.collection then + "Convert to playlist" + + else + "Convert to collection" + , value = + if playlist.collection then + { name = playlist.name } + |> UI.ConvertCollectionToPlaylist + |> Command + + else + { name = playlist.name } + |> UI.ConvertPlaylistToCollection + |> Command + } ] Nothing -> diff --git a/src/Core/UI/Playlists/ContextMenu.elm b/src/Core/UI/Playlists/ContextMenu.elm index 1f1c50da..989544c2 100644 --- a/src/Core/UI/Playlists/ContextMenu.elm +++ b/src/Core/UI/Playlists/ContextMenu.elm @@ -72,6 +72,7 @@ listMenu playlist allTracks confirmation coordinates = , removePlaylist menuMsg confirmation playlist , renamePlaylist playlist , storeInCache tracksFromPlaylist + , convert playlist ] coordinates @@ -94,6 +95,27 @@ addToQueue identifiedTracks = } +convert playlist = + Item + { icon = Icons.waves + , label = + if playlist.collection then + "Convert to playlist" + + else + "Convert to collection" + , msg = + if playlist.collection then + ConvertCollectionToPlaylist { name = playlist.name } + + else + ConvertPlaylistToCollection { name = playlist.name } + + -- + , active = False + } + + convertToRegularCollection tracksFromPlaylist playlist = Item { icon = Icons.waves diff --git a/src/Core/UI/Playlists/State.elm b/src/Core/UI/Playlists/State.elm index ff8101ab..65345db6 100644 --- a/src/Core/UI/Playlists/State.elm +++ b/src/Core/UI/Playlists/State.elm @@ -179,6 +179,74 @@ assistWithSelectingPlaylist model = |> (\a -> Alfred.assign a model) +convertCollectionToPlaylist : { name : String } -> Manager +convertCollectionToPlaylist { name } model = + case + List.findIndex + (\p -> Maybe.isNothing p.autoGenerated && p.name == name) + model.playlists + of + Just playlistIndex -> + model.playlists + |> List.updateAt + playlistIndex + (\p -> { p | collection = False }) + |> (\newInventory -> + { model + | playlists = newInventory + , selectedPlaylist = + Maybe.map + (\p -> + if p.name == name then + { p | collection = False } + + else + p + ) + model.selectedPlaylist + } + ) + |> Return.singleton + |> andThen User.savePlaylists + + Nothing -> + Return.singleton model + + +convertPlaylistToCollection : { name : String } -> Manager +convertPlaylistToCollection { name } model = + case + List.findIndex + (\p -> Maybe.isNothing p.autoGenerated && p.name == name) + model.playlists + of + Just playlistIndex -> + model.playlists + |> List.updateAt + playlistIndex + (\p -> { p | collection = True }) + |> (\newInventory -> + { model + | playlists = newInventory + , selectedPlaylist = + Maybe.map + (\p -> + if p.name == name then + { p | collection = True } + + else + p + ) + model.selectedPlaylist + } + ) + |> Return.singleton + |> andThen User.savePlaylists + + Nothing -> + Return.singleton model + + create : { collection : Bool } -> Manager create { collection } model = case model.newPlaylistContext of diff --git a/src/Core/UI/Types.elm b/src/Core/UI/Types.elm index 209b2d14..a48bfe63 100644 --- a/src/Core/UI/Types.elm +++ b/src/Core/UI/Types.elm @@ -260,6 +260,8 @@ type Msg | AssistWithAddingTracksToCollection (List IdentifiedTrack) | AssistWithAddingTracksToPlaylist (List IdentifiedTrack) | AssistWithSelectingPlaylist + | ConvertCollectionToPlaylist { name : String } + | ConvertPlaylistToCollection { name : String } | CreateCollection | CreatePlaylist | DeactivatePlaylist -- 2.51.2