diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index ef43b675..220866ff 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -78,7 +78,6 @@ import UI.Sources.Page import UI.Svg.Elements import UI.Tracks as Tracks import UI.Tracks.ContextMenu as Tracks -import UI.Tracks.Core as Tracks import UI.Tracks.Scene.List import UI.UserData as UserData import Url exposing (Url) @@ -267,7 +266,8 @@ update msg model = case model.tracks.scene of Tracks.List -> DnD.stoppedDragging - |> Tracks.ListDragAndDropMsg + |> UI.Tracks.Scene.List.DragAndDropMsg + |> Tracks.ListSceneMsg |> TracksMsg |> updateWithModel notDragging @@ -1456,8 +1456,13 @@ defaultScreen model = -- Main ----------------------------------------- , vessel - [ model - |> Tracks.view + [ { amountOfSources = List.length model.sources.collection + , bgColor = model.backdrop.bgColor + , isOnIndexPage = model.page == Page.Index + , sourceIdsBeingProcessed = model.sources.isProcessing + , viewport = model.viewport + } + |> Tracks.view model.tracks |> Html.map TracksMsg -- Pages diff --git a/src/Applications/UI/Alfred.elm b/src/Applications/UI/Alfred.elm index 42c3db3a..5333b30e 100644 --- a/src/Applications/UI/Alfred.elm +++ b/src/Applications/UI/Alfred.elm @@ -15,7 +15,7 @@ import Keyboard import List.Extra as List import Material.Icons exposing (Coloring(..)) import Material.Icons.Hardware as Icons -import Return3 exposing (..) +import Return3 as Return exposing (..) import Tachyons.Classes as T import Task import UI.Kit diff --git a/src/Applications/UI/Console.elm b/src/Applications/UI/Console.elm index 2d0449e8..2f03662f 100644 --- a/src/Applications/UI/Console.elm +++ b/src/Applications/UI/Console.elm @@ -19,7 +19,7 @@ import Tachyons.Classes as T import UI.Core as Core exposing (Msg(..)) import UI.Kit import UI.Queue as Queue -import UI.Tracks.Core as Tracks +import UI.Tracks as Tracks diff --git a/src/Applications/UI/Core.elm b/src/Applications/UI/Core.elm index eb0a9666..ab763274 100644 --- a/src/Applications/UI/Core.elm +++ b/src/Applications/UI/Core.elm @@ -6,6 +6,7 @@ import Browser import Browser.Navigation as Nav import Common exposing (Switch(..)) import ContextMenu exposing (ContextMenu) +import Coordinates exposing (Viewport) import Debouncer.Basic as Debouncer exposing (Debouncer) import File exposing (File) import Http @@ -25,7 +26,7 @@ import UI.Playlists as Playlists import UI.Queue as Queue import UI.Reply exposing (Reply) import UI.Sources as Sources -import UI.Tracks.Core as Tracks +import UI.Tracks as Tracks import Url exposing (Url) @@ -80,12 +81,6 @@ type alias Model = } -type alias Viewport = - { height : Float - , width : Float - } - - -- 📣 diff --git a/src/Applications/UI/Playlists.elm b/src/Applications/UI/Playlists.elm index 9b1d15bd..4b2a21dd 100644 --- a/src/Applications/UI/Playlists.elm +++ b/src/Applications/UI/Playlists.elm @@ -17,7 +17,7 @@ import Material.Icons.Content as Icons import Material.Icons.File as Icons import Material.Icons.Navigation as Icons import Playlists exposing (..) -import Return3 exposing (..) +import Return3 as Return exposing (..) import Tachyons.Classes as T import UI.Kit exposing (ButtonType(..)) import UI.List diff --git a/src/Applications/UI/Settings.elm b/src/Applications/UI/Settings.elm index 94b35553..7fb0fda9 100644 --- a/src/Applications/UI/Settings.elm +++ b/src/Applications/UI/Settings.elm @@ -22,7 +22,7 @@ import UI.Navigation exposing (..) import UI.Page as Page import UI.Settings.ImportExport import UI.Settings.Page as Settings exposing (..) -import UI.Tracks.Core as Tracks +import UI.Tracks as Tracks diff --git a/src/Applications/UI/Tracks.elm b/src/Applications/UI/Tracks.elm index b1903dc3..0972e092 100644 --- a/src/Applications/UI/Tracks.elm +++ b/src/Applications/UI/Tracks.elm @@ -1,4 +1,4 @@ -module UI.Tracks exposing (initialModel, makeParcel, resolveParcel, update, view) +module UI.Tracks exposing (Model, Msg(..), Necessities, Scene(..), initialModel, makeParcel, resolveParcel, update, view) import Alien import Chunky exposing (..) @@ -6,7 +6,8 @@ import Classes as C import Color exposing (Color) import Color.Ext as Color import Common exposing (Switch(..)) -import Coordinates +import Conditional exposing (ifThenElse) +import Coordinates exposing (Coordinates, Viewport) import Css import Css.Transitions exposing (transition) import Html.Events.Extra.Mouse as Mouse @@ -31,13 +32,13 @@ import Material.Icons.Navigation as Icons import Maybe.Extra as Maybe import Playlists exposing (Playlist) import Return3 as Return exposing (..) +import Sources exposing (Source) import Tachyons.Classes as T import Task.Extra as Task import Tracks exposing (..) import Tracks.Collection as Collection exposing (..) import Tracks.Encoding as Encoding import Tracks.Favourites as Favourites -import UI.Core import UI.DnD as DnD import UI.Kit import UI.Navigation exposing (..) @@ -45,8 +46,8 @@ import UI.Page exposing (Page) import UI.Playlists.Page import UI.Ports import UI.Queue.Page -import UI.Reply exposing (Reply(..)) -import UI.Tracks.Core exposing (..) +import UI.Reply as UI exposing (Reply(..)) +import UI.Tracks.Reply as Tracks exposing (Reply(..)) import UI.Tracks.Scene.List @@ -54,6 +55,36 @@ import UI.Tracks.Scene.List -- 🌳 +type alias Model = + { cached : List String + , cachedOnly : Bool + , cachingInProgress : List String + , collection : Collection + , enabledSourceIds : List String + , favourites : List Favourite + , favouritesOnly : Bool + , grouping : Maybe Grouping + , hideDuplicates : Bool + , nowPlaying : Maybe IdentifiedTrack + , scene : Scene + , searchResults : Maybe (List String) + , searchTerm : Maybe String + , selectedPlaylist : Maybe Playlist + , selectedTrackIndexes : List Int + , sortBy : SortBy + , sortDirection : SortDirection + + ----------------------------------------- + -- Scenes + ----------------------------------------- + , listScene : UI.Tracks.Scene.List.Model + } + + +type Scene + = List + + initialModel : Model initialModel = { cached = [] @@ -75,10 +106,9 @@ initialModel = , sortDirection = Asc ----------------------------------------- - -- Scenes / List + -- Scenes ----------------------------------------- - , infiniteList = InfiniteList.init - , listDnD = DnD.initialModel + , listScene = UI.Tracks.Scene.List.initialModel } @@ -86,7 +116,51 @@ initialModel = -- 📣 -update : Msg -> Model -> Return Model Msg Reply +type Msg + = Bypass + | Harvest + | Reply UI.Reply + | ScrollToNowPlaying + | SetEnabledSourceIds (List String) + | SetNowPlaying (Maybe IdentifiedTrack) + | ToggleCachedOnly + | ToggleFavouritesOnly + | ToggleHideDuplicates + ----------------------------------------- + -- Collection + ----------------------------------------- + | Add Json.Value + | RemoveByPaths Json.Value + | RemoveBySourceId String + ----------------------------------------- + -- Groups + ----------------------------------------- + | DisableGrouping + | GroupBy Grouping + ----------------------------------------- + -- Menus + ----------------------------------------- + | ShowTrackMenu Int Coordinates + | ShowViewMenu (Maybe Grouping) Mouse.Event + ----------------------------------------- + -- Playlists + ----------------------------------------- + | DeselectPlaylist + | SelectPlaylist Playlist + ----------------------------------------- + -- Scenes + ----------------------------------------- + | ListSceneMsg UI.Tracks.Scene.List.Msg + ----------------------------------------- + -- Search + ----------------------------------------- + | ClearSearch + | Search + | SetSearchResults Json.Value + | SetSearchTerm String + + +update : Msg -> Model -> Return Model Msg UI.Reply update msg model = case msg of Bypass -> @@ -95,29 +169,8 @@ update msg model = Harvest -> reviseCollection harvest model - MarkAsSelected indexInList { shiftKey } -> - let - selection = - if shiftKey then - model.selectedTrackIndexes - |> List.head - |> Maybe.map - (\n -> - if n > indexInList then - List.range indexInList n - - else - List.range n indexInList - ) - |> Maybe.withDefault [ indexInList ] - - else - [ indexInList ] - in - return { model | selectedTrackIndexes = selection } - - Reply replies -> - returnRepliesWithModel model replies + Reply reply -> + returnReplyWithModel model reply ScrollToNowPlaying -> let @@ -145,6 +198,7 @@ update msg model = (case model.scene of List -> UI.Tracks.Scene.List.scrollToNowPlaying model.collection.harvested + >> Cmd.map ListSceneMsg ) |> Maybe.map (\cmd -> @@ -174,27 +228,16 @@ update msg model = (map <| List.map mapFn) { model | nowPlaying = maybeIdentifiedTrack } - SortBy property -> - let - sortDir = - if model.sortBy /= property then - Asc - - else if model.sortDirection == Asc then - Desc - - else - Asc - in - { model | sortBy = property, sortDirection = sortDir } - |> reviseCollection arrange - |> addReply SaveEnclosedUserData - ToggleCachedOnly -> { model | cachedOnly = not model.cachedOnly } |> reviseCollection harvest |> addReply SaveEnclosedUserData + ToggleFavouritesOnly -> + { model | favouritesOnly = not model.favouritesOnly } + |> reviseCollection harvest + |> addReply SaveEnclosedUserData + ToggleHideDuplicates -> { model | hideDuplicates = not model.hideDuplicates } |> reviseCollection arrange @@ -255,22 +298,6 @@ update msg model = |> reviseCollection identify |> addReply (RemoveTracksFromCache removed) - ----------------------------------------- - -- Favourites - ----------------------------------------- - -- > Make a track a favourite, or remove it as a favourite - ToggleFavourite index -> - model.collection.harvested - |> List.getAt index - |> Maybe.map (toggleFavourite model) - |> Maybe.withDefault (return model) - - -- > Filter collection by favourites only {toggle} - ToggleFavouritesOnly -> - { model | favouritesOnly = not model.favouritesOnly } - |> reviseCollection harvest - |> addReply SaveEnclosedUserData - ----------------------------------------- -- Groups ----------------------------------------- @@ -287,13 +314,11 @@ update msg model = ----------------------------------------- -- Menus ----------------------------------------- - ShowTrackMenuWithSmallDelay a b -> - ShowTrackMenu a b - |> Task.doDelayed 250 - |> returnCommandWithModel model - ShowTrackMenu trackIndex coordinates -> let + listScene = + model.listScene + selection = if List.isEmpty model.selectedTrackIndexes then [ trackIndex ] @@ -316,7 +341,7 @@ update msg model = |> ShowTracksContextMenu coordinates |> returnReplyWithModel { model - | listDnD = DnD.initialModel + | listScene = { listScene | dnd = DnD.initialModel } , selectedTrackIndexes = selection } @@ -339,46 +364,18 @@ update msg model = |> addReply SaveEnclosedUserData ----------------------------------------- - -- Scenes / List + -- Scenes ----------------------------------------- - InfiniteListMsg infiniteList -> - return { model | infiniteList = infiniteList } - - ListDragAndDropMsg subMsg -> - let - ( newDnD, replies ) = - DnD.update subMsg model.listDnD - in - if DnD.hasDropped newDnD then - let - ( subject, target ) = - ( Maybe.withDefault 0 <| DnD.modelSubject newDnD - , Maybe.withDefault 0 <| DnD.modelTarget newDnD - ) - - moveFromTo = - { from = subject, to = target } - - selectedPlaylist = - Maybe.map - (\p -> { p | tracks = List.move moveFromTo p.tracks }) - model.selectedPlaylist - in - case selectedPlaylist of - Just playlist -> - { model | listDnD = newDnD, selectedPlaylist = Just playlist } - |> reviseCollection arrange - |> addReply (ReplacePlaylistInCollection playlist) - - Nothing -> - returnRepliesWithModel - { model | listDnD = newDnD } - replies - - else - returnRepliesWithModel - { model | listDnD = newDnD } - replies + ListSceneMsg sub -> + Return.castNested + translateReply + { mapCmd = ListSceneMsg + , mapModel = \child -> { model | listScene = child } + , update = UI.Tracks.Scene.List.update + } + { model = model.listScene + , msg = sub + } ----------------------------------------- -- Search @@ -429,6 +426,83 @@ update msg model = +-- 📣 ░░ CHILDREN & REPLIES + + +translateReply : Tracks.Reply -> Model -> Return Model Msg UI.Reply +translateReply reply model = + case reply of + Transcend uiReplies -> + returnRepliesWithModel model uiReplies + + -- + MarkAsSelected indexInList { shiftKey } -> + let + selection = + if shiftKey then + model.selectedTrackIndexes + |> List.head + |> Maybe.map + (\n -> + if n > indexInList then + List.range indexInList n + + else + List.range n indexInList + ) + |> Maybe.withDefault [ indexInList ] + + else + [ indexInList ] + in + return { model | selectedTrackIndexes = selection } + + MoveTrackInSelectedPlaylist moveFromTo -> + case model.selectedPlaylist of + Just p -> + let + updatedPlaylist = + { p | tracks = List.move moveFromTo p.tracks } + in + { model | selectedPlaylist = Just updatedPlaylist } + |> reviseCollection arrange + |> addReply (ReplacePlaylistInCollection updatedPlaylist) + + Nothing -> + return model + + ShowTrackMenuWithoutDelay a b -> + update (ShowTrackMenu a b) model + + ShowTrackMenuWithSmallDelay a b -> + ShowTrackMenu a b + |> Task.doDelayed 250 + |> returnCommandWithModel model + + SortBy property -> + let + sortDir = + if model.sortBy /= property then + Asc + + else if model.sortDirection == Asc then + Desc + + else + Asc + in + { model | sortBy = property, sortDirection = sortDir } + |> reviseCollection arrange + |> addReply SaveEnclosedUserData + + ToggleFavourite index -> + model.collection.harvested + |> List.getAt index + |> Maybe.map (toggleFavourite model) + |> Maybe.withDefault (return model) + + + -- 📣 ░░ PARCEL @@ -451,7 +525,7 @@ makeParcel model = ) -resolveParcel : Model -> Parcel -> Return Model Msg Reply +resolveParcel : Model -> Parcel -> Return Model Msg UI.Reply resolveParcel model ( _, newCollection ) = let scrollObj = @@ -476,15 +550,20 @@ resolveParcel model ( _, newCollection ) = model.collection.harvested newCollection.harvested + listSceneModel = + model.listScene + + listScene = + if harvestChanged && model.scene == List then + { listSceneModel | infiniteList = InfiniteList.updateScroll scrollEvent listSceneModel.infiniteList } + + else + listSceneModel + modelWithNewCollection = { model | collection = newCollection - , infiniteList = - if harvestChanged && model.scene == List then - InfiniteList.updateScroll scrollEvent model.infiniteList - - else - model.infiniteList + , listScene = listScene , selectedTrackIndexes = if harvestChanged then [] @@ -500,7 +579,7 @@ resolveParcel model ( _, newCollection ) = , if harvestChanged then case model.scene of List -> - UI.Tracks.Scene.List.scrollToTop + Cmd.map ListSceneMsg UI.Tracks.Scene.List.scrollToTop else Cmd.none @@ -518,7 +597,7 @@ resolveParcel model ( _, newCollection ) = ) -reviseCollection : (Parcel -> Parcel) -> Model -> Return Model Msg Reply +reviseCollection : (Parcel -> Parcel) -> Model -> Return Model Msg UI.Reply reviseCollection collector model = model |> makeParcel @@ -530,7 +609,7 @@ reviseCollection collector model = -- 📣 ░░ FAVOURITES -toggleFavourite : Model -> IdentifiedTrack -> Return Model Msg Reply +toggleFavourite : Model -> IdentifiedTrack -> Return Model Msg UI.Reply toggleFavourite model ( i, t ) = let newFavourites = @@ -552,8 +631,17 @@ toggleFavourite model ( i, t ) = -- 🗺 -view : UI.Core.Model -> Html Msg -view core = +type alias Necessities = + { amountOfSources : Int + , bgColor : Maybe Color + , isOnIndexPage : Bool + , sourceIdsBeingProcessed : List String + , viewport : Viewport + } + + +view : Model -> Necessities -> Html Msg +view model nec = chunk [ T.flex , T.flex_column @@ -561,43 +649,34 @@ view core = ] [ lazy6 navigation - core.tracks.grouping - core.tracks.favouritesOnly - core.tracks.searchTerm - core.tracks.selectedPlaylist - core.page - core.backdrop.bgColor + model.grouping + model.favouritesOnly + model.searchTerm + model.selectedPlaylist + nec.isOnIndexPage + nec.bgColor -- - , if List.isEmpty core.tracks.collection.harvested then + , if List.isEmpty model.collection.harvested then lazy4 noTracksView - core.sources.isProcessing - (List.length core.sources.collection) - (List.length core.tracks.collection.harvested) - (List.length core.tracks.favourites) + nec.sourceIdsBeingProcessed + nec.amountOfSources + (List.length model.collection.harvested) + (List.length model.favourites) else - case core.tracks.scene of + case model.scene of List -> - UI.Tracks.Scene.List.view - { height = core.viewport.height - , isVisible = core.page == UI.Page.Index - } - core.tracks + listView model nec ] -navigation : Maybe Grouping -> Bool -> Maybe String -> Maybe Playlist -> Page -> Maybe Color -> Html Msg -navigation maybeGrouping favouritesOnly searchTerm selectedPlaylist page bgColor = +navigation : Maybe Grouping -> Bool -> Maybe String -> Maybe Playlist -> Bool -> Maybe Color -> Html Msg +navigation maybeGrouping favouritesOnly searchTerm selectedPlaylist isOnIndexPage bgColor = let tabindex_ = - case page of - UI.Page.Index -> - 0 - - _ -> - -1 + ifThenElse isOnIndexPage 0 -1 in brick [ css navigationStyles ] @@ -766,7 +845,7 @@ noTracksView isProcessing amountOfSources amountOfTracks amountOfFavourites = , UI.Kit.buttonWithColor UI.Kit.colorKit.base04 UI.Kit.Normal - (Reply [ InsertDemo ]) + (Reply InsertDemo) (inline [] [ UI.Kit.inlineIcon Icons.music_note @@ -791,6 +870,32 @@ message m = [ text m ] +listView : Model -> Necessities -> Html Msg +listView model nec = + model.selectedPlaylist + |> Maybe.map .autoGenerated + |> Maybe.andThen + (\bool -> + if bool then + Nothing + + else + Just model.listScene.dnd + ) + |> Tuple.pair model.selectedTrackIndexes + |> lazy7 + UI.Tracks.Scene.List.view + { height = nec.viewport.height + , isVisible = nec.isOnIndexPage + } + model.collection.harvested + model.listScene.infiniteList + model.favouritesOnly + model.sortBy + model.sortDirection + |> Html.map ListSceneMsg + + -- 🖼 diff --git a/src/Applications/UI/Tracks/ContextMenu.elm b/src/Applications/UI/Tracks/ContextMenu.elm index 617108f7..44a64f6f 100644 --- a/src/Applications/UI/Tracks/ContextMenu.elm +++ b/src/Applications/UI/Tracks/ContextMenu.elm @@ -13,7 +13,7 @@ import Tracks exposing (Grouping(..), IdentifiedTrack) import UI.Core exposing (Msg(..)) import UI.Queue as Queue import UI.Reply -import UI.Tracks.Core as Tracks +import UI.Tracks as Tracks diff --git a/src/Applications/UI/Tracks/Core.elm b/src/Applications/UI/Tracks/Core.elm deleted file mode 100644 index f147d81e..00000000 --- a/src/Applications/UI/Tracks/Core.elm +++ /dev/null @@ -1,105 +0,0 @@ -module UI.Tracks.Core exposing (Model, Msg(..), Scene(..)) - -import Coordinates exposing (Coordinates) -import Html.Events.Extra.Mouse as Mouse -import InfiniteList -import Json.Encode as Json -import Playlists exposing (Playlist) -import Tracks exposing (..) -import UI.DnD as DnD -import UI.Reply exposing (Reply) - - - --- 🌳 - - -type alias Model = - { cached : List String - , cachedOnly : Bool - , cachingInProgress : List String - , collection : Collection - , enabledSourceIds : List String - , favourites : List Favourite - , favouritesOnly : Bool - , grouping : Maybe Grouping - , hideDuplicates : Bool - , nowPlaying : Maybe IdentifiedTrack - , scene : Scene - , searchResults : Maybe (List String) - , searchTerm : Maybe String - , selectedPlaylist : Maybe Playlist - , selectedTrackIndexes : List Int - , sortBy : SortBy - , sortDirection : SortDirection - - ----------------------------------------- - -- Scenes / List - ----------------------------------------- - , infiniteList : InfiniteList.Model - , listDnD : DnD.Model Int - } - - - --- 📣 - - -type Msg - = Bypass - | Harvest - | MarkAsSelected Int { shiftKey : Bool } - | Reply (List Reply) - | ScrollToNowPlaying - | SetEnabledSourceIds (List String) - | SetNowPlaying (Maybe IdentifiedTrack) - | SortBy SortBy - | ToggleCachedOnly - | ToggleHideDuplicates - ----------------------------------------- - -- Collection - ----------------------------------------- - | Add Json.Value - | RemoveByPaths Json.Value - | RemoveBySourceId String - ----------------------------------------- - -- Favourites - ----------------------------------------- - | ToggleFavourite Int - | ToggleFavouritesOnly - ----------------------------------------- - -- Groups - ----------------------------------------- - | DisableGrouping - | GroupBy Grouping - ----------------------------------------- - -- Menus - ----------------------------------------- - | ShowTrackMenu Int Coordinates - | ShowTrackMenuWithSmallDelay Int Coordinates - | ShowViewMenu (Maybe Grouping) Mouse.Event - ----------------------------------------- - -- Playlists - ----------------------------------------- - | DeselectPlaylist - | SelectPlaylist Playlist - ----------------------------------------- - -- Scenes / List - ----------------------------------------- - | InfiniteListMsg InfiniteList.Model - | ListDragAndDropMsg (DnD.Msg Int) - ----------------------------------------- - -- Search - ----------------------------------------- - | ClearSearch - | Search - | SetSearchResults Json.Value - | SetSearchTerm String - - - --- OTHER - - -type Scene - = List diff --git a/src/Applications/UI/Tracks/Reply.elm b/src/Applications/UI/Tracks/Reply.elm new file mode 100644 index 00000000..03749e04 --- /dev/null +++ b/src/Applications/UI/Tracks/Reply.elm @@ -0,0 +1,20 @@ +module UI.Tracks.Reply exposing (Reply(..)) + +import Coordinates exposing (Coordinates) +import Tracks exposing (..) +import UI.Reply as UI + + + +-- 🌳 + + +type Reply + = Transcend (List UI.Reply) + -- + | MarkAsSelected Int { shiftKey : Bool } + | MoveTrackInSelectedPlaylist { from : Int, to : Int } + | ShowTrackMenuWithoutDelay Int Coordinates + | ShowTrackMenuWithSmallDelay Int Coordinates + | SortBy SortBy + | ToggleFavourite Int diff --git a/src/Applications/UI/Tracks/Scene/List.elm b/src/Applications/UI/Tracks/Scene/List.elm index 05ca4b17..fe1e18e5 100644 --- a/src/Applications/UI/Tracks/Scene/List.elm +++ b/src/Applications/UI/Tracks/Scene/List.elm @@ -1,4 +1,4 @@ -module UI.Tracks.Scene.List exposing (containerId, scrollToNowPlaying, scrollToTop, view) +module UI.Tracks.Scene.List exposing (Model, Msg(..), containerId, initialModel, scrollToNowPlaying, scrollToTop, update, view) import Browser.Dom as Dom import Chunky exposing (..) @@ -27,6 +27,7 @@ import Material.Icons.Av as Icons import Material.Icons.Navigation as Icons import Maybe.Extra as Maybe import Playlists exposing (Playlist) +import Return3 as Return exposing (..) import Tachyons import Tachyons.Classes as T import Task @@ -34,8 +35,71 @@ import Tracks exposing (..) import UI.Css import UI.DnD as DnD import UI.Kit -import UI.Reply -import UI.Tracks.Core exposing (..) +import UI.Reply as UI +import UI.Tracks.Reply exposing (..) + + + +-- 🌳 + + +type alias Model = + { dnd : DnD.Model Int + , infiniteList : InfiniteList.Model + } + + +initialModel : Model +initialModel = + { dnd = DnD.initialModel + , infiniteList = InfiniteList.init + } + + + +-- 📣 + + +type Msg + = Bypass + | Reply Reply + -- + | DragAndDropMsg (DnD.Msg Int) + | InfiniteListMsg InfiniteList.Model + + +update : Msg -> Model -> Return Model Msg Reply +update msg model = + case msg of + Bypass -> + return model + + Reply reply -> + returnReplyWithModel model reply + + -- + InfiniteListMsg infiniteList -> + return { model | infiniteList = infiniteList } + + DragAndDropMsg subMsg -> + let + ( newDnD, uiReplies ) = + DnD.update subMsg model.dnd + in + if DnD.hasDropped newDnD then + returnRepliesWithModel + { model | dnd = newDnD } + [ MoveTrackInSelectedPlaylist + { from = Maybe.withDefault 0 <| DnD.modelSubject newDnD + , to = Maybe.withDefault 0 <| DnD.modelTarget newDnD + } + , Transcend uiReplies + ] + + else + returnRepliesWithModel + { model | dnd = newDnD } + [ Transcend uiReplies ] @@ -48,25 +112,8 @@ type alias Necessities = } -view : Necessities -> Model -> Html.Styled.Html Msg -view necessities model = - Html.Styled.Lazy.lazy7 - lazyView - necessities - model.collection.harvested - model.infiniteList - model.favouritesOnly - model.sortBy - model.sortDirection - ( model.selectedPlaylist - |> Maybe.map .autoGenerated - |> Maybe.andThen (\bool -> ifThenElse bool Nothing <| Just model.listDnD) - , model.selectedTrackIndexes - ) - - -lazyView : Necessities -> List IdentifiedTrack -> InfiniteList.Model -> Bool -> SortBy -> SortDirection -> ( Maybe (DnD.Model Int), List Int ) -> Html.Styled.Html Msg -lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection ( maybeDnD, selectedTrackIndexes ) = +view : Necessities -> List IdentifiedTrack -> InfiniteList.Model -> Bool -> SortBy -> SortDirection -> ( List Int, Maybe (DnD.Model Int) ) -> Html.Styled.Html Msg +view necessities harvest infiniteList favouritesOnly sortBy sortDirection ( selectedTrackIndexes, maybeDnD ) = brick [ Html.Styled.Attributes.css lazyViewStyles , Html.Styled.Attributes.fromUnstyled (InfiniteList.onScroll InfiniteListMsg) @@ -198,9 +245,9 @@ header isPlaylist sortBy sortDirection = else [ headerColumn "" 4.5 First Nothing Bypass - , headerColumn "Title" 37.5 Between (maybeSortIcon Title) (SortBy Title) - , headerColumn "Artist" 29.0 Between (maybeSortIcon Artist) (SortBy Artist) - , headerColumn "Album" 29.0 Last (maybeSortIcon Album) (SortBy Album) + , headerColumn "Title" 37.5 Between (maybeSortIcon Title) (Reply <| SortBy Title) + , headerColumn "Artist" 29.0 Between (maybeSortIcon Artist) (Reply <| SortBy Artist) + , headerColumn "Album" 29.0 Last (maybeSortIcon Album) (Reply <| SortBy Album) ] ) @@ -391,7 +438,7 @@ playlistItemView favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = dragEnv = { model = dnd - , toMsg = ListDragAndDropMsg + , toMsg = DragAndDropMsg } isSelected = @@ -403,11 +450,15 @@ playlistItemView favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = -- , List.append - (if isSelected then + (if isSelected && not favouritesOnly then [ touchContextMenuEvent identifiedTrack (Just dragEnv) , DnD.listenToStart dragEnv listIdx ] + else if isSelected then + [ touchContextMenuEvent identifiedTrack (Just dragEnv) + ] + else [] ) @@ -457,9 +508,10 @@ mouseContextMenuEvent ( i, _ ) = Bypass else - ShowTrackMenuWithSmallDelay - i.indexInList - (Coordinates.fromTuple event.clientPos) + event.clientPos + |> Coordinates.fromTuple + |> ShowTrackMenuWithSmallDelay i.indexInList + |> Reply , stopPropagation = True , preventDefault = True } @@ -481,7 +533,9 @@ touchContextMenuEvent ( i, _ ) maybeDragEnv = Bypass Nothing -> - ShowTrackMenu i.indexInList { x = x, y = y } + { x = x, y = y } + |> ShowTrackMenuWithoutDelay i.indexInList + |> Reply , stopPropagation = False , preventDefault = False } @@ -501,7 +555,11 @@ playEvent ( i, t ) = Bypass else - Reply [ UI.Reply.PlayTrack ( i, t ) ] + ( i, t ) + |> UI.PlayTrack + |> List.singleton + |> Transcend + |> Reply , stopPropagation = True , preventDefault = True } @@ -517,7 +575,9 @@ selectEvent ( i, _ ) = { message = case button of 0 -> - MarkAsSelected i.indexInList { shiftKey = shiftKey } + { shiftKey = shiftKey } + |> MarkAsSelected i.indexInList + |> Reply _ -> Bypass @@ -624,7 +684,7 @@ favouriteColumn : Bool -> Bool -> Identifiers -> Html Msg favouriteColumn favouritesOnly isSelected identifiers = Html.div ((++) - [ Html.Events.onClick (ToggleFavourite identifiers.indexInList) + [ Html.Events.onClick (Reply <| ToggleFavourite identifiers.indexInList) , Tachyons.classes [ T.flex_shrink_0, T.fw4, T.pl3 ] ] (favouriteColumnStyles favouritesOnly isSelected identifiers) diff --git a/src/Applications/UI/UserData.elm b/src/Applications/UI/UserData.elm index d638ede3..92d06db2 100644 --- a/src/Applications/UI/UserData.elm +++ b/src/Applications/UI/UserData.elm @@ -27,7 +27,6 @@ import UI.Ports as Ports import UI.Reply as UI import UI.Sources as Sources import UI.Tracks as Tracks -import UI.Tracks.Core as Tracks diff --git a/src/Library/Coordinates.elm b/src/Library/Coordinates.elm index 34f5812b..d70c29e4 100644 --- a/src/Library/Coordinates.elm +++ b/src/Library/Coordinates.elm @@ -1,4 +1,4 @@ -module Coordinates exposing (Coordinates, fromTuple) +module Coordinates exposing (Coordinates, Viewport, fromTuple) -- 🌳 @@ -7,6 +7,12 @@ type alias Coordinates = { x : Float, y : Float } +type alias Viewport = + { height : Float + , width : Float + } + + -- 🔱 diff --git a/src/Library/Return3.elm b/src/Library/Return3.elm index ad92f0c1..134d273a 100644 --- a/src/Library/Return3.elm +++ b/src/Library/Return3.elm @@ -1,4 +1,4 @@ -module Return3 exposing (Return, addCommand, addReplies, addReply, andThen, commandWithModel, from2, fromDebouncer, mapCmd, mapModel, mapReplies, repliesWithModel, replyWithModel, return, returnCommandWithModel, returnRepliesWithModel, returnReplyWithModel, three, wield, wieldNested) +module Return3 exposing (Return, addCommand, addReplies, addReply, andThen, cast, castNested, commandWithModel, from2, fromDebouncer, mapCmd, mapModel, mapReplies, repliesWithModel, replyWithModel, return, returnCommandWithModel, returnRepliesWithModel, returnReplyWithModel, three, wield, wieldNested) import Maybe.Extra as Maybe import Return2 @@ -116,6 +116,8 @@ mapReplies fn ( model, cmd, replies ) = -- 🔱 ░░ WIELDING +-- +-- Return3 -> Return2 wield : @@ -140,7 +142,7 @@ wieldNested : -> { mapCmd : subMsg -> msg , mapModel : subModel -> model - , update : subMsg -> subModel -> ( subModel, Cmd subMsg, List reply ) + , update : subMsg -> subModel -> Return subModel subMsg reply } -> { model : subModel @@ -167,6 +169,61 @@ wieldNested replyTransformer a b = +-- 🔱 ░░ CASTING +-- +-- Return3 -> Return3 + + +cast : + (reply -> model -> Return model msg otherReply) + -> Return model msg reply + -> Return model msg otherReply +cast replyTransformer ( model, cmd, replies ) = + List.foldl + (\reply ( accModel, accCmd, accReplies ) -> + accModel + |> replyTransformer reply + |> (\( m, c, r ) -> ( m, Cmd.batch [ accCmd, c ], accReplies ++ r )) + ) + ( model + , cmd + , [] + ) + replies + + +castNested : + (reply -> model -> Return model msg otherReply) + -> + { mapCmd : subMsg -> msg + , mapModel : subModel -> model + , update : subMsg -> subModel -> Return subModel subMsg reply + } + -> + { model : subModel + , msg : subMsg + } + -> Return model msg otherReply +castNested replyTransformer a b = + let + cmdTransformer = + a.mapCmd + + modelTransformer = + a.mapModel + + ( subModel, subCmd, replies ) = + a.update b.msg b.model + in + cast + replyTransformer + ( modelTransformer subModel + , Cmd.map cmdTransformer subCmd + , replies + ) + + + -- 🔱 ░░ DEBOUNCER