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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293module Themes.Sunrise.Sources.View exposing (view)
import Chunky exposing (..)import Conditional exposing (ifThenElse)import Dict.Ext as Dictimport Html exposing (Html, text)import Html.Attributes exposing (href)import Html.Lazy as Lazyimport List.Extra as Listimport Material.Icons.Round as Iconsimport Material.Icons.Types exposing (Coloring(..))import Sources exposing (..)import Themes.Sunrise.Kit as Kitimport Themes.Sunrise.Listimport Themes.Sunrise.Navigation as Navigationimport Themes.Sunrise.Sources.Form as Formimport UI.Navigation exposing (..)import UI.Page as Pageimport UI.Sources.Page as Sources exposing (..)import UI.Sources.Types exposing (Msg(..))import UI.Types as UI exposing (Model)
-- 🌳
type alias PartialModel = { processingContext : List ( String, Float ) , processingError : Maybe { error : String, sourceId : String } , sources : List Source }
-- 🗺
view : Sources.Page -> Model -> Html UI.Msgview page model = Html.map UI.SourcesMsg (case page of Index -> Lazy.lazy2 (\a b -> receptacle <| index a b) (List.length model.tracks.untouched) { processingContext = model.processingContext , processingError = model.processingError , sources = model.sources }
Edit _ -> lazyForm model <| Form.edit
New -> lazyForm model <| Form.new { onboarding = False }
NewOnboarding -> lazyForm model <| Form.new { onboarding = True }
NewThroughRedirect _ _ -> lazyForm model <| Form.new { onboarding = False }
Rename _ -> lazyForm model <| Form.rename )
lazyForm model formView = Lazy.lazy (formView >> receptacle) model.sourceForm
receptacle = Kit.receptacle { scrolling = True }
-- INDEX
index : Int -> PartialModel -> List (Html Msg)index amountOfTracks model = [ ----------------------------------------- -- Navigation ----------------------------------------- if List.isEmpty model.sources then Navigation.local [ ( Icon Icons.add , Label "Add a new source" Shown , NavigateToPage (Page.Sources New) ) ]
else Navigation.local [ ( Icon Icons.add , Label "Add a new source" Shown , NavigateToPage (Page.Sources New) )
-- Process ---------- , if List.isEmpty model.processingContext then ( Icon Icons.sync , Label "Process sources" Shown , PerformMsg Process )
else ( Icon Icons.sync , Label "Stop processing ..." Shown , PerformMsg StopProcessing ) ]
----------------------------------------- -- Content ----------------------------------------- , if List.isEmpty model.sources then chunk [ "relative" ] [ chunk [ "absolute", "left-0", "top-0" ] [ Kit.canister [ Kit.h1 "Sources" ] ] ]
else Kit.canister [ Kit.h1 "Sources"
-- Intro -------- , intro amountOfTracks
-- List ------- , model.sources |> List.sortBy lowercaseName |> List.map (\source -> { label = Html.text (Dict.fetch "name" "" source.data) , actions = sourceActions model.processingContext model.processingError source , msg = Nothing , isSelected = False } ) |> Themes.Sunrise.List.view Themes.Sunrise.List.Normal ]
-- , if List.isEmpty model.sources then Kit.centeredContent [ slab Html.a [ href (Page.toString <| Page.Sources New) ] [ "block" , "opacity-30" , "text-inherit" ] [ Icons.music_note 64 Inherit ] , slab Html.a [ href (Page.toString <| Page.Sources New) ] [ "block" , "leading-normal" , "mt-2" , "opacity-40" , "text-center" , "text-inherit" ] [ text "A source is a place where music is stored," , lineBreak , text "add one so you can play some music " , inline [ "align-middle", "inline-block", "-mt-px" ] [ Icons.add 14 Inherit ] ] ]
else nothing ]
intro : Int -> Html Msgintro amountOfTracks = [ text "A source is a place where your music is stored." , lineBreak , text "By connecting a source, the application will scan it and keep a list of all the music in it." , lineBreak , text "You currently have " , text (String.fromInt amountOfTracks) , text " " , text (ifThenElse (amountOfTracks == 1) "track" "tracks") , text " in your collection." ] |> raw |> Kit.intro
sourceActions : List ( String, Float ) -> Maybe { error : String, sourceId : String } -> Source -> List (Themes.Sunrise.List.Action Msg)sourceActions processingContext processingError source = let processIndex = List.findIndex (Tuple.first >> (==) source.id) processingContext
process = Maybe.andThen (\idx -> List.getAt idx processingContext) processIndex in List.append (case ( process, processingError ) of ( Just ( _, progress ), _ ) -> [ { icon = \_ _ -> if progress < 0.05 then inline [ "inline-block", "opacity-70", "px-1" ] [ case processIndex of Just 0 -> Html.text "Listing"
_ -> Html.text "Waiting" ]
else progress |> (*) 100 |> round |> String.fromInt |> (\s -> s ++ "%") |> Html.text |> List.singleton |> inline [ "inline-block", "opacity-70", "px-1" ] , msg = Nothing , title = "" } , { icon = Icons.sync , msg = Nothing , title = "Currently processing" } ]
( Nothing, Just { error, sourceId } ) -> if sourceId == source.id then [ { icon = \size _ -> Icons.error_outline size (Color Kit.colors.error) , msg = Nothing , title = error } ]
else []
_ -> [] ) [ { icon = if source.enabled then Icons.check
else Icons.block , msg = { sourceId = source.id } |> ToggleActivation |> always |> Just , title = if source.enabled then "Enabled (click to disable)"
else "Disabled (click to enable)" }
-- , { icon = Icons.more_vert , msg = Just (SourceContextMenu source) , title = "Menu" } ]
-- 🛠
lowercaseName : Source -> StringlowercaseName = .data >> Dict.fetch "name" "" >> String.toLower