From 87b71d6fcef3ef1d414bc17b61d6edc8cf54b39f Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Wed, 24 Jul 2019 09:45:10 +0200 Subject: [PATCH] Remove UI.Queue.Core module --- src/Applications/UI.elm | 1 - src/Applications/UI/Console.elm | 2 +- src/Applications/UI/Core.elm | 2 +- src/Applications/UI/Queue.elm | 64 +++++++++++++++++++-- src/Applications/UI/Queue/Core.elm | 63 -------------------- src/Applications/UI/Queue/Fill.elm | 67 +++++++++++++--------- src/Applications/UI/Tracks/ContextMenu.elm | 2 +- 7 files changed, 102 insertions(+), 99 deletions(-) delete mode 100644 src/Applications/UI/Queue/Core.elm diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index acfd943e..ef43b675 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -68,7 +68,6 @@ import UI.Playlists.Directory import UI.Ports as Ports import UI.Queue as Queue import UI.Queue.Common -import UI.Queue.Core as Queue import UI.Reply as Reply exposing (Reply(..)) import UI.Settings as Settings import UI.Settings.Page diff --git a/src/Applications/UI/Console.elm b/src/Applications/UI/Console.elm index 15062aeb..2d0449e8 100644 --- a/src/Applications/UI/Console.elm +++ b/src/Applications/UI/Console.elm @@ -18,7 +18,7 @@ import Queue import Tachyons.Classes as T import UI.Core as Core exposing (Msg(..)) import UI.Kit -import UI.Queue.Core as Queue +import UI.Queue as Queue import UI.Tracks.Core as Tracks diff --git a/src/Applications/UI/Core.elm b/src/Applications/UI/Core.elm index 8ba55029..eb0a9666 100644 --- a/src/Applications/UI/Core.elm +++ b/src/Applications/UI/Core.elm @@ -22,7 +22,7 @@ import UI.Backdrop as Backdrop import UI.Equalizer as Equalizer import UI.Page exposing (Page) import UI.Playlists as Playlists -import UI.Queue.Core as Queue +import UI.Queue as Queue import UI.Reply exposing (Reply) import UI.Sources as Sources import UI.Tracks.Core as Tracks diff --git a/src/Applications/UI/Queue.elm b/src/Applications/UI/Queue.elm index 224ba48a..df00b9d0 100644 --- a/src/Applications/UI/Queue.elm +++ b/src/Applications/UI/Queue.elm @@ -1,10 +1,11 @@ -module UI.Queue exposing (initialModel, update, view) +module UI.Queue exposing (Model, Msg(..), initialModel, update, view) import Chunky exposing (..) import Color.Ext as Color import Common import Conditional exposing (..) import Css +import Html.Events.Extra.Mouse as Mouse import Html.Styled as Html exposing (Html, fromUnstyled, text) import Html.Styled.Attributes exposing (css, href) import List.Extra as List @@ -26,7 +27,6 @@ import UI.Navigation exposing (..) import UI.Page as Page import UI.Ports as Ports import UI.Queue.Common exposing (makeItem) -import UI.Queue.Core exposing (..) import UI.Queue.Fill as Fill import UI.Queue.Page as Queue exposing (Page(..)) import UI.Reply exposing (Reply(..)) @@ -37,6 +37,21 @@ import UI.Sources.Page -- 🌳 +type alias Model = + { activeItem : Maybe Item + , future : List Item + , ignored : List Item + , past : List Item + + -- + , repeat : Bool + , shuffle : Bool + + -- + , dnd : DnD.Model Int + } + + initialModel : Model initialModel = { activeItem = Nothing @@ -57,6 +72,39 @@ initialModel = -- 📣 +type Msg + = ------------------------------------ + -- Combos + ------------------------------------ + InjectFirstAndPlay IdentifiedTrack + ------------------------------------ + -- Future + ------------------------------------ + | InjectFirst { showNotification : Bool } (List IdentifiedTrack) + | InjectLast { showNotification : Bool } (List IdentifiedTrack) + | RemoveItem { index : Int, item : Item } + ------------------------------------ + -- Position + ------------------------------------ + | Rewind + | Shift + ------------------------------------ + -- Contents + ------------------------------------ + | Clear + | Reset + | Fill Time.Posix (List IdentifiedTrack) + ------------------------------------ + -- Drag & Drop + ------------------------------------ + | DragMsg (DnD.Msg Int) + ------------------------------------ + -- Settings + ------------------------------------ + | ToggleRepeat + | ToggleShuffle + + update : Msg -> Model -> Return Model Msg Reply update msg model = case msg of @@ -353,13 +401,21 @@ fillQueue timestamp availableTracks model = m ) |> (\m -> + let + fillState = + { activeItem = m.activeItem + , future = m.future + , ignored = m.ignored + , past = m.past + } + in -- Fill using the appropiate method case m.shuffle of False -> - { m | future = Fill.ordered timestamp nonMissingTracks m } + { m | future = Fill.ordered timestamp nonMissingTracks fillState } True -> - { m | future = Fill.shuffled timestamp nonMissingTracks m } + { m | future = Fill.shuffled timestamp nonMissingTracks fillState } ) diff --git a/src/Applications/UI/Queue/Core.elm b/src/Applications/UI/Queue/Core.elm deleted file mode 100644 index cd07cba1..00000000 --- a/src/Applications/UI/Queue/Core.elm +++ /dev/null @@ -1,63 +0,0 @@ -module UI.Queue.Core exposing (Model, Msg(..)) - -import UI.DnD as DnD -import Html.Events.Extra.Mouse as Mouse -import Queue exposing (..) -import Time -import Tracks exposing (IdentifiedTrack) - - - --- 🌳 - - -type alias Model = - { activeItem : Maybe Item - , future : List Item - , ignored : List Item - , past : List Item - - -- - , repeat : Bool - , shuffle : Bool - - -- - , dnd : DnD.Model Int - } - - - --- 📣 - - -type Msg - = ------------------------------------ - -- Combos - ------------------------------------ - InjectFirstAndPlay IdentifiedTrack - ------------------------------------ - -- Future - ------------------------------------ - | InjectFirst { showNotification : Bool } (List IdentifiedTrack) - | InjectLast { showNotification : Bool } (List IdentifiedTrack) - | RemoveItem { index : Int, item : Item } - ------------------------------------ - -- Position - ------------------------------------ - | Rewind - | Shift - ------------------------------------ - -- Contents - ------------------------------------ - | Clear - | Reset - | Fill Time.Posix (List IdentifiedTrack) - ------------------------------------ - -- Drag & Drop - ------------------------------------ - | DragMsg (DnD.Msg Int) - ------------------------------------ - -- Settings - ------------------------------------ - | ToggleRepeat - | ToggleShuffle diff --git a/src/Applications/UI/Queue/Fill.elm b/src/Applications/UI/Queue/Fill.elm index e603697d..67cf5ca5 100644 --- a/src/Applications/UI/Queue/Fill.elm +++ b/src/Applications/UI/Queue/Fill.elm @@ -1,4 +1,4 @@ -module UI.Queue.Fill exposing (cleanAutoGenerated, ordered, shuffled) +module UI.Queue.Fill exposing (State, cleanAutoGenerated, ordered, shuffled) {-| These functions will return a new list for the `future` property. -} @@ -11,43 +11,38 @@ import Random exposing (Generator, Seed) import Time import Tracks exposing (IdentifiedTrack) import UI.Queue.Common exposing (makeItem) -import UI.Queue.Core exposing (Model) --- 🔱 - +-- 🌳 -cleanAutoGenerated : Bool -> String -> List Item -> List Item -cleanAutoGenerated shuffle trackId future = - case shuffle of - True -> - List.filterNot - (\i -> i.manualEntry == False && itemTrackId i == trackId) - future - False -> - future +type alias State = + { activeItem : Maybe Item + , future : List Item + , ignored : List Item + , past : List Item + } -- 🔱 ░░ ORDERED -ordered : Time.Posix -> List IdentifiedTrack -> Model -> List Item -ordered _ rawTracks model = +ordered : Time.Posix -> List IdentifiedTrack -> State -> List Item +ordered _ rawTracks state = let tracks = - purifyTracksList model.ignored rawTracks + purifyTracksList state.ignored rawTracks manualEntries = - List.filter (.manualEntry >> (==) True) model.future + List.filter (.manualEntry >> (==) True) state.future remaining = max (queueLength - List.length manualEntries) 0 focus = - Maybe.preferFirst (List.last manualEntries) model.activeItem + Maybe.preferFirst (List.last manualEntries) state.activeItem in case focus of Just item -> @@ -82,11 +77,11 @@ ordered _ rawTracks model = -- 🔱 ░░ SHUFFLED -shuffled : Time.Posix -> List IdentifiedTrack -> Model -> List Item -shuffled timestamp rawTracks model = +shuffled : Time.Posix -> List IdentifiedTrack -> State -> List Item +shuffled timestamp rawTracks state = let tracks = - purifyTracksList model.ignored rawTracks + purifyTracksList state.ignored rawTracks amountOfTracks = List.length tracks @@ -95,9 +90,9 @@ shuffled timestamp rawTracks model = Random.int 0 (amountOfTracks - 1) ( pastIds, futureIds, activeId ) = - ( List.map itemTrackId model.past - , List.map itemTrackId model.future - , Maybe.map itemTrackId model.activeItem + ( List.map itemTrackId state.past + , List.map itemTrackId state.future + , Maybe.map itemTrackId state.activeItem ) usedIndexes = @@ -114,7 +109,7 @@ shuffled timestamp rawTracks model = List.length usedIndexes >= amountOfTracks hasNoFuture = - List.isEmpty model.future + List.isEmpty state.future in if isUsedUp && hasNoFuture && amountOfTracks > 1 then case amountOfTracks > 1 of @@ -128,7 +123,7 @@ shuffled timestamp rawTracks model = usedIndexes ( toAmount, maxAmount ) = - ( max (queueLength - List.length model.future) 0 + ( max (queueLength - List.length state.future) 0 , max (amountOfTracks - List.length usedIndexes_) 0 ) @@ -143,10 +138,26 @@ shuffled timestamp rawTracks model = |> List.map (\idx -> List.getAt idx tracks) |> Maybe.values |> List.map (makeItem False) - |> List.append model.future + |> List.append state.future else - model.future + state.future + + + +-- 🔱 + + +cleanAutoGenerated : Bool -> String -> List Item -> List Item +cleanAutoGenerated shuffle trackId future = + case shuffle of + True -> + List.filterNot + (\i -> i.manualEntry == False && itemTrackId i == trackId) + future + + False -> + future diff --git a/src/Applications/UI/Tracks/ContextMenu.elm b/src/Applications/UI/Tracks/ContextMenu.elm index f187cbec..617108f7 100644 --- a/src/Applications/UI/Tracks/ContextMenu.elm +++ b/src/Applications/UI/Tracks/ContextMenu.elm @@ -11,7 +11,7 @@ import Playlists exposing (Playlist) import Sources.Services import Tracks exposing (Grouping(..), IdentifiedTrack) import UI.Core exposing (Msg(..)) -import UI.Queue.Core as Queue +import UI.Queue as Queue import UI.Reply import UI.Tracks.Core as Tracks -- knotmirror 0.0.1