From 0af8248e1119f1612ea36475cd06dd7e8b60fc99 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Sun, 2 Jun 2019 16:54:17 +0200 Subject: [PATCH] Track selection --- src/Applications/UI.elm | 3 +- src/Applications/UI/DnD.elm | 24 +- src/Applications/UI/Kit.elm | 3 +- src/Applications/UI/List.elm | 19 +- src/Applications/UI/Tracks.elm | 77 ++- src/Applications/UI/Tracks/Core.elm | 4 +- src/Applications/UI/Tracks/Scene/List.elm | 451 ++++++++++-------- src/Library/List/Ext.elm | 9 +- src/Library/Tracks.elm | 2 - .../Tracks/Collection/Internal/Arrange.elm | 1 - .../Tracks/Collection/Internal/Identify.elm | 2 - 11 files changed, 365 insertions(+), 230 deletions(-) diff --git a/src/Applications/UI.elm b/src/Applications/UI.elm index 78338572..afe18841 100644 --- a/src/Applications/UI.elm +++ b/src/Applications/UI.elm @@ -1262,7 +1262,8 @@ defaultScreen model = ----------------------------------------- -- Controls ----------------------------------------- - , UI.Console.view + , Lazy.lazy6 + UI.Console.view model.queue.activeItem model.queue.repeat model.queue.shuffle diff --git a/src/Applications/UI/DnD.elm b/src/Applications/UI/DnD.elm index 1eee4e11..d58ff784 100644 --- a/src/Applications/UI/DnD.elm +++ b/src/Applications/UI/DnD.elm @@ -1,9 +1,9 @@ module UI.DnD exposing (Environment, Model, Msg, environmentSubject, environmentTarget, hasDropped, initialModel, isBeingDraggedOver, listenToDrop, listenToEnterLeave, listenToStart, modelSubject, modelTarget, stoppedDragging, update) +import Html exposing (Attribute) +import Html.Attributes as Attributes import Html.Events.Extra.Mouse as Mouse import Html.Events.Extra.Pointer as Pointer -import Html.Styled exposing (Attribute) -import Html.Styled.Attributes as Attributes import UI.Reply as Reply exposing (Reply) @@ -94,16 +94,15 @@ update msg model = listenToStart : Environment context msg -> context -> Attribute msg listenToStart { toMsg } context = - (\event -> - case event.pointer.button of - Mouse.MainButton -> - toMsg (Start context) + Pointer.onDown + (\event -> + case event.pointer.button of + Mouse.MainButton -> + toMsg (Start context) - _ -> - toMsg Stop - ) - |> Pointer.onDown - |> Attributes.fromUnstyled + _ -> + toMsg Stop + ) listenToEnterLeave : Environment context msg -> context -> List (Attribute msg) @@ -118,13 +117,11 @@ listenToEnterLeave { model, toMsg } context = |> toMsg |> always |> Pointer.onEnter - |> Attributes.fromUnstyled , context |> Leave |> toMsg |> always |> Pointer.onLeave - |> Attributes.fromUnstyled ] @@ -140,7 +137,6 @@ listenToDrop { model, toMsg } context = |> toMsg |> always |> Pointer.onUp - |> Attributes.fromUnstyled ] diff --git a/src/Applications/UI/Kit.elm b/src/Applications/UI/Kit.elm index 4836f322..cb041e3e 100644 --- a/src/Applications/UI/Kit.elm +++ b/src/Applications/UI/Kit.elm @@ -3,6 +3,7 @@ module UI.Kit exposing (ButtonType(..), borderRadius, button, buttonFocus, butto import Chunky exposing (..) import Color import Color.Ext as Color +import Color.Manipulate as Color import Css exposing (deg, em, none, num, pct, px, solid, url, zero) import Css.Global import Html.Styled as Html exposing (Html) @@ -57,7 +58,7 @@ colors = , background = rgb 2 7 14 , focus = rgb 0 0 0 , selection = colorKit.base0D - , selectionAlt = rgb 3 48 63 + , selectionAlt = Color.darken 0.275 colorKit.base0D -- rgb 3 48 63 , text = colorKit.base01 } diff --git a/src/Applications/UI/List.elm b/src/Applications/UI/List.elm index 58e6d509..aaec2d99 100644 --- a/src/Applications/UI/List.elm +++ b/src/Applications/UI/List.elm @@ -81,11 +81,16 @@ item variant idx { label, actions, msg } = ) Draggable env -> - List.concat - [ [ css (itemStyles { dragTarget = DnD.environmentTarget env == Just idx }) ] - , DnD.listenToEnterLeave env idx - , DnD.listenToDrop env idx - ] + [ DnD.listenToEnterLeave env idx + , DnD.listenToDrop env idx + ] + |> List.concat + |> List.map Attributes.fromUnstyled + |> List.append + [ { dragTarget = DnD.environmentTarget env == Just idx } + |> itemStyles + |> css + ] ) [ T.flex , T.fw6 @@ -144,8 +149,8 @@ actionView action = dragActionView : Coloring -> DnD.Environment Int msg -> Int -> Html msg dragActionView coloring env context = brick - [ title "Drag me" - , DnD.listenToStart env context + [ Attributes.title "Drag me" + , Attributes.fromUnstyled (DnD.listenToStart env context) ] [ C.lh_0 , C.grab_cursor diff --git a/src/Applications/UI/Tracks.elm b/src/Applications/UI/Tracks.elm index 94c3b851..24207c4d 100644 --- a/src/Applications/UI/Tracks.elm +++ b/src/Applications/UI/Tracks.elm @@ -66,6 +66,7 @@ initialModel = , searchResults = Nothing , searchTerm = Nothing , selectedPlaylist = Nothing + , selectedTrackIndexes = [] , sortBy = Artist , sortDirection = Asc @@ -87,6 +88,27 @@ update msg model = Bypass -> return model + MarkAsSelected indexInList mouseEvent -> + let + selection = + if mouseEvent.keys.shift 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 @@ -130,6 +152,8 @@ update msg model = { model | enabledSourceIds = sourceIds } SetNowPlaying maybeIdentifiedTrack -> + -- TODO: + -- Improve performance let mapFn = case maybeIdentifiedTrack of @@ -236,10 +260,29 @@ update msg model = ----------------------------------------- -- Menus ----------------------------------------- - ShowTrackMenu track mouseEvent -> - [ track ] + ShowTrackMenu trackIndex mouseEvent -> + let + selection = + if List.isEmpty model.selectedTrackIndexes then + [ trackIndex ] + + else if List.member trackIndex model.selectedTrackIndexes == False then + [ trackIndex ] + + else + model.selectedTrackIndexes + in + selection + |> List.foldr + (\s acc -> + model.collection.harvested + |> List.getAt s + |> Maybe.map (List.addTo acc) + |> Maybe.withDefault acc + ) + [] |> ShowTracksContextMenu (Coordinates.fromTuple mouseEvent.clientPos) - |> returnReplyWithModel model + |> returnReplyWithModel { model | selectedTrackIndexes = selection } ShowViewMenu grouping mouseEvent -> grouping @@ -381,17 +424,6 @@ resolveParcel model ( _, newCollection ) = Json.Encode.object [ ( "target", scrollObj ) ] - modelWithNewCollection = - { model - | collection = newCollection - , infiniteList = - if harvestChanged && model.scene == List then - InfiniteList.updateScroll scrollEvent model.infiniteList - - else - model.infiniteList - } - collectionChanged = Collection.tracksChanged model.collection.untouched @@ -405,6 +437,23 @@ resolveParcel model ( _, newCollection ) = Collection.harvestChanged model.collection.harvested newCollection.harvested + + modelWithNewCollection = + { model + | collection = newCollection + , infiniteList = + if harvestChanged && model.scene == List then + InfiniteList.updateScroll scrollEvent model.infiniteList + + else + model.infiniteList + , selectedTrackIndexes = + if harvestChanged then + [] + + else + model.selectedTrackIndexes + } in ( modelWithNewCollection ---------- diff --git a/src/Applications/UI/Tracks/Core.elm b/src/Applications/UI/Tracks/Core.elm index d43ce3d7..886708be 100644 --- a/src/Applications/UI/Tracks/Core.elm +++ b/src/Applications/UI/Tracks/Core.elm @@ -25,6 +25,7 @@ type alias Model = , searchResults : Maybe (List String) , searchTerm : Maybe String , selectedPlaylist : Maybe Playlist + , selectedTrackIndexes : List Int , sortBy : SortBy , sortDirection : SortDirection @@ -42,6 +43,7 @@ type alias Model = type Msg = Bypass + | MarkAsSelected Int Mouse.Event | Reply (List Reply) | ScrollToNowPlaying | SetEnabledSourceIds (List String) @@ -67,7 +69,7 @@ type Msg ----------------------------------------- -- Menus ----------------------------------------- - | ShowTrackMenu IdentifiedTrack Mouse.Event + | ShowTrackMenu Int Mouse.Event | ShowViewMenu (Maybe Grouping) Mouse.Event ----------------------------------------- -- Playlists diff --git a/src/Applications/UI/Tracks/Scene/List.elm b/src/Applications/UI/Tracks/Scene/List.elm index 3e753635..43f7c051 100644 --- a/src/Applications/UI/Tracks/Scene/List.elm +++ b/src/Applications/UI/Tracks/Scene/List.elm @@ -5,22 +5,26 @@ import Chunky exposing (..) import Classes as C import Color import Color.Ext as Color +import Color.Manipulate as Color import Conditional exposing (ifThenElse) import Css -import Html as UnstyledHtml -import Html.Attributes as UnstyledHtmlAttributes -import Html.Events.Extra.Mouse exposing (onWithOptions) -import Html.Styled as Html exposing (Html, text) -import Html.Styled.Attributes exposing (css, fromUnstyled, id, style, tabindex) -import Html.Styled.Events exposing (onClick) -import Html.Styled.Lazy as Lazy +import Html exposing (Html, text) +import Html.Attributes exposing (class, style) +import Html.Events +import Html.Events.Extra.Mouse as Mouse exposing (onWithOptions) +import Html.Styled +import Html.Styled.Attributes +import Html.Styled.Events +import Html.Styled.Lazy import InfiniteList import Json.Decode +import List.Ext as List import Material.Icons exposing (Coloring(..)) import Material.Icons.Av as Icons import Material.Icons.Navigation as Icons import Maybe.Extra as Maybe import Playlists exposing (Playlist) +import Tachyons import Tachyons.Classes as T import Task import Tracks exposing (..) @@ -38,9 +42,9 @@ type alias Necessities = { height : Float, isVisible : Bool } -view : Necessities -> Model -> Html Msg +view : Necessities -> Model -> Html.Styled.Html Msg view necessities model = - Lazy.lazy7 + Html.Styled.Lazy.lazy7 lazyView necessities model.collection.harvested @@ -48,18 +52,19 @@ view necessities model = model.favouritesOnly model.sortBy model.sortDirection - (model.selectedPlaylist + ( model.selectedPlaylist |> Maybe.map .autoGenerated - |> Maybe.andThen (\bool -> ifThenElse (not bool) (Just model.listDnD) Nothing) + |> Maybe.andThen (\bool -> ifThenElse bool Nothing <| Just model.listDnD) + , model.selectedTrackIndexes ) -lazyView : Necessities -> List IdentifiedTrack -> InfiniteList.Model -> Bool -> SortBy -> SortDirection -> Maybe (DnD.Model Int) -> Html Msg -lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection maybeDnD = +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 ) = brick - [ fromUnstyled (InfiniteList.onScroll InfiniteListMsg) - , id containerId - , tabindex (ifThenElse necessities.isVisible 0 -1) + [ Html.Styled.Attributes.fromUnstyled (InfiniteList.onScroll InfiniteListMsg) + , Html.Styled.Attributes.id containerId + , Html.Styled.Attributes.tabindex (ifThenElse necessities.isVisible 0 -1) ] [ C.disable_selection , T.flex_grow_1 @@ -70,7 +75,7 @@ lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection ma ] [ -- Header --------- - Lazy.lazy3 + Html.Styled.Lazy.lazy3 header (Maybe.isJust maybeDnD) sortBy @@ -78,7 +83,7 @@ lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection ma -- List ------- - , Html.fromUnstyled + , Html.Styled.fromUnstyled (InfiniteList.view (InfiniteList.withCustomContainer infiniteListContainer @@ -86,10 +91,10 @@ lazyView necessities harvest infiniteList favouritesOnly sortBy sortDirection ma { itemView = case maybeDnD of Just dnd -> - playlistItemView favouritesOnly dnd + playlistItemView favouritesOnly selectedTrackIndexes dnd _ -> - defaultItemView favouritesOnly + defaultItemView favouritesOnly selectedTrackIndexes -- , itemHeight = InfiniteList.withVariableHeight dynamicRowHeight @@ -127,7 +132,7 @@ scrollToTop = -- HEADERS -header : Bool -> SortBy -> SortDirection -> Html Msg +header : Bool -> SortBy -> SortDirection -> Html.Styled.Html Msg header isPlaylist sortBy sortDirection = let sortIcon = @@ -141,13 +146,13 @@ header isPlaylist sortBy sortDirection = Inherit sortIconHtml = - Html.fromUnstyled sortIcon + Html.Styled.fromUnstyled sortIcon maybeSortIcon s = ifThenElse (sortBy == s) (Just sortIconHtml) Nothing in brick - [ css headerStyles ] + [ Html.Styled.Attributes.css headerStyles ] [ T.bg_white, T.flex, T.fw6, T.relative, T.z_5 ] (if isPlaylist then [ headerColumn "" 4.5 First Nothing Bypass @@ -193,18 +198,18 @@ headerColumn : String -> Float -> Pos - -> Maybe (Html msg) + -> Maybe (Html.Styled.Html msg) -> msg - -> Html msg + -> Html.Styled.Html msg headerColumn text_ width pos maybeSortIcon msg = brick - [ onClick msg - , css + [ Html.Styled.Events.onClick msg + , Html.Styled.Attributes.css [ Css.borderLeft3 (Css.px <| ifThenElse (pos /= First) 1 0) Css.solid (Color.toElmCssColor UI.Kit.colors.subtleBorder) - , Css.minWidth (Css.px columnMinWidth) + , Css.property "min-width" columnMinWidth , Css.width (Css.pct width) ] ] @@ -218,13 +223,13 @@ headerColumn text_ width pos maybeSortIcon msg = , ifThenElse (pos == First) "" T.pointer ] [ brick - [ css [ Css.top (Css.px 1) ] ] + [ Html.Styled.Attributes.css [ Css.top (Css.px 1) ] ] [ T.relative ] - [ text text_ ] + [ Html.Styled.text text_ ] , case maybeSortIcon of Just sortIcon -> brick - [ css sortIconStyles ] + [ Html.Styled.Attributes.css sortIconStyles ] [ T.absolute, T.mr1, T.right_0 ] [ sortIcon ] @@ -248,25 +253,20 @@ sortIconStyles = infiniteListContainer : List ( String, String ) - -> List (UnstyledHtml.Html msg) - -> UnstyledHtml.Html msg -infiniteListContainer styles children = - UnstyledHtml.div - (List.map (\( k, v ) -> UnstyledHtmlAttributes.style k v) styles) - [ (Html.toUnstyled << rawy) <| - brick - [ css listStyles ] - [ T.f6 - , T.pb1 - , T.pt1 - ] - (List.map Html.fromUnstyled children) - ] + -> List (Html msg) + -> Html msg +infiniteListContainer styles = + styles + |> List.map (\( k, v ) -> style k v) + |> List.append listStyles + |> Html.div -listStyles : List Css.Style +listStyles : List (Html.Attribute msg) listStyles = - [ Css.fontSize (Css.px 12.5) ] + [ Tachyons.classes [ T.f6, T.pb1, T.pt1 ] + , style "font-size" "12.5px" + ] dynamicRowHeight : Int -> IdentifiedTrack -> Int @@ -288,8 +288,8 @@ dynamicRowHeight _ ( i, t ) = -- INFINITE LIST ITEM -defaultItemView : Bool -> Int -> Int -> IdentifiedTrack -> UnstyledHtml.Html Msg -defaultItemView favouritesOnly _ idx identifiedTrack = +defaultItemView : Bool -> List Int -> Int -> Int -> IdentifiedTrack -> Html Msg +defaultItemView favouritesOnly selectedTrackIndexes _ idx identifiedTrack = let ( identifiers, track ) = identifiedTrack @@ -298,39 +298,51 @@ defaultItemView favouritesOnly _ idx identifiedTrack = identifiers.group |> Maybe.map (.firstInGroup >> (==) True) |> Maybe.withDefault False + + isSelected = + List.member idx selectedTrackIndexes in - Html.toUnstyled <| - Html.div - [] - [ if shouldRenderGroup then - groupNode idx identifiers + Html.div + [] + [ if shouldRenderGroup then + groupNode idx identifiers - else - nothing + else + text "" - -- - , brick - [ css (rowStyles idx identifiers) - , contextMenuEvent identifiedTrack - , mousePlayEvent identifiedTrack - ] - [ T.flex - , T.items_center + -- + , Html.div + (List.concat + [ rowStyles idx isSelected identifiers -- - , ifThenElse identifiers.isMissing "" T.pointer - , ifThenElse identifiers.isSelected T.fw6 "" - ] - [ favouriteColumn favouritesOnly identifiers - , otherColumn 37.5 False track.tags.title - , otherColumn 29.0 False track.tags.artist - , otherColumn 29.0 True track.tags.album + , [ contextMenuEvent identifiedTrack + , mousePlayEvent identifiedTrack + , mouseSelectEvent identifiedTrack + ] + + -- + , [ T.flex + , T.items_center + + -- + , ifThenElse identifiers.isMissing "" T.pointer + , ifThenElse isSelected T.fw6 "" + ] + |> Tachyons.classes + |> List.singleton ] + ) + [ favouriteColumn favouritesOnly isSelected identifiers + , otherColumn "37.5%" False track.tags.title + , otherColumn "29.0%" False track.tags.artist + , otherColumn "29.0%" True track.tags.album ] + ] -playlistItemView : Bool -> DnD.Model Int -> Int -> Int -> IdentifiedTrack -> UnstyledHtml.Html Msg -playlistItemView favouritesOnly dnd _ idx identifiedTrack = +playlistItemView : Bool -> List Int -> DnD.Model Int -> Int -> Int -> IdentifiedTrack -> Html Msg +playlistItemView favouritesOnly selectedTrackIndexes dnd _ idx identifiedTrack = let ( identifiers, track ) = identifiedTrack @@ -342,61 +354,66 @@ playlistItemView favouritesOnly dnd _ idx identifiedTrack = { model = dnd , toMsg = ListDragAndDropMsg } + + isSelected = + List.member idx selectedTrackIndexes in - Html.toUnstyled <| - brick - ((++) - [ css (rowStyles idx identifiers) - , contextMenuEvent identifiedTrack - , mousePlayEvent identifiedTrack - , DnD.listenToStart dragEnv listIdx - ] - (List.concat - [ DnD.listenToEnterLeave dragEnv listIdx - , DnD.listenToDrop dragEnv listIdx - - -- - , if DnD.isBeingDraggedOver listIdx dnd then - [ style - "box-shadow" - ("0 1px 0 0 " ++ Color.toCssString UI.Kit.colorKit.accent ++ " inset") - ] - - else - [] - ] - ) - ) - [ T.flex - , T.items_center + Html.div + (List.concat + [ rowStyles idx isSelected identifiers -- - , ifThenElse identifiers.isMissing "" T.pointer - , ifThenElse identifiers.isSelected T.fw6 "" - ] - [ favouriteColumn favouritesOnly identifiers - , playlistIndexColumn (Maybe.withDefault 0 identifiers.indexInPlaylist) - , otherColumn 36.0 False track.tags.title - , otherColumn 27.5 False track.tags.artist - , otherColumn 27.5 True track.tags.album + , [ contextMenuEvent identifiedTrack + , mousePlayEvent identifiedTrack + , mouseSelectEvent identifiedTrack + , DnD.listenToStart dragEnv listIdx + ] + + -- + , [ T.flex + , T.items_center + + -- + , ifThenElse identifiers.isMissing "" T.pointer + , ifThenElse isSelected T.fw6 "" + ] + |> Tachyons.classes + |> List.singleton + + -- + , DnD.listenToEnterLeave dragEnv listIdx + , DnD.listenToDrop dragEnv listIdx + + -- + , if DnD.isBeingDraggedOver listIdx dnd then + [ dragIndicator ] + + else + [] ] + ) + [ favouriteColumn favouritesOnly isSelected identifiers + , playlistIndexColumn (Maybe.withDefault 0 identifiers.indexInPlaylist) + , otherColumn "36.0%" False track.tags.title + , otherColumn "27.5%" False track.tags.artist + , otherColumn "27.5%" True track.tags.album + ] contextMenuEvent : IdentifiedTrack -> Html.Attribute Msg -contextMenuEvent identifiedTrack = - identifiedTrack +contextMenuEvent ( i, _ ) = + i.indexInList |> ShowTrackMenu |> onWithOptions "contextmenu" { stopPropagation = True , preventDefault = True } - |> Html.Styled.Attributes.fromUnstyled mousePlayEvent : IdentifiedTrack -> Html.Attribute Msg mousePlayEvent ( i, t ) = - Html.Styled.Events.custom + Html.Events.custom "dblclick" (Json.Decode.succeed { message = @@ -411,6 +428,11 @@ mousePlayEvent ( i, t ) = ) +mouseSelectEvent : IdentifiedTrack -> Html.Attribute Msg +mouseSelectEvent ( i, _ ) = + Mouse.onClick (MarkAsSelected i.indexInList) + + -- ROWS @@ -423,31 +445,36 @@ groupNode idx identifiers = |> Maybe.map .name |> Maybe.withDefault "Unknown" in - brick - [ css groupStyles ] - [ T.f7 - , T.fw7 - , T.lh_copy - , T.pb3 - , T.ph3 - , ifThenElse (0 == idx) T.pt3 T.pt4 - , T.truncate - ] - [ inline - [ T.dib, T.pr2, T.v_mid, C.lh_0 ] - [ Html.fromUnstyled (Icons.library_music 16 Inherit) ] - , inline - [ T.v_mid ] - [ text groupName ] + Html.div + ([ T.f7 + , T.fw7 + , T.lh_copy + , T.pb3 + , T.ph3 + , ifThenElse (0 == idx) T.pt3 T.pt4 + , T.truncate + ] + |> Tachyons.classes + |> List.addTo groupStyles + ) + [ groupIcon + , Html.span [ class T.v_mid ] [ text groupName ] ] -groupStyles : List Css.Style +groupIcon : Html msg +groupIcon = + Html.span + [ Tachyons.classes [ T.dib, T.pr2, T.v_mid, C.lh_0 ] ] + [ Icons.library_music 16 Inherit ] + + +groupStyles : List (Html.Attribute msg) groupStyles = - [ Css.color (Color.toElmCssColor UI.Kit.colorKit.base04) - , Css.fontFamilies UI.Kit.headerFontFamilies - , Css.fontSize (Css.px 11) - , Css.letterSpacing (Css.em 0.005) + [ style "color" rowFontColors.grey + , style "font-family" (String.join ", " UI.Kit.headerFontFamilies) + , style "font-size" "11px" + , style "letter-spacing" "0.005em" ] @@ -456,32 +483,35 @@ rowHeight = 35 -rowStyles : Int -> Identifiers -> List Css.Style -rowStyles idx { isMissing, isNowPlaying } = +rowStyles : Int -> Bool -> Identifiers -> List (Html.Attribute msg) +rowStyles idx isSelected { isMissing, isNowPlaying } = let bgColor = if isNowPlaying then - Color.toElmCssColor UI.Kit.colors.selection + rowBackgroundColors.selection else if modBy 2 idx == 1 then - Css.rgb 252 252 252 + rowBackgroundColors.whiteNear else - Css.rgb 255 255 255 + rowBackgroundColors.white color = - if isNowPlaying then - Css.rgb 255 255 255 + if isSelected then + rowFontColors.selection + + else if isNowPlaying then + rowFontColors.white else if isMissing then - Color.toElmCssColor UI.Kit.colorKit.base04 + rowFontColors.grey else - Color.toElmCssColor UI.Kit.colors.text + rowFontColors.default in - [ Css.backgroundColor bgColor - , Css.color color - , Css.height (Css.px <| toFloat rowHeight) + [ style "background-color" bgColor + , style "color" color + , style "height" (String.fromInt rowHeight ++ "px") ] @@ -490,16 +520,18 @@ rowStyles idx { isMissing, isNowPlaying } = columnMinWidth = - 28 + "28px" -favouriteColumn : Bool -> Identifiers -> Html Msg -favouriteColumn favouritesOnly identifiers = - brick - [ css (favouriteColumnStyles favouritesOnly identifiers) - , onClick (ToggleFavourite identifiers.indexInList) - ] - [ T.flex_shrink_0, T.pl3 ] +favouriteColumn : Bool -> Bool -> Identifiers -> Html Msg +favouriteColumn favouritesOnly isSelected identifiers = + Html.div + ((++) + [ Html.Events.onClick (ToggleFavourite identifiers.indexInList) + , Tachyons.classes [ T.flex_shrink_0, T.fw4, T.pl3 ] + ] + (favouriteColumnStyles favouritesOnly isSelected identifiers) + ) [ if identifiers.isFavourite then text "t" @@ -508,60 +540,107 @@ favouriteColumn favouritesOnly identifiers = ] -favouriteColumnStyles : Bool -> Identifiers -> List Css.Style -favouriteColumnStyles favouritesOnly { isFavourite, isNowPlaying, isSelected } = +favouriteColumnStyles : Bool -> Bool -> Identifiers -> List (Html.Attribute msg) +favouriteColumnStyles favouritesOnly isSelected { isFavourite, isNowPlaying } = let color = - if isSelected then - Color.toElmCssColor UI.Kit.colors.selectionAlt + if isNowPlaying && isFavourite then + if isSelected then + favColors.selection - else if isNowPlaying && isFavourite then - Css.rgb 255 255 255 + else + favColors.white else if isNowPlaying then - Css.rgba 255 255 255 0.4 + if isSelected then + favColors.selectionFaded + + else + favColors.whiteFaded else if favouritesOnly || not isFavourite then - Css.rgb 222 222 222 + if isSelected then + favColors.selectionFadedMore + + else + favColors.blackFaded + + else if isSelected then + favColors.selection else - Color.toElmCssColor UI.Kit.colorKit.base08 + favColors.red in - [ Css.color color - , Css.fontFamilies [ "or-favourites" ] - , Css.minWidth (Css.px columnMinWidth) - , Css.width (Css.pct 4.5) + [ style "color" color + , style "font-family" "or-favourites" + , style "min-width" columnMinWidth + , style "width" "4.5%" ] playlistIndexColumn : Int -> Html msg playlistIndexColumn indexInPlaylist = - brick - [ css (otherColumnStyles 4.5) ] - [ T.pl2 - , T.pr2 - , C.pointer_events_none - , T.truncate - ] - [ text (String.fromInt <| indexInPlaylist + 1) ] + [ T.pl2 + , T.pr2 + , C.pointer_events_none + , T.truncate + ] + |> Tachyons.classes + |> List.addTo (otherColumnStyles "4.5%") + |> (\attributes -> Html.div attributes [ text (String.fromInt <| indexInPlaylist + 1) ]) -otherColumn : Float -> Bool -> String -> Html msg +otherColumn : String -> Bool -> String -> Html msg otherColumn width isLast text_ = - brick - [ css (otherColumnStyles width) ] - [ T.pl2 - , C.pointer_events_none - , T.truncate + [ T.pl2 + , C.pointer_events_none + , T.truncate - -- - , ifThenElse isLast T.pr3 T.pr2 - ] - [ text text_ ] + -- + , ifThenElse isLast T.pr3 T.pr2 + ] + |> Tachyons.classes + |> List.addTo (otherColumnStyles width) + |> (\attributes -> Html.div attributes [ text text_ ]) -otherColumnStyles : Float -> List Css.Style +otherColumnStyles : String -> List (Html.Attribute msg) otherColumnStyles columnWidth = - [ Css.minWidth (Css.px columnMinWidth) - , Css.width (Css.pct columnWidth) + [ style "min-width" columnMinWidth + , style "width" columnWidth ] + + + +-- 🖼 + + +favColors = + { blackFaded = Color.toCssString (Color.rgba 0 0 0 0.125) + , red = Color.toCssString UI.Kit.colorKit.base08 + , selection = Color.toCssString UI.Kit.colors.selectionAlt + , selectionFaded = Color.toCssString (Color.fadeOut 0.6 UI.Kit.colors.selectionAlt) + , selectionFadedMore = Color.toCssString (Color.fadeOut 0.875 UI.Kit.colors.selectionAlt) + , white = Color.toCssString (Color.rgb 1 1 1) + , whiteFaded = Color.toCssString (Color.rgba 1 1 1 0.4) + } + + +rowBackgroundColors = + { selection = Color.toCssString UI.Kit.colors.selection + , white = favColors.white + , whiteNear = Color.toCssString (Color.rgb255 252 252 252) + } + + +rowFontColors = + { default = Color.toCssString UI.Kit.colors.text + , grey = Color.toCssString UI.Kit.colorKit.base04 + , selection = favColors.selection + , white = favColors.white + } + + +dragIndicator : Html.Attribute msg +dragIndicator = + style "box-shadow" ("0 1px 0 0 " ++ Color.toCssString UI.Kit.colorKit.accent ++ " inset") diff --git a/src/Library/List/Ext.elm b/src/Library/List/Ext.elm index 4fe2ca4d..28e09eb4 100644 --- a/src/Library/List/Ext.elm +++ b/src/Library/List/Ext.elm @@ -1,8 +1,15 @@ -module List.Ext exposing (move) +module List.Ext exposing (addTo, move) import List.Extra as List +{-| Flipped version of (::). +-} +addTo : List a -> a -> List a +addTo list item = + item :: list + + {-| Move an item "from" an index "to" another index. -} move : { from : Int, to : Int } -> List a -> List a diff --git a/src/Library/Tracks.elm b/src/Library/Tracks.elm index 98c13a92..03e16956 100644 --- a/src/Library/Tracks.elm +++ b/src/Library/Tracks.elm @@ -59,7 +59,6 @@ type alias Identifiers = { isFavourite : Bool , isMissing : Bool , isNowPlaying : Bool - , isSelected : Bool -- , group : Maybe { name : String, firstInGroup : Bool } @@ -166,7 +165,6 @@ emptyIdentifiers = { isFavourite = False , isMissing = False , isNowPlaying = False - , isSelected = False -- , group = Nothing diff --git a/src/Library/Tracks/Collection/Internal/Arrange.elm b/src/Library/Tracks/Collection/Internal/Arrange.elm index ca233b42..59c9c4c8 100644 --- a/src/Library/Tracks/Collection/Internal/Arrange.elm +++ b/src/Library/Tracks/Collection/Internal/Arrange.elm @@ -337,7 +337,6 @@ makeMissingPlaylistTrack ( identifiers, playlistTrack ) = , isFavourite = False , isMissing = True , isNowPlaying = False - , isSelected = False } { tags = tags , id = missingId diff --git a/src/Library/Tracks/Collection/Internal/Identify.elm b/src/Library/Tracks/Collection/Internal/Identify.elm index 14b47904..4a055633 100644 --- a/src/Library/Tracks/Collection/Internal/Identify.elm +++ b/src/Library/Tracks/Collection/Internal/Identify.elm @@ -103,7 +103,6 @@ partTwo favourites nowPlaying track ( acc, remainingFavourites ) = ( { isFavourite = isFav , isMissing = False , isNowPlaying = isNP - , isSelected = False -- , group = Nothing @@ -160,7 +159,6 @@ makeMissingFavouriteTrack fav = ( { isFavourite = True , isMissing = True , isNowPlaying = False - , isSelected = False -- , group = Nothing -- knotmirror 0.0.1